Skip to content

Comments

Fix silent git am failure on CRLF repositories in safe_outputs patch application#18029

Merged
pelikhan merged 5 commits intomainfrom
copilot/fix-crlf-line-ending-issue
Feb 24, 2026
Merged

Fix silent git am failure on CRLF repositories in safe_outputs patch application#18029
pelikhan merged 5 commits intomainfrom
copilot/fix-crlf-line-ending-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

Repositories with CRLF line endings (e.g., .gitattributes: * -crlf) cause git am to silently fail when applying git format-patch output — git-mailsplit strips \r during parsing, producing an LF diff that can't match the CRLF working tree. The workflow run appears green but no PR is created.

Changes

  • pkg/workflow/git_configuration_steps.go and compiler_safe_outputs_steps.go: Add git config --global am.keepcr true to the "Configure Git credentials" step, preserving \r in patch content during git am application. Safe for LF-only repos — no behavioral change when \r is absent.
  • Golden files / lock files: Regenerated all 158 compiled workflow lock files to reflect the new config line.
  • git_config_test.go: Updated step-count assertion (11→12) and added assertion for the new am.keepcr line.
  • smoke-multi-pr.md: Updated PR 2 to create a file with CRLF line endings (printf "...\r\n...") as a regression test for this fix. Added printf * to the allowed bash tools. The agent verifies CRLF endings via cat -A before submitting the PR.

The fix mirrors the workaround described in the issue: setting am.keepcr=true globally before any patch application step.

Original prompt

This section details on the original issue you should resolve

<issue_title>Code Simplification agent silently fails to create PRs when the repo stores line endings as CRLF</issue_title>
<issue_description>The agentic-workflows agent was able to diagnose why no PR was generated despite the workflow run being green and supplied a workaround. Here is its summary:

Summary

When a repository uses CRLF line endings (e.g., via * -crlf in .gitattributes), the safe_outputs handler's git am call silently fails to
apply patches generated by git format-patch. The agent successfully identifies changes and calls safeoutputs-create_pull_request, but no PR or
issue is ever created. The only evidence of failure is in the job logs.

Root Cause

git format-patch correctly preserves CRLF in diff content lines (context and change lines). However, git am uses git-mailsplit to parse the
mailbox-format patch, which strips \r from all lines during parsing. This produces a diff with LF line endings that cannot match the CRLF content
in the working tree.

The failure cascade:

  1. Text apply fails: LF diff context lines don't match CRLF working tree files
  2. 3-way merge also fails (even with am.threeWay=true): The LF-stripped diff can't apply to the pre-image blob either (which also has CRLF
    content), so git can't construct the theirs side of the merge
  3. git am exits with code 128, handler reports Failed to apply patch
  4. No PR, no issue, no user-visible feedback — the workflow appears to succeed but produces nothing

Reproduction

Any repository with these characteristics will hit this bug:

  • .gitattributes contains * -crlf or * -text (disabling line ending normalization)
  • Source files were committed from Windows with CRLF line endings
  • An agentic workflow uses create_pull_request safe output

Error Output

[command]/usr/bin/git am /tmp/gh-aw/aw.patch                                                                                   ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes github/gh-aw#17975

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/github/gh-aw/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.


---

## Changeset

- **Type**: patch
- **Description**: Configure `git am` to keep CRLF when applying safe_outputs patches so CRLF repositories can create PRs reliably.

> Generated by [Changeset Generator](https://github.com/github/gh-aw/actions/runs/22334817320) for issue #18029

> [!WARNING]
> <details>
> <summary>⚠️ Firewall blocked 1 domain</summary>
>
> The following domain was blocked by the firewall during workflow execution:
>
> - `github.com`
>
> </details>


<!-- gh-aw-agentic-workflow: Changeset Generator, engine: codex, model: gpt-5.1-codex-mini, id: 22334817320, workflow_id: changeset, run: https://github.com/github/gh-aw/actions/runs/22334817320 -->

@pelikhan
Copy link
Contributor

@copilot update smoke-pr agentic workflow to create a file with mixed newline endings and add it to the repo

…ion steps

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate CRLF line endings issue in PR creation Fix silent git am failure on CRLF repositories in safe_outputs patch application Feb 24, 2026
@pelikhan pelikhan added the smoke label Feb 24, 2026
@github-actions
Copy link
Contributor

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@copilot update smoke-pr agentic workflow to create a file with mixed newline endings and add it to the repo

Updated smoke-multi-pr.md in commit 127aed9:

  • PR 2 now creates a file with CRLF line endings using printf "...\r\n...", which directly exercises the am.keepcr=true fix
  • Added printf * to the allowed bash tools so the agent can create CRLF files
  • The agent verifies the file has CRLF endings via cat -A (lines should end with ^M$)
  • Updated success criteria to confirm CRLF handling passed

@github-actions
Copy link
Contributor

Commit pushed: 0326647

Generated by Changeset Generator

@github-actions
Copy link
Contributor

Smoke test results for PR #18029
PR titles: #18031 Update README with llms.txt download instruction; #18021 [WIP] Update activation comments with AI message footer
GitHub MCP (2 merged PRs) ✅
Serena activate+find_symbol ✅
Playwright title contains GitHub ✅
Web-fetch contains GitHub ✅
File write+cat ✅
Build make build
Overall: PASS

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Contributor

Smoke Test Results - Run §22334817339

Test Status
GitHub MCP
Safe Inputs GH CLI
Serena MCP ⚠️
Playwright
Web Fetch
File Writing + Bash
Discussion Interaction
Build gh-aw
Discussion Creation
Workflow Dispatch
PR Review

Overall: PASS ✅

PR by @app/copilot-swe-agent · Assignees: @pelikhan, @Copilot

📰 BREAKING: Report filed by Smoke Copilot

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds git config --global am.keepcr true consistently across all compiled lock files, preserving carriage returns when applying patches. Good cross-platform defensive fix. Source markdown files should also be updated to avoid regression on recompile.

📰 BREAKING: Report filed by Smoke Copilot

run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git config --global am.keepcr true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent application of am.keepcr true across all lock files ensures uniform behavior. Since these are compiled from .md sources, this change should also be reflected in the source markdown to avoid regression when recompiling.

@pelikhan pelikhan marked this pull request as ready for review February 24, 2026 03:09
Copilot AI review requested due to automatic review settings February 24, 2026 03:09
@github-actions
Copy link
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@pelikhan pelikhan merged commit 8cb3b78 into main Feb 24, 2026
44 checks passed
@pelikhan pelikhan deleted the copilot/fix-crlf-line-ending-issue branch February 24, 2026 03:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical bug where git am silently fails when applying patches in repositories with CRLF line endings. The issue occurs because git-mailsplit strips \r during patch parsing, creating an LF diff that cannot match CRLF working tree files. The fix adds git config --global am.keepcr true to preserve carriage returns during patch application.

Changes:

  • Added am.keepcr configuration to all git setup steps in the workflow compiler
  • Updated tests to verify the new configuration is present
  • Enhanced smoke-multi-pr workflow to test CRLF line ending handling
  • Regenerated all 158 workflow lock files to reflect the new configuration

Reviewed changes

Copilot reviewed 167 out of 167 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/workflow/git_configuration_steps.go Added am.keepcr true configuration to standard git setup
pkg/workflow/compiler_safe_outputs_steps.go Added am.keepcr true configuration to safe outputs git setup
pkg/workflow/git_config_test.go Updated test assertions for new configuration line (11→12 lines)
.github/workflows/smoke-multi-pr.md Added CRLF regression test with printf tool and verification
.changeset/patch-preserve-crlf-in-safe-outputs.md Added changeset documenting the patch fix
.github/workflows/*.lock.yml (158 files) Regenerated lock files with new git configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 Automated smoke test review - all systems nominal!

💥 [THE END] — Illustrated by Smoke Claude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants