Skip to content

Commit 5c0aa86

Browse files
committed
fix(init): resolve hooks path relative to repo root
Ensure that `core.hooksPath` is resolved relative to the repository root of the current worktree, or the git dir if it is bare. This should be the same logic as git uses for resolution.
1 parent 7e8853e commit 5c0aa86

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

git-branchless-lib/src/core/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ pub fn get_main_worktree_hooks_dir(
5454
let hooks_path = if result.exit_code.is_success() {
5555
let path = String::from_utf8(result.stdout)
5656
.context("Decoding git config output for hooks path")?;
57-
PathBuf::from(path.strip_suffix('\n').unwrap_or(&path))
57+
58+
let path = PathBuf::from(path.strip_suffix('\n').unwrap_or(&path));
59+
60+
repo.get_working_copy_path()
61+
.as_deref()
62+
.unwrap_or_else(|| repo.get_path())
63+
.join(path)
5864
} else {
5965
get_default_hooks_dir(repo)?
6066
};

git-branchless/tests/test_init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ fn test_init_core_hooks_path_warning() -> eyre::Result<()> {
547547
Auto-detected your main branch as: master
548548
If this is incorrect, run: git branchless init --main-branch <branch>
549549
Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
550-
Warning: the configuration value core.hooksPath was set to: my-hooks,
550+
Warning: the configuration value core.hooksPath was set to: <repo-path>/my-hooks,
551551
which is not the expected default value of: <repo-path>/.git/hooks
552552
The Git hooks above may have been installed to an unexpected global location.
553553
Successfully installed git-branchless.
@@ -600,7 +600,7 @@ hooksPath = my-hooks
600600
Auto-detected your main branch as: master
601601
If this is incorrect, run: git branchless init --main-branch <branch>
602602
Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
603-
Warning: the configuration value core.hooksPath was set to: my-hooks,
603+
Warning: the configuration value core.hooksPath was set to: <repo-path>/my-hooks,
604604
which is not the expected default value of: <repo-path>/.git/hooks
605605
The Git hooks above may have been installed to an unexpected global location.
606606
Successfully installed git-branchless.

0 commit comments

Comments
 (0)