Repository navigation
fix(setup-hooks): work in a linked git worktree (#137) - #142
royosherove wants to merge 2 commits into
Conversation
setup-hooks.sh checked for a .git directory and wrote the hook to <repo>/.git/hooks. In a linked worktree, .git is a file, so the script printed "not a git repository" and exited 1. Git also does not read hooks from that path in a linked worktree. The script now uses git rev-parse --git-dir to find the repository and git rev-parse --git-path hooks to find the hooks directory that git reads. That path is in the common git directory for a linked worktree, and it obeys core.hooksPath. tests/test-setup-hooks.sh makes a temporary repository with a linked worktree and runs the script in both. It fails on main and passes with this fix. Crew: Drew (Kiro Crew Issue Radar)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 63b1808ba2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| if [[ ! -d "${REPO_ROOT}/.git" ]]; then | ||
| # In a linked worktree, .git is a file, so ask git for the git directory. | ||
| if ! git -C "${REPO_ROOT}" rev-parse --git-dir >/dev/null 2>&1; then |
There was a problem hiding this comment.
Reject repositories found only in an ancestor
When an unpacked or vendored copy of Lowkey resides inside an unrelated Git checkout, rev-parse --git-dir walks up to that ancestor and succeeds. The script then silently installs Lowkey's hook into the outer repository even though REPO_ROOT is not its worktree root, rather than reporting “not a git repository” as before. Verify that git rev-parse --show-toplevel matches REPO_ROOT while still allowing linked worktrees.
Useful? React with 👍 / 👎.
|
|
||
| # Use the hooks directory that git reads. In a linked worktree this is in the | ||
| # common git directory. It also obeys core.hooksPath. | ||
| HOOKS_DIR="$(git -C "${REPO_ROOT}" rev-parse --git-path hooks)" |
There was a problem hiding this comment.
Avoid copying the hook onto itself
When core.hooksPath is configured as scripts—including through a global configuration—this resolves HOOKS_DIR to the directory already containing the source hook. The later cp scripts/pre-commit scripts/pre-commit exits with “are the same file” under set -e, so setup fails for a valid hooks-path configuration that this change intends to support. Detect an identical source and destination and only ensure the existing hook is executable.
Useful? React with 👍 / 👎.
Make sure that the git worktree root is the repository root. If git finds only an ancestor repository, stop with exit 1 and do not install a hook into it. If core.hooksPath points to scripts/, do not copy the hook onto itself. Add tests for both cases. Crew: Drew (Kiro Crew Issue Radar)
Summary
Fixes #137.
scripts/setup-hooks.shchecked for a.gitdirectory and wrote the hook to<repo>/.git/hooks. In a linked worktree (git worktree add),.gitis a file. The script printed "not a git repository" and exited 1. Git also does not read hooks from that path in a linked worktree.Changes
git rev-parse --git-dirto make sure that it is in a git repository.git rev-parse --git-path hooksto find the hooks directory that git reads. In a linked worktree, this is in the common git directory. It also obeyscore.hooksPath. A relative result is made absolute against the repository root. The script does not use--path-format=absolute, because that option needs git 2.31 or later.tests/test-setup-hooks.sh. It makes a temporary repository with a linked worktree and runs the script in the main checkout, in the linked worktree, and outside a repository.Testing
tests/test-setup-hooks.shonmain: 2 of 6 checks fail, exit 1.bash -n scripts/setup-hooks.sh: no syntax errors.Crew: Drew (Kiro Crew Issue Radar)