git-hooks: make pre-push validation work in linked worktrees - #13488
Open
ldanielmadariaga wants to merge 1 commit into
Open
ldanielmadariaga wants to merge 1 commit into
ldanielmadariaga wants to merge 1 commit into
Conversation
Git exports GIT_DIR to hooks. In a linked worktree (`git worktree add`) it points at .git/worktrees/<name> and GIT_WORK_TREE is unset, so git treats whatever directory it runs in as the top of the working tree. generate-proto.sh runs `git rev-parse --show-toplevel` from dev/tools/controllerbuilder and gets that directory back, so validate-generated-files fails and every push from a worktree is rejected: ./generate-proto.sh: line 24: cd: <worktree>/dev/tools/controllerbuilder/dev/tools/controllerbuilder: No such file or directory Clear GIT_DIR and GIT_WORK_TREE in the hook, as githooks(5) recommends, so the validation runs the same way as `./dev/tasks/validate-and-push --validate-only`. Git doesn't export them in a normal checkout, so nothing changes there.
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: barney-s, cheftako The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This branch has not been deployed
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.
Makes the pre-push hook work when pushing from a linked worktree (
git worktree add).Git exports
GIT_DIRto hooks. In a linked worktree it points at.git/worktrees/<name>andGIT_WORK_TREEis unset, so git treats whatever directory it runs in as the top of the working tree.generate-proto.shrunsgit rev-parse --show-toplevelfromdev/tools/controllerbuilderand gets that directory back.validate-generated-filesthen fails, so every push from a worktree is rejected:The hook now clears
GIT_DIRandGIT_WORK_TREE, as githooks(5) recommends, so validation runs the same way as./dev/tasks/validate-and-push --validate-only. Git doesn't export them in a normal checkout, so nothing changes there.Tested:
make fmt,go vet,validate-generated-files,unit-tests), and it passed.