Skip to content

Commit 3654225

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 main worktree, or the git dir if it is bare (git itself uses the same logic).
1 parent 7e8853e commit 3654225

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ 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 parent_repo = repo.open_worktree_parent_repo()?;
59+
let main_repo = parent_repo.as_ref().unwrap_or(repo);
60+
61+
let path = PathBuf::from(path.strip_suffix('\n').unwrap_or(&path));
62+
63+
main_repo
64+
.get_working_copy_path()
65+
.as_deref()
66+
.unwrap_or_else(|| main_repo.get_path())
67+
.join(path)
5868
} else {
5969
get_default_hooks_dir(repo)?
6070
};

0 commit comments

Comments
 (0)