fix(husky): stage server files from worktree root in pre-commit hook#41835
fix(husky): stage server files from worktree root in pre-commit hook#41835wyattwalter wants to merge 1 commit into
Conversation
When git runs the pre-commit hook in a linked worktree it sets GIT_DIR but leaves GIT_WORK_TREE unset, so `git add` from a subdirectory treats cwd as the worktree root. The previous flow pushd'd into app/server, stripped the app/server/ prefix from the path list, then ran `git add appsmith-interfaces/...` — which staged an orphan tree at the worktree root in addition to the correct entry. Only manifested on worktrees, not the main checkout. Run mvn in a subshell instead of pushd'ing, and stage with full app/server/ paths from the worktree root. Behavior is unchanged in the main checkout and now correct in worktrees too. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe Git hook ChangesSpotless execution context refactoring
🎯 2 (Simple) | ⏱️ ~8 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
GIT_DIRset butGIT_WORK_TREEunset. Afterpushd app/server,git addfalls back to treating cwd as the worktree root, soxargs git add appsmith-interfaces/...(with theapp/server/prefix stripped) stages files at the wrong location. Only affects worktrees, not the main checkout.mvn spotless:applyin a subshell (so the script's cwd stays at worktree root), and stage with fullapp/server/...paths via the unchanged path list. Same behavior in the main checkout; correct behavior in worktrees.Reproduction
In a linked worktree with a staged change under
app/server/, the hook stages the file twice — once correctly and once at the worktree root without theapp/server/prefix. Verified by simulating the hook env (GIT_DIRset, cwd atapp/server/) and running the old vs newgit addinvocation; old path produces the duplicate orphan entry, new path produces only the correct entry.Test plan
git worktree add ...); confirmgit statusafter commit shows no orphan entries at the worktree root.lint-stagedstill runs.🤖 Generated with Claude Code
Summary by CodeRabbit
Note: This release contains no user-facing changes. The update addresses internal development tooling.