Skip to content

Add additional_git_am_switches input to backport workflow for handling branch-specific files#16235

Merged
akoeplinger merged 2 commits intomainfrom
copilot/fix-backport-workflow-issues
Oct 22, 2025
Merged

Add additional_git_am_switches input to backport workflow for handling branch-specific files#16235
akoeplinger merged 2 commits intomainfrom
copilot/fix-backport-workflow-issues

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Problem

The backport workflow currently fails when patches contain files that don't exist or have incompatible structures between source and target branches. A common scenario is release notes files where:

  • main branch has docs/release-notes/11.0.0.md for an upcoming version
  • release/dev17.12 branch doesn't have this file (it has 10.4.0.md instead)
  • Backporting a PR that touches both code and release notes causes merge conflicts that block automated backporting

Example failure from dotnet/fsharp:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
...
Auto-merging docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
CONFLICT (content): Merge conflict in docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
error: Failed to merge in the changes.

Solution

This PR adds a new optional workflow input additional_git_am_switches that allows repositories to pass custom flags to the git am command. This enables:

  1. Excluding problematic paths: --exclude=docs/release-notes/*
  2. Fixing whitespace issues automatically: --whitespace=fix
  3. Using other git am options: --ignore-space-change, --directory=, etc.

Changes

  1. Added new workflow input additional_git_am_switches with:

    • Clear description and usage examples
    • Optional parameter (default: empty string)
    • Backward compatible
  2. Modified git am command construction to:

    • Read additional switches from environment variable
    • Trim whitespace from input
    • Conditionally append switches only when provided
    • Maintain original behavior when no switches are provided

Usage Example

Repositories like dotnet/fsharp can now use:

jobs:
  backport:
    uses: dotnet/arcade/.github/workflows/backport-base.yml@main
    with:
      additional_git_am_switches: '--exclude=docs/release-notes/*'
      pr_description_template: |
        Backport of #%source_pr_number% to %target_branch%
        
        **Note:** Release notes excluded from backport and should be added manually to the target branch version file.
        
        /cc %cc_users%

Benefits

  • Backward compatible: Default empty string maintains current behavior
  • Flexible: Repos can use any valid git am options for their needs
  • Safe: Follows existing patterns for user input handling, CodeQL verified (0 vulnerabilities)
  • Minimal: Only 11 lines changed (+11, -1)
  • No parsing complexity: Passes switches directly to git am

Testing

The implementation has been validated with:

  • 10 comprehensive test cases (all passing)
  • YAML syntax validation (no new issues introduced)
  • Security analysis (CodeQL scan: 0 vulnerabilities)
  • Backward compatibility verification

This change will unblock backporting workflows for repositories with version-specific files that differ between branches, addressing recurring pain points across multiple dotnet repositories.

Alternative Approaches Considered

  • Specific exclude_paths input: More restrictive, would require parsing and validation
  • Always exclude certain patterns: Too opinionated, not all repos have the same structure
  • Post-process patch files: More complex, harder to debug

The chosen approach provides maximum flexibility while maintaining simplicity and safety.

Original prompt

Problem

The current backport workflow fails when patches contain files that don't exist or have incompatible structures between the source and target branches. A common scenario is release notes files where:

  • main branch has docs/release-notes/11.0.0.md for an upcoming version
  • release/dev17.12 branch doesn't have this file (it has 10.4.0.md instead)
  • Backporting a PR that touches both code and release notes causes merge conflicts

Example failure from dotnet/fsharp:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add a failsafe in case of infinite types
Applying: do not cache when invalid keys
Applying: refactor
Applying: rn
.git/rebase-apply/patch:13: trailing whitespace.
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))  
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M	docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
Falling back to patching base and 3-way merge...
Auto-merging docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
CONFLICT (content): Merge conflict in docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
error: Failed to merge in the changes.

Proposed Solution

Add a new optional workflow input additional_git_am_switches that allows repositories to pass custom flags to the git am command. This enables:

  1. Excluding problematic paths: --exclude=docs/release-notes/*
  2. Fixing whitespace issues automatically: --whitespace=fix
  3. Other git am options: --ignore-space-change, --directory=, etc.

Implementation Requirements

1. Add new workflow input to backport-base.yml

Add to the inputs: section:

additional_git_am_switches:
  description: 'Additional switches to pass to git am command (e.g., "--exclude=docs/release-notes/* --whitespace=fix"). Useful for excluding files that differ between branches or fixing whitespace conflicts.'
  required: false
  type: string
  default: ''

2. Modify the git am command construction

In the "Run backport" step, update the command construction (around line 134):

Current code:

const git_am_command = "git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch";

New code:

const additional_switches = '${{ inputs.additional_git_am_switches }}'.trim();
const base_switches = '--3way --empty=keep --ignore-whitespace --keep-non-patch';
const git_am_command = additional_switches 
  ? `git am ${base_switches} ${additional_switches} changes.patch`
  : `git am ${base_switches} changes.patch`;

Usage Example

Repositories like dotnet/fsharp can then use it:

jobs:
  backport:
    uses: dotnet/arcade/.github/workflows/backport-base.yml@main
    with:
      additional_git_am_switches: '--exclude=docs/release-notes/* --whitespace=fix'
      pr_description_template: |
        Backport of #%source_pr_number% to %target_branch%
        
        **Note:** Release notes excluded from backport and should be added manually to the target branch version file.

Benefits

  • Backward compatible: Default empty string maintains current behavior
  • Flexible: Repos can use any valid git am options for their needs
  • No parsing complexity: Passes switches directly to git am
  • Solves real pain: Addresses recurring backport failures in multiple dotnet repos

Alternative Approaches Considered

  • Specific exclude_paths input: More restrictive, would require parsing and validation
  • Always exclude certain patterns: Too opinionated, not all repos have the same structure
  • Post-process patch files: More complex, harder to debug

Testing

Should be tested with:

  1. Empty string (default behavior)
  2. Single exclude pattern: --exclude=docs/*
  3. Multiple switches: --exclude=docs/* --whitespace=fix
  4. Invalid switch (should fail with clear git error message)

This change will unblock backporting workflows for repositories with version-specific files that differ between branches.

This pull request was created as a result of the following prompt from Copilot chat.

Problem

The current backport workflow fails when patches contain files that don't exist or have incompatible structures between the source and target branches. A common scenario is release notes files where:

  • main branch has docs/release-notes/11.0.0.md for an upcoming version
  • release/dev17.12 branch doesn't have this file (it has 10.4.0.md instead)
  • Backporting a PR that touches both code and release notes causes merge conflicts

Example failure from dotnet/fsharp:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add a failsafe in case of infinite types
Applying: do not cache when invalid keys
Applying: refactor
Applying: rn
.git/rebase-apply/patch:13: trailing whitespace.
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))  
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M	docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
Falling back to patching base and 3-way merge...
Auto-merging docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
CONFLICT (content): Merge conflict in docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
error: Failed to merge in the changes.

Proposed Solution

Add a new optional workflow input additional_git_am_switches that allows repositories to pass custom flags to the git am command. This enables:

  1. Excluding problematic paths: --exclude=docs/release-notes/*
  2. Fixing whitespace issues automatically: --whitespace=fix
  3. Other git am options: --ignore-space-change, --directory=, etc.

Implementation Requirements

1. Add new workflow input to backport-base.yml

Add to the inputs: section:

additional_git_am_switches:
  description: 'Additional switches to pass to git am command (e.g., "--exclude=docs/release-notes/* --whitespace=fix"). Useful for excluding files that differ between branches or fixing whitespace conflicts.'
  required: false
  type: string
  default: ''

2. Modify the git am command construction

In the "Run backport" step, update the command construction (around line 134):

Current code:

const git_am_command = "git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch";

New code:

const additional_switches = '${{ inputs.additional_git_am_switches }}'.trim();
const base_switches = '--3way --empty=keep --ignore-whitespace --keep-non-patch';
const git_am_command = additional_switches 
  ? `git am ${base_switches} ${additional_switches} changes.patch`
  : `git am ${base_switches} changes.patch`;

Usage Example

Repositories like dotnet/fsharp can then use it:

jobs:
  backport:
    uses: dotnet/arcade/.github/workflows/backport-base.yml@main
    with:
      additional_git_am_switches: '--exclude=docs/release-notes/* --whitespace=fix'
      pr_description_template: |
        Backport of #%source_pr_number% to %target_branch%
        
        **Note:** Release notes excluded from backport and should be added manually to the target branch version file.

Benefits

  • Backward compatible: Default empty string maintains current behavior
  • Flexible: Repos can use any valid git am options for their needs
  • No parsing complexity: Passes switches directly to git am
  • Solves real pain: Addresses recurring backport failures in multiple dotnet repos

Alternative Approaches Considered

  • Specific exclude_paths input: More restrictive, would require parsing and validation
  • Always exclude certain patterns: Too opinionated, not all repos have the same structure
  • Post-process patch files: More complex, harder to debug

Testing

Should be tested with:

  1. Empty string (default behavior)
  2. Single exclude pattern: --exclude=docs/*
  3. Multiple switches: --exclude=docs/* --whitespace=fix
  4. Invalid switch (should fail with clear git error message)

This change will unblock backporting workflows for repositories with version-specific files that differ between branches.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix backport workflow for incompatible release notes Add additional_git_am_switches input to backport workflow for handling branch-specific files Oct 21, 2025
Copilot AI requested a review from T-Gro October 21, 2025 09:24
@T-Gro T-Gro marked this pull request as ready for review October 21, 2025 09:33
@T-Gro T-Gro requested a review from akoeplinger October 21, 2025 09:33
@akoeplinger akoeplinger enabled auto-merge (squash) October 22, 2025 15:06
@akoeplinger
Copy link
Member

/ba-g GitHub workflow not tested by AzDO

@akoeplinger akoeplinger merged commit 00d4b9b into main Oct 22, 2025
3 of 4 checks passed
@akoeplinger akoeplinger deleted the copilot/fix-backport-workflow-issues branch October 22, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants