Resolve repository hooks from the common directory - #2813
Open
YuriNachos wants to merge 1 commit into
Open
Conversation
Git stores hooks in the repository's common directory, which is shared by all linked worktrees. -pathForHookWithName: derived the default hooks path from self.repositoryPath, i.e. git_repository_path(), which for a linked worktree is the per-worktree git directory. That directory never contains a hooks directory, so GitUp silently failed to find pre-commit, pre-push, and other hooks when operating on a worktree (issue git-up#1053). Use git_repository_commondir() for the default hooks path instead. For a plain (non-worktree) repository the common directory is the git directory, so behavior is unchanged there; only linked worktrees now resolve hooks correctly. Fixes git-up#1053
|
| Filename | Overview |
|---|---|
| GitUpKit/Core/GCRepository.m | Correctly changes default hook resolution from the per-worktree Git directory to the shared common directory. |
| GitUpKit/Core/GCRepository-Tests.m | Adds focused linked-worktree coverage that exercises the previous failure and verifies the resolved shared hook path. |
Reviews (1): Last reviewed commit: "Resolve repository hooks from the common..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1053
Summary
pre-commit,pre-push, and other Git hooks are now found when the repository is a linked worktree. Previously GitUp silently skipped hooks for worktrees because it looked them up in the wrong directory.Root Cause
-pathForHookWithName:built the default hooks directory fromself.repositoryPath, i.e.git_repository_path(). For a linked worktree that returns the per-worktree git directory (e.g.<main>/.git/worktrees/<name>), which never contains ahooksdirectory. Git stores hooks in the repository common directory (<main>/.git/hooks), shared by all linked worktrees, so GitUp never found them andrunHookWithName:(used for the pre-push hook in-sendLocalBranchesToRemote:...) silently treated them as absent.Changes
GitUpKit/Core/GCRepository.m-pathForHookWithName:, derive the default hooks path fromgit_repository_commondir(_private)instead ofself.repositoryPath. For a plain repository the common directory equals the git directory, so behavior is unchanged; only linked worktrees are affected.Test plan
testPathForHookWithName_FoundFromLinkedWorktreetoGCRepository-Tests.m(GCMultipleCommitsRepositoryTests): creates a linked worktree viagit worktree add, installs an executablepre-commithook in the main repository hooks directory, and asserts the worktree resolves the hook to that shared path.master(worktree cannot resolve the hook) and passes with this change.testPathForHookWithName,testPathForHookWithName_AbsoluteCustomHooksPath, andtestPathForHookWithName_RelativeCustomHooksPathare unaffected (a plain repo hascommondir == gitdir, and the customcore.hooksPathbranch is untouched).I AGREE TO THE GITUP CONTRIBUTOR LICENSE AGREEMENT