Skip to content

fix(git): abort cherry-pick on failure#18334

Closed
sentry[bot] wants to merge 1 commit intomainfrom
seer/fix/abort-cherry-pick-on-failure
Closed

fix(git): abort cherry-pick on failure#18334
sentry[bot] wants to merge 1 commit intomainfrom
seer/fix/abort-cherry-pick-on-failure

Conversation

@sentry
Copy link
Contributor

@sentry sentry bot commented Mar 3, 2026

Fixes WEBLATE-37ZV.

The issue was that: Cherry-pick fails due to merge conflicts, and the custom merge driver's immediate exit on WEBLATE_MERGE_SKIP causes RepositoryError to be raised.

This pull request addresses the issue by:

  • Adding a try-except block around the git cherry-pick command.
  • If cherry-pick fails, git cherry-pick --abort is executed to clean up the repository state.
  • The original RepositoryError is then re-raised.

This fix was generated by Seer in Sentry, triggered by Michal Čihař. 👁️ Run ID: 857074

Not quite right? Click here to continue debugging with Seer.

@sentry sentry bot requested a review from nijel March 3, 2026 16:31
@nijel nijel self-assigned this Mar 3, 2026
@nijel nijel added this to the 5.17 milestone Mar 3, 2026
@nijel nijel marked this pull request as ready for review March 3, 2026 16:31
@nijel nijel enabled auto-merge (rebase) March 3, 2026 16:31
Comment on lines +221 to +223
except RepositoryError:
repository.execute(["cherry-pick", "--abort"])
raise
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bug: The error handler for a failed git cherry-pick unconditionally calls cherry-pick --abort, which can fail and mask the original error if no cherry-pick was in progress.
Severity: MEDIUM

Suggested Fix

Before calling repository.execute(["cherry-pick", "--abort"]), check if a cherry-pick operation is actually in progress. This can be done by verifying the existence of the .git/CHERRY_PICK_HEAD file, for example: if repository.has_git_file("CHERRY_PICK_HEAD"): repository.execute(["cherry-pick", "--abort"]). This aligns with the established defensive pattern used for rebase and merge aborts in the codebase.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: weblate/addons/git.py#L221-L223

Potential issue: The new error handling in the `squash_author` method calls
`repository.execute(["cherry-pick", "--abort"])` within an `except RepositoryError`
block. However, if the initial `cherry-pick` fails for reasons that do not leave the
repository in a cherry-pick state (e.g., an invalid commit reference), the `cherry-pick
--abort` command will also fail. This second failure raises a new `RepositoryError`,
masking the original, more informative error. This behavior is inconsistent with
existing patterns for `rebase --abort` and `merge --abort` in the codebase, which check
the repository state before attempting to abort. The same issue exists in a second
`cherry-pick` operation in the same method.

Did we get this right? 👍 / 👎 to inform future reviews.

@nijel
Copy link
Member

nijel commented Mar 3, 2026

Superseeded by #18337

@nijel nijel closed this Mar 3, 2026
auto-merge was automatically disabled March 3, 2026 16:47

Pull request was closed

@nijel nijel deleted the seer/fix/abort-cherry-pick-on-failure branch March 3, 2026 16:47
@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.98%. Comparing base (7e5b583) to head (239f46d).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
weblate/addons/git.py 40.00% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (40.00%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant