Skip to content

Conversation

@danielrafailov1
Copy link

What?

Removes the --3way flag from git apply to prevent Codex from automatically staging files after applying patches.

Why?

Fixes #8405. Codex was automatically staging files after applying patches due to the --3way flag. According to man git-apply, when --3way is used and a patch applies cleanly, Git automatically stages the edited file. This was not the intended behavior and made it difficult for users to distinguish which files were actually modified when iterating over changes.

How?

  • Removed the --3way flag from the git apply command in codex-rs/utils/git/src/apply.rs
  • Added test apply_does_not_stage_files() to verify files are not staged after applying patches

All existing tests pass, and the new test confirms the fix works as expected.

Fixes issue openai#8405 where Codex was automatically staging files after
applying patches. The --3way flag causes git apply to stage files when
patches apply cleanly, which was not the intended behavior.

- Remove --3way flag from git apply command
- Add test to verify files are not staged after applying patches
@github-actions
Copy link
Contributor

github-actions bot commented Dec 26, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@danielrafailov1
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 54 to 56
// Build git args
let mut args: Vec<String> = vec!["apply".into(), "--3way".into()];
let mut args: Vec<String> = vec!["apply".into()];
if req.revert {
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Removing --3way breaks fallback application

Dropping --3way from the git apply invocation removes the three-way merge fallback, so any patch that no longer applies cleanly to the working tree now fails outright instead of merging or emitting conflict markers. git apply -h documents that --3way attempts a three-way merge before falling back to a normal patch; without it, ApplyGitResult will return non-zero for patches that previously succeeded (or produced conflicts) when the local tree had drifted, reducing the tool’s ability to apply user patches in common workflows with local edits or slightly outdated diffs.

Useful? React with 👍 / 👎.

@danielrafailov1
Copy link
Author

recheck

github-actions bot added a commit that referenced this pull request Dec 26, 2025
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.

GPT 5.2 keeps staging its changes

1 participant