Skip to content

fix(github): Keep co-authors when Junior rewrites commits - #2699

Merged
thomasjiangcy merged 3 commits into
mainfrom
fix/github-keep-coauthors-on-rewrite
Nov 5, 2026
Merged

thomasjiangcy merged 3 commits into
mainfrom
fix/github-keep-coauthors-on-rewrite

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

The prepare-commit-msg hook removes every Co-authored-by line, 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: a pull_request.comment.created follow-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/-F give no commit arg, so the hook reads --amend from the parent git commit cmdline.
  • rebase pick and cherry-pick: CHERRY_PICK_HEAD. A conflicted rebase step: REBASE_HEAD. An edit stop (rebase-merge/amend) that makes a new commit gets no inherited credit.
  • fixup/squash: HEAD plus the folded commit. Rebased merges: the merge -C commit. merge --squash: the commits listed in SQUASH_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:

  • The author check failed on an amend or rebase --continue of 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.
  • A one-line unscoped subject like chore: base was read as a trailer block, so Co-Authored-By got stuck right under the subject. The subject paragraph is never trailers now, and a trailer key has to start with a capital letter (or be co-authored-by), so feat: x lines in squash messages stay body text.
  • The comment block Git adds for an editor (conflicts, squash) broke trailer detection. Trailers now go before it.
  • The hook is POSIX sh now (passes shellcheck, tested under dash). -ef is replaced with a pwd -P comparison.

Known limits:

  • rebase --apply and git am don't run prepare-commit-msg.
  • -C <any sha> reuses that commit's co-authors and author.
  • The --amend -m detection depends on /proc, so it only works on Linux (the sandbox).
  • core.hooksPath overrides or commit-tree skip 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]

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>
@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 5, 2026 12:54am UTC

Request Review

CI has no global Git identity, so the commit made outside Junior's hooks
failed with exit 128.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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
thomasjiangcy merged commit 7e357ce into main Nov 5, 2026
44 checks passed
@thomasjiangcy
thomasjiangcy deleted the fix/github-keep-coauthors-on-rewrite branch November 5, 2026 04:06

This branch was successfully deployed

1 active deployment
Preview – junior-docs — e58e6a2b Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant