Skip to content

fix(githooks): install hooks in the directory git runs them from - #13

Closed
peterkc wants to merge 1 commit into
mainfrom
fix/githook-hooks-path
Closed

peterkc wants to merge 1 commit into
mainfrom
fix/githook-hooks-path

Conversation

@peterkc

@peterkc peterkc commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Summary

gortex githook install could write the hook to a directory that Git never runs hooks from, so the hook was installed but never ran. uninstall and status looked in the same wrong place.

  • In a linked worktree, git rev-parse --git-dir names the worktree's own directory (.git/worktrees/<name>). Git runs hooks from the shared hooks/ directory instead.
  • With a relative core.hooksPath, the path was joined to the current directory. Run from a subdirectory, the hook went to <subdir>/<hooksPath>, while Git resolves the setting from the top of the worktree.

Changes

  • HookPathFor asks Git for the hooks directory with git rev-parse --path-format=absolute --git-path hooks. Git then applies core.hooksPath, the shared directory of linked worktrees and relative paths itself. This follows the pattern in internal/gitstate/gitstate.go.
  • Git older than 2.31 has no --path-format. The fallback uses git rev-parse --git-path hooks and makes a relative result absolute. That fallback was not tested on an old Git.
  • New tests cover the default hooks directory from the main worktree and from a linked worktree, and a relative core.hooksPath used from a subdirectory. Both new tests fail on main.

Testing

  • All tests pass (go test -race ./...)
  • New tests added for new functionality
  • Benchmarks run if performance-relevant

go test -race ./internal/githooks/ passes. go vet and golangci-lint report no issues for the changed package.

Checklist

  • Code follows existing patterns in the codebase
  • No unnecessary abstractions added

Use the common hooks directory in linked worktrees and resolve relative
core.hooksPath from the worktree root when called from a subdirectory.
@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Git hook installation now resolves the hooks directory more reliably in main repositories and linked worktrees, including when invoked from a subdirectory or when the hooks path is relative.
    • Hook path checks now account for symlinks when verifying that hooks remain within the repository.

Walkthrough

HookPathFor now asks Git for the hooks directory and falls back when the first result is unavailable or relative. Tests cover default paths in main and linked worktrees, relative custom paths, and resolved-path containment.

Changes

Git hook path resolution

Layer / File(s) Summary
Resolve and verify the hooks path
internal/githooks/install.go, internal/githooks/install_test.go
HookPathFor uses git rev-parse --git-path hooks and resolves relative fallback results against repoRoot. Tests check default paths in main and linked worktrees, relative custom paths from a subdirectory, and resolved-path containment. The package comment describes Git invocation as limited to git rev-parse.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: madeinoz67

Merge Risk: 🔵 Low · up to 91633

Hook installation, removal, and status can target the wrong directory when invoked from a subdirectory on Git 2.12 with a relative hooks path. This is a narrow compatibility issue that should be fixed or explicitly accepted before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the hook-directory fix. At 64 characters, it exceeds the preferred 50-character length, but it remains concise and specific enough to identify the change.
Description check ✅ Passed The description explains the linked-worktree and relative core.hooksPath problems, the implementation, and the tests. It is directly related to the changeset.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 90580e1d-5951-418a-90b9-8f1416dcfa5c
📥 Commits

Reviewing files that changed from the base of the PR and between b36a02d and 916333c.

📒 Files selected for processing (2)
  • internal/githooks/install.go
  • internal/githooks/install_test.go

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour. Your free on-demand review promotion remains active until October 9, 2026 at 6:00 PM UTC.

📜 Review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: test (macos-latest, 1.27)
  • GitHub Check: trivy-fs
  • GitHub Check: build-onnx
  • GitHub Check: build-linux-static
  • GitHub Check: benchmark
  • GitHub Check: test (ubuntu-latest, 1.27)
  • GitHub Check: lint
  • GitHub Check: govulncheck
  • GitHub Check: test (windows-latest, 1.27)

Comment thread internal/githooks/install.go
@peterkc

peterkc commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

Continued upstream as zzet#867

@peterkc peterkc closed this Oct 3, 2026
@peterkc
peterkc deleted the fix/githook-hooks-path branch October 4, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant