Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab1fd304ae
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| except Exception: | ||
| _restore_patch_target(snapshot) |
There was a problem hiding this comment.
Restore the staged index entry after a failed commit
GitAudit.commit_paths() runs git add before attempting the commit, so when the commit fails—for example, because a pre-commit hook rejects it—this handler restores only the working-tree file while leaving the failed patch staged. The approval remains pending, but a later unrelated git commit can silently record that patch; snapshot and restore the target's prior index state as part of this rollback.
Useful? React with 👍 / 👎.
| existed = path.exists() | ||
| content = path.read_text(encoding="utf-8") if existed else None | ||
| return PatchTargetSnapshot(path=path, existed=existed, content=content) |
There was a problem hiding this comment.
Preserve the target's exact bytes in the snapshot
When an existing target uses CRLF line endings, read_text() performs universal-newline conversion and the later write_text() restoration writes normalized platform line endings. On Linux, a failed commit therefore changes the supposedly restored file from CRLF to LF; use byte-oriented snapshot and restoration so rollback reproduces the original content exactly.
Useful? React with 👍 / 👎.
| try: | ||
| yield | ||
| except Exception: | ||
| _restore_patch_target(snapshot) |
There was a problem hiding this comment.
Restore the target when patch application is interrupted
If the user interrupts patch application or the Git commit with Ctrl-C, KeyboardInterrupt bypasses this except Exception block, leaving the applied file—and potentially its staged entry—in place even though the command never completed. Cleanup context managers should restore on BaseException (and then re-raise) so cancellation receives the same integrity guarantee as ordinary failures.
Useful? React with 👍 / 👎.
ab1fd30 to
19415de
Compare
Summary
Adds a small workspace integrity guard around patch application.
Changes
Closes #64.
Validation
CI should run on this PR.