feat(hooks): draft/proposal: support multiple worktrees#180
Merged
zimbatm merged 1 commit intonumtide:masterfrom Apr 11, 2022
Merged
feat(hooks): draft/proposal: support multiple worktrees#180zimbatm merged 1 commit intonumtide:masterfrom
zimbatm merged 1 commit intonumtide:masterfrom
Conversation
823aecd to
5b06c9e
Compare
by setting up git hook shim scripts that exec into the corresponding
real hook scripts under ${DEVSHELL_GIT_HOOKS_DIR}/bin if and only
if:
1. DEVSHELL_DIR is defined,
2. DEVSHELL_GIT_HOOKS_DIR is defined, and
3. ${DEVSHELL_GIT_HOOKS_DIR}/bin/<hook-name> is executable.
Otherwise, the hook shim scripts emit a diagnostic message and exit.
This way, we can safely install a hook shim to the git hooks directory
*even if the hook isn't active for all worktrees*, and punt to
DEVSHELL_GIT_HOOKS_DIR to activate only those hooks that are pertinent
for a given devshell.
Ancillary changes:
1. Respect GIT_COMMON_DIR on git clients that support it
(GIT_COMMON_DIR may affect where git looks for hooks), and
2. Respect the user's core.hooksPath setting.
5b06c9e to
4a1cead
Compare
tennox
pushed a commit
to tennox/devshell
that referenced
this pull request
May 17, 2022
by setting up git hook shim scripts that exec into the corresponding
real hook scripts under ${DEVSHELL_GIT_HOOKS_DIR}/bin if and only
if:
1. DEVSHELL_DIR is defined,
2. DEVSHELL_GIT_HOOKS_DIR is defined, and
3. ${DEVSHELL_GIT_HOOKS_DIR}/bin/<hook-name> is executable.
Otherwise, the hook shim scripts emit a diagnostic message and exit.
This way, we can safely install a hook shim to the git hooks directory
*even if the hook isn't active for all worktrees*, and punt to
DEVSHELL_GIT_HOOKS_DIR to activate only those hooks that are pertinent
for a given devshell.
Ancillary changes:
1. Respect GIT_COMMON_DIR on git clients that support it
(GIT_COMMON_DIR may affect where git looks for hooks), and
2. Respect the user's core.hooksPath setting.
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.
First, thanks for this convenient solution for managing git hooks. It was very easy to get started rolling custom hooks (after cribbing some plays from
digga, to be sure 😃 ).I use
git worktreeextensively, and it would be nice ifdevshellsupported per-worktree hook definitions (if for no other reason than to more easily validate changes to git hooks made in a feature branch worktree).This pull request is a proposal to support per-worktree hooks via the use of shim scripts that can safely be installed to the shared hooks directory. These shims read the real hook path from the
DEVSHELL_GIT_HOOKS_DIRenvironment variable, whichs points to a store path containing the actual hook scripts for the current devshell.The shim scripts cause git hooks to be ignored:
DEVSHELL_DIRis unset or empty), orDEVSHELL_GIT_HOOKS_DIRis unset or empty), or${DEVSHELL_GIT_HOOKS_DIR}/bin/<hook-name>is not executable).In such cases, the hook shim scripts emit a diagnostic message and exit.
This way,
devshellcan safely install a shim script to the git hooks directory even if the corresponding hook isn't active for all worktrees, or if different worktrees provide different definitions for the hook, and punt toDEVSHELL_GIT_HOOKS_DIRto activate only those hooks that are pertinent for the current devshell.Ancillary changes:
GIT_COMMON_DIRon git clients that support it (GIT_COMMON_DIRmay affect where git looks for hooks), andcore.hooksPathsetting.Thanks in advance for your consideration.