Conversation
…icts `stack_squash` with `-m` writes the new commit message to a temp file and inserts an `exec git commit --amend -F <tmpfile>` line in the rebase todo. The previous code wrapped the rebase in `try/finally` so the temp file was unlinked even when the rebase failed mid-way (e.g. conflicts on a fixup line that runs before the exec). After the user resolved conflicts and ran `git rebase --continue`, git would replay the exec line and fail because the message file no longer existed. Drop the `finally`; only unlink on the success path. If the rebase raises SystemExit, the file persists so `--continue` can still execute the amend. The temp file lives in `/tmp` and gets cleaned by the OS. Same pattern (and same fix) as `stack_reword` — flagged by Copilot on Change-Id: Ia026b5b631ed043a03983beec5ca81fd29f77633 #1384 review.
Contributor
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 👀 Review RequirementsWaiting for
This rule is failing.
🔴 🔎 ReviewsWaiting for
This rule is failing.
🟢 🤖 Continuous IntegrationWonderful, this rule succeeded.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
There was a problem hiding this comment.
Pull request overview
Adjusts stack_squash -m/--message to avoid deleting the temporary commit-message file when an interactive rebase stops mid-way (e.g., due to conflicts), so git rebase --continue can still replay the inserted exec git commit --amend -F <tmpfile> line successfully.
Changes:
- Removes the
try/finallycleanup around the temp message file instack_squash. - Unlinks the temp message file only after a successful
run_action_rebasecompletion. - Adds inline rationale explaining why the file must persist across conflict-driven rebase interruptions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # SystemExit (conflicts), the rebase-todo still references this | ||
| # file, so `git rebase --continue` will need it to complete the | ||
| # `exec git commit --amend -F …` line. Leak the file rather than | ||
| # break --continue; /tmp gets cleaned by the OS. |
Comment on lines
152
to
+167
| msg_fd, msg_path = tempfile.mkstemp(suffix=".txt", prefix="mergify_squash_msg_") | ||
| try: | ||
| with os.fdopen(msg_fd, "w") as f: | ||
| f.write(message) | ||
| run_action_rebase( | ||
| base, | ||
| new_shas, | ||
| actions, | ||
| exec_after_sha=src_shas[-1], | ||
| exec_command=f"git commit --amend -F {shlex.quote(msg_path)}", | ||
| ) | ||
| finally: | ||
| pathlib.Path(msg_path).unlink(missing_ok=True) | ||
| with os.fdopen(msg_fd, "w") as f: | ||
| f.write(message) | ||
| # Intentionally NOT in a `finally`: if `run_action_rebase` raises | ||
| # SystemExit (conflicts), the rebase-todo still references this | ||
| # file, so `git rebase --continue` will need it to complete the | ||
| # `exec git commit --amend -F …` line. Leak the file rather than | ||
| # break --continue; /tmp gets cleaned by the OS. | ||
| run_action_rebase( | ||
| base, | ||
| new_shas, | ||
| actions, | ||
| exec_after_sha=src_shas[-1], | ||
| exec_command=f"git commit --amend -F {shlex.quote(msg_path)}", | ||
| ) | ||
| pathlib.Path(msg_path).unlink(missing_ok=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stack_squashwith-mwrites the new commit message to a temp fileand inserts an
exec git commit --amend -F <tmpfile>line in therebase todo. The previous code wrapped the rebase in
try/finallysothe temp file was unlinked even when the rebase failed mid-way (e.g.
conflicts on a fixup line that runs before the exec). After the user
resolved conflicts and ran
git rebase --continue, git would replaythe exec line and fail because the message file no longer existed.
Drop the
finally; only unlink on the success path. If the rebaseraises SystemExit, the file persists so
--continuecan still executethe amend. The temp file lives in
/tmpand gets cleaned by the OS.Same pattern (and same fix) as
stack_reword— flagged by Copilot on#1384 review.