Repository navigation
fix(github): Keep co-authors when Junior rewrites commits - #2699
Merged
Merged
Conversation
The prepare-commit-msg hook removed every Co-authored-by line and added only the human actors of the current run. Runs with no human actor, such as PR event follow-ups, erased earlier credit on amend or rebase. The hook now keeps the co-authors and author of the commits that an amend, rebase, cherry-pick, fixup, squash, or merge --squash replaces. It also stops adding trailers to a one-line subject, keeps the comment block Git adds for an editor, and runs under POSIX sh. Co-Authored-By: Thomas Jiang <20501235+thomasjiangcy@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
CI has no global Git identity, so the commit made outside Junior's hooks failed with exit 128.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a8547fc. Configure here.
The hook removes Co-authored-by lines from every trailer paragraph, but read the co-authors of a rewritten commit only from its last trailer block. A squash-style message lost its earlier co-authors. The hook now reads them with the same awk rules that remove them.
thomasjiangcy
approved these changes
Nov 5, 2026
This branch was successfully deployed
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.

The
prepare-commit-msghook removes everyCo-authored-byline, then adds only the human actors of the current run. A run with no human actor (PR event follow-ups, automations, child agents) adds nobody. So when one of those runs amends or rebases, earlier credit is gone. That's how #2647 lost dingsdax's credit: apull_request.comment.createdfollow-up rebased the branch and force-pushed, and none of the new commits had his trailer.The hook now builds co-authors from the commits being replaced, then appends the current run's human actors. It finds those commits from Git state:
--amend,-c/-C,reword: the source commit.--amend -m/-Fgive no commit arg, so the hook reads--amendfrom the parentgit commitcmdline.pickandcherry-pick:CHERRY_PICK_HEAD. A conflicted rebase step:REBASE_HEAD. Aneditstop (rebase-merge/amend) that makes a new commit gets no inherited credit.fixup/squash: HEAD plus the folded commit. Rebased merges: themerge -Ccommit.merge --squash: the commits listed inSQUASH_MSG.Model-written message text still can't add co-authors. Trailers are deduped by email, and the bot is excluded.
Other bugs found while reproducing:
rebase --continueof a commit a person authored, because Git passes the original author to the hook. It now accepts the author of a replaced commit only. A new commit with a spoofed author still fails.chore: basewas read as a trailer block, soCo-Authored-Bygot stuck right under the subject. The subject paragraph is never trailers now, and a trailer key has to start with a capital letter (or beco-authored-by), sofeat: xlines in squash messages stay body text.shnow (passes shellcheck, tested under dash).-efis replaced with apwd -Pcomparison.Known limits:
rebase --applyandgit amdon't runprepare-commit-msg.-C <any sha>reuses that commit's co-authors and author.--amend -mdetection depends on/proc, so it only works on Linux (the sandbox).core.hooksPathoverrides orcommit-treeskip the hook. This is a guardrail, not a security boundary.Follow-up, not in this PR: runs with no human actor on a PR could credit the PR's stored requester, so brand-new fixup commits get credit too.
via @thomasjiangcy.
--
View Session [Sentry]