fix(post-checkout): scaffold only on clone/init - #393
Merged
Merged
Conversation
The .claude/ scaffold copy was gated only on branch_checkout == 1 and on .claude/ being absent. Guards 0a (null prev_head) and 0b (linked worktree: --absolute-git-dir differs from --git-common-dir) protected only the ignore entry, which runs after the copy. So `git checkout -b` and `git worktree add -b` both copied the scaffold and left it as untracked files. In a linked worktree that also stops `git worktree remove`, and with it `gh pr merge --delete-branch`. Move both guards into is_fresh_clone_or_init and apply it before the copy, after seed_editorconfig, which keeps its own origin-remote guard. The ignore-entry function no longer repeats them. The wrapper's synthesized init call (null SHAs, main work tree) and a real clone still pass both guards. Tests: Cases C (checkout -b) and D2 (worktree add -b) now assert that no .claude/ appears; both failed against the old hook. Case H now asserts that the synthesized init call still scaffolds. Closes #392
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.
Summary
The global
post-checkouthook copied the.claude/scaffold on everygit checkout -band everygit worktree add -b, not only on a fresh clone or init. Guards 0a (nullprev_head) and 0b (linked worktree) protected only the ignore entry, which runs after the copy. The scaffold was left behind as untracked files. In a linked worktree, those files also stopgit worktree remove, and with itgh pr merge --delete-branch.Change
git/template/hooks/post-checkout: guards 0a and 0b move intois_fresh_clone_or_init, which runs before the copy and afterseed_editorconfig.seed_editorconfigis unchanged and keeps its own origin-remote guard.add_claude_gitignore_entryno longer repeats guard 0. Guards 1-3 keep their numbers. The header and guard comments now describe the new order.git rev-parsecannot answer, the hook treats the checkout as not fresh and skips. This matches the old ignore-entry behavior.Tests
bash/tests/test-post-checkout-gitignore.sh:git checkout -bin a repo with commits) asserts that no.claude/appears.git worktree add -bof an established repo) asserts that no.claude/appears in the new worktree.Against the old hook, the two new no-scaffold assertions fail:
With the fix, all four post-checkout-related files pass locally:
test-post-checkout-gitignore.sh,test-post-checkout-editorconfig-seed.sh,test-post-checkout-hookspath.sh,test-git-wrapper-init-hook.sh. The full suite runs in CI asbash-tests.shellcheck -S infowith the canonical config is clean on both files.Closes #392