diff --git a/git-branchless-lib/src/core/config.rs b/git-branchless-lib/src/core/config.rs index 248525a36..82eac41b1 100644 --- a/git-branchless-lib/src/core/config.rs +++ b/git-branchless-lib/src/core/config.rs @@ -54,7 +54,13 @@ pub fn get_main_worktree_hooks_dir( let hooks_path = if result.exit_code.is_success() { let path = String::from_utf8(result.stdout) .context("Decoding git config output for hooks path")?; - PathBuf::from(path.strip_suffix('\n').unwrap_or(&path)) + + let path = PathBuf::from(path.strip_suffix('\n').unwrap_or(&path)); + + repo.get_working_copy_path() + .as_deref() + .unwrap_or_else(|| repo.get_path()) + .join(path) } else { get_default_hooks_dir(repo)? }; diff --git a/git-branchless/tests/test_init.rs b/git-branchless/tests/test_init.rs index 82be1b2d1..d5a4ce8b2 100644 --- a/git-branchless/tests/test_init.rs +++ b/git-branchless/tests/test_init.rs @@ -547,7 +547,7 @@ fn test_init_core_hooks_path_warning() -> eyre::Result<()> { Auto-detected your main branch as: master If this is incorrect, run: git branchless init --main-branch Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction - Warning: the configuration value core.hooksPath was set to: my-hooks, + Warning: the configuration value core.hooksPath was set to: /my-hooks, which is not the expected default value of: /.git/hooks The Git hooks above may have been installed to an unexpected global location. Successfully installed git-branchless. @@ -600,7 +600,7 @@ hooksPath = my-hooks Auto-detected your main branch as: master If this is incorrect, run: git branchless init --main-branch Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction - Warning: the configuration value core.hooksPath was set to: my-hooks, + Warning: the configuration value core.hooksPath was set to: /my-hooks, which is not the expected default value of: /.git/hooks The Git hooks above may have been installed to an unexpected global location. Successfully installed git-branchless.