-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make githooks possible to run local hook from global hooks (#901)
- Loading branch information
Showing
10 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
#!/usr/bin/env -S bash | ||
|
||
use flake | ||
|
||
# See GH-545 | ||
export GIT_HOOKS_TRUST_REPOS="${GIT_HOOKS_TRUST_REPOS}:${PWD}" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
typos --config "$TYPOS_CONFIG_PATH" "$1" | ||
|
||
run_local_hook 'commit-msg' "$@" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ pkgs, ... }: | ||
pkgs.writeShellApplication rec { | ||
name = "run_local_hook"; | ||
text = builtins.readFile ./${name}.bash; | ||
meta.description = "GH-545"; | ||
runtimeInputs = with pkgs; [ | ||
git | ||
coreutils # `cat` | ||
]; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# You should remove local hooks as `git config --local --unset core.hooksPath` to prefer global hooks for the entry point | ||
|
||
readonly hook_name="$1" | ||
shift | ||
|
||
repository_path="$(git rev-parse --show-toplevel)" | ||
readonly repository_path | ||
|
||
# Avoiding -o error only at here: https://stackoverflow.com/a/7832158 | ||
TRUST_PATH=${GIT_HOOKS_TRUST_REPOS:-} | ||
|
||
if [[ -x "${repository_path}/.git/hooks/${hook_name}" ]]; then | ||
# Why using `case`: https://unix.stackexchange.com/a/32054 | ||
case ":$TRUST_PATH:" in | ||
*:$repository_path:*) | ||
exec "${repository_path}/.git/hooks/${hook_name}" "$@" | ||
;; | ||
*) | ||
cat <<'EOF' | ||
Found an ignored local hook. | ||
You can allow it as | ||
```bash | ||
export GIT_HOOKS_TRUST_REPOS="${GIT_HOOKS_TRUST_REPOS}:${PWD}" | ||
``` | ||
EOF | ||
;; | ||
esac | ||
fi |