Commit 3d5deb5
fix(husky): stage server files from worktree root in pre-commit hook (#41835)
## Summary
- Pre-commit hook stages server files at the wrong path when committing
from a linked git worktree, creating an orphan tree at the worktree root
in addition to the correct entry.
- Root cause: git invokes hooks with `GIT_DIR` set but `GIT_WORK_TREE`
unset. After `pushd app/server`, `git add` falls back to treating cwd as
the worktree root, so `xargs git add appsmith-interfaces/...` (with the
`app/server/` prefix stripped) stages files at the wrong location. Only
affects worktrees, not the main checkout.
- Fix: run `mvn spotless:apply` in a subshell (so the script's cwd stays
at worktree root), and stage with full `app/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 the `app/server/` prefix. Verified by simulating the hook env
(`GIT_DIR` set, cwd at `app/server/`) and running the old vs new `git
add` invocation; old path produces the duplicate orphan entry, new path
produces only the correct entry.
## Test plan
- [ ] Commit a server file change from a linked git worktree (`git
worktree add ...`); confirm `git status` after commit shows no orphan
entries at the worktree root.
- [ ] Commit a server file change from the main checkout; confirm
spotless still runs and re-staging works as before.
- [ ] Commit a client-only change; confirm `lint-staged` still runs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Chores**
* Updated internal code formatting automation to improve developer
workflow efficiency.
---
**Note:** This release contains no user-facing changes. The update
addresses internal development tooling.
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/appsmithorg/appsmith/pull/41835?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent 51c5591 commit 3d5deb5
1 file changed
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | | - | |
11 | | - | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
26 | | - | |
27 | 30 | | |
28 | | - | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
0 commit comments