-
Notifications
You must be signed in to change notification settings - Fork 11
fix(stack): preserve Change-Id when amending commits with -m flag #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(stack): preserve Change-Id when amending commits with -m flag #903
Conversation
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 🤖 Continuous IntegrationWonderful, this rule succeeded.
🟢 👀 Review RequirementsWonderful, this rule succeeded.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 🔎 ReviewsWonderful, this rule succeeded.
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
🧪 CI InsightsHere's what we observed from your CI run for 00548c0. 🟢 All jobs passed!But CI Insights is watching 👀 |
9ad866a to
1c57403
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an issue where Change-IDs were being lost when commits are amended using git commit --amend -m "message", a common pattern used by tools like Claude Code. The solution adds a new prepare-commit-msg git hook that detects amend operations and preserves the original Change-ID.
Changes:
- Refactored hook installation logic in
setup.pyto support multiple hooks - Added new
prepare-commit-msghook to preserve Change-IDs during amends with -m flag - Added comprehensive integration tests covering various commit and amend scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| mergify_cli/tests/stack/test_setup.py | Added integration tests for hook behavior with real git repository, including tests for new commits, amends with/without -m flag, and Change-ID preservation |
| mergify_cli/stack/setup.py | Refactored hook installation into reusable _install_hook() function to support installing both commit-msg and prepare-commit-msg hooks |
| mergify_cli/stack/hooks/prepare-commit-msg | New shell script hook that detects amend operations by comparing author dates and preserves Change-ID from HEAD when amending with -m/-F flags |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1c57403 to
76efb7d
Compare
When tools like Claude Code amend commits using `git commit --amend -m "msg"`, the Change-Id was being lost because: 1. The -m flag replaces the entire commit message 2. The commit-msg hook only preserves Change-Id if already present in the message This adds a prepare-commit-msg hook that detects amend operations and preserves the original Change-Id. The detection works by comparing GIT_AUTHOR_DATE (which git sets to the original commit's author date during --amend) with HEAD's author date. An additional check ensures the date is at least 2 seconds old to avoid false positives when commits happen in quick succession. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Change-Id: Ic5abaa3b20d6cc789d6a20379062fbcb3d7e54ac
76efb7d to
00548c0
Compare
Merge Queue Status✅ The pull request has been merged at 00548c0 This pull request spent 2 minutes 21 seconds in the queue, including 1 minute 47 seconds running CI. Required conditions to merge
|
When tools like Claude Code amend commits using
git commit --amend -m "msg",the Change-Id was being lost because:
This adds a prepare-commit-msg hook that detects amend operations and preserves
the original Change-Id. The detection works by comparing GIT_AUTHOR_DATE (which
git sets to the original commit's author date during --amend) with HEAD's author
date. An additional check ensures the date is at least 2 seconds old to avoid
false positives when commits happen in quick succession.
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com