Skip to content

Conversation

@jd
Copy link
Member

@jd jd commented Jan 13, 2026

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

Copilot AI review requested due to automatic review settings January 13, 2026 18:23
@mergify mergify bot had a problem deploying to Mergify Merge Protections January 13, 2026 18:23 Failure
@mergify
Copy link
Contributor

mergify bot commented Jan 13, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=ci-gate

🟢 👀 Review Requirements

Wonderful, this rule succeeded.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?:

🟢 🔎 Reviews

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

@mergify
Copy link
Contributor

mergify bot commented Jan 13, 2026

🧪 CI Insights

Here's what we observed from your CI run for 00548c0.

🟢 All jobs passed!

But CI Insights is watching 👀

@jd jd force-pushed the devs/jd/keep-change-id/Ic5abaa3b20d6cc789d6a20379062fbcb3d7e54ac branch from 9ad866a to 1c57403 Compare January 13, 2026 18:26
@mergify mergify bot had a problem deploying to Mergify Merge Protections January 13, 2026 18:26 Failure
@mergify mergify bot requested a review from a team January 13, 2026 18:28
Copy link

Copilot AI left a 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.py to support multiple hooks
  • Added new prepare-commit-msg hook 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.

@jd jd marked this pull request as draft January 13, 2026 18:30
@jd jd force-pushed the devs/jd/keep-change-id/Ic5abaa3b20d6cc789d6a20379062fbcb3d7e54ac branch from 1c57403 to 76efb7d Compare January 13, 2026 20:09
@mergify mergify bot had a problem deploying to Mergify Merge Protections January 13, 2026 20:09 Failure
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
@jd jd force-pushed the devs/jd/keep-change-id/Ic5abaa3b20d6cc789d6a20379062fbcb3d7e54ac branch from 76efb7d to 00548c0 Compare January 13, 2026 20:15
@mergify mergify bot deployed to Mergify Merge Protections January 13, 2026 20:15 Active
@jd jd marked this pull request as ready for review January 13, 2026 20:15
mergify bot added a commit that referenced this pull request Jan 14, 2026
@mergify
Copy link
Contributor

mergify bot commented Jan 14, 2026

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.
The checks were run on draft #910.

Required conditions to merge

@mergify mergify bot added the queued label Jan 14, 2026
@mergify mergify bot merged commit aa1cdfe into main Jan 14, 2026
18 checks passed
@mergify mergify bot deleted the devs/jd/keep-change-id/Ic5abaa3b20d6cc789d6a20379062fbcb3d7e54ac branch January 14, 2026 10:14
@mergify mergify bot removed the queued label Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants