Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions weblate/addons/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,14 @@ def squash_author(self, component: Component, repository: GitRepository) -> None
base = repository.get_last_revision()
# Cherry pick current commit (this should work
# unless something is messed up)
repository.execute(
["cherry-pick", commit, *gpg_sign],
environment={"WEBLATE_MERGE_SKIP": "1"},
)
try:
repository.execute(
["cherry-pick", commit, *gpg_sign],
environment={"WEBLATE_MERGE_SKIP": "1"},
)
except RepositoryError:
repository.execute(["cherry-pick", "--abort"])
raise
Comment on lines +221 to +223
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.

handled = []
# Pick other commits by same author
for i, other in enumerate(commits):
Expand Down
Loading