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 3 commits into
base: master
Choose a base branch
from

Conversation

ethanwu10
Copy link

@ethanwu10 ethanwu10 commented Nov 15, 2024

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 for bare repos).

Fixes #1438

@ethanwu10
Copy link
Author

I'm not clear on which worktree core.hooksPath is being read from and where it's supposed to be resolved relative to. If I'm reading the git docs correctly, they should be read from the current worktree regardless of which worktree the config value itself was read from. I'll need to figure out how to test this properly.

@ethanwu10 ethanwu10 force-pushed the fix/hookspath-from-root branch from 3654225 to 5c0aa86 Compare November 15, 2024 21:53
@arxanas
Copy link
Owner

arxanas commented Nov 19, 2024

I'm not clear on which worktree core.hooksPath is being read from and where it's supposed to be resolved relative to. If I'm reading the git docs correctly, they should be read from the current worktree regardless of which worktree the config value itself was read from. I'll need to figure out how to test this properly.

I agree with that interpretation of the docs: a relative hook path always needs to be interpreted from the worktree root that the hook is running in (which means that there's not a way to specify a hook path that's relative to the main worktree).

@ethanwu10 ethanwu10 force-pushed the fix/hookspath-from-root branch from 5c0aa86 to 2b017e3 Compare January 28, 2025 01:29
@ethanwu10 ethanwu10 marked this pull request as ready for review January 28, 2025 01:30
@ethanwu10 ethanwu10 marked this pull request as draft January 28, 2025 02:40
Allow running git commands in a different working directory in tests.
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.
Since init previously used the root worktree for all of its actions, it
failed to resolve `core.hooksPath` relative to the worktree it was being
run in. Change `init` to work with the current worktree, and update code
to explicitly refer to the shared git directory when necessary. This
also entirely removes the need for `open_worktree_parent_repo`.
@ethanwu10 ethanwu10 force-pushed the fix/hookspath-from-root branch from 2b017e3 to 4d6d5fb Compare January 28, 2025 04:03
@@ -606,8 +606,7 @@ fn command_init(
main_branch_name: Option<&str>,
) -> EyreExitOr<()> {
let mut in_ = BufReader::new(stdin());
let repo = Repo::from_current_dir()?;
let mut repo = repo.open_worktree_parent_repo()?.unwrap_or(repo);
let mut repo = Repo::from_current_dir()?;

let default_config = Config::open_default()?;
let readonly_config = repo.get_readonly_config()?;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes readonly_config to be read from the current worktree instead of the root. (It's used for modifying the root config to include branchless/config) This doesn't seem to break any tests, and also uninstall uses the current worktree instead of the root. I'm not sure if this is a problem or not, since I'm not clear on how much of the config file init/uninstall process is covered in the worktree tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core.hooksPath not resolved from repository root
2 participants