Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(init): resolve hooks path relative to repo root #1446

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 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,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)?
};
Expand Down
4 changes: 2 additions & 2 deletions git-branchless/tests/test_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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: <repo-path>/my-hooks,
which is not the expected default value of: <repo-path>/.git/hooks
The Git hooks above may have been installed to an unexpected global location.
Successfully installed git-branchless.
Expand Down Expand Up @@ -600,7 +600,7 @@ hooksPath = my-hooks
Auto-detected your main branch as: master
If this is incorrect, run: git branchless init --main-branch <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: <repo-path>/my-hooks,
which is not the expected default value of: <repo-path>/.git/hooks
The Git hooks above may have been installed to an unexpected global location.
Successfully installed git-branchless.
Expand Down
Loading