scripts: push-split scrubs trailers from a throwaway worktree so a dirty main tree can't abort the push

This commit is contained in:
Local Dev 2026-09-10 22:39:58 +02:00
parent 8dae3f3008
commit b0559fc99a

View file

@ -59,9 +59,20 @@ git subtree split --prefix="$prefix" HEAD -b "$branch" >/dev/null
# "Co-authored-by: Claude ..." trailers from the ephemeral branch before push.
# Local monorepo history is untouched — only what lands on the forge is filtered.
echo "→ scrubbing Co-Authored-By: Claude trailers from $branch …"
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --msg-filter '
# filter-branch refuses to run from a dirty working tree ("You have unstaged
# changes"), and with set -e that silently aborted the push whenever another
# session had uncommitted edits. Run it from a throwaway worktree of the
# ephemeral branch instead — refs are shared, the main tree is never touched.
scrubwt=$(mktemp -d "${TMPDIR:-/tmp}/push-split-XXXXXX")
git worktree add --detach --quiet "$scrubwt" "$branch"
if ! (cd "$scrubwt" && FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --msg-filter '
sed -e "/^Co-[Aa]uthored-[Bb]y: Claude.*/d"
' "$branch" >/dev/null 2>&1
' "$branch" >/dev/null 2>&1); then
git worktree remove --force "$scrubwt" >/dev/null 2>&1 || true
echo "error: trailer scrub failed — not pushing." >&2
exit 1
fi
git worktree remove --force "$scrubwt" >/dev/null 2>&1 || true
# filter-branch leaves refs/original/refs/heads/$branch as a backup — delete it
# so it can not be pushed by accident (--mirror isn't used here, but be safe).
git update-ref -d "refs/original/refs/heads/$branch" 2>/dev/null || true