Skip to content

Commit

Permalink
fix(init): resolve hooks path relative to repo root
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ethanwu10 committed Nov 15, 2024
1 parent 7e8853e commit 3654225
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion git-branchless-lib/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ 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 parent_repo = repo.open_worktree_parent_repo()?;
let main_repo = parent_repo.as_ref().unwrap_or(repo);

let path = PathBuf::from(path.strip_suffix('\n').unwrap_or(&path));

main_repo
.get_working_copy_path()
.as_deref()
.unwrap_or_else(|| main_repo.get_path())
.join(path)
} else {
get_default_hooks_dir(repo)?
};
Expand Down

0 comments on commit 3654225

Please sign in to comment.