-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdispatch
More file actions
executable file
·46 lines (40 loc) · 1.45 KB
/
Copy pathdispatch
File metadata and controls
executable file
·46 lines (40 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
# Shared dispatcher for the global git hooks in this directory.
#
# Because core.hooksPath overrides a repo's own .git/hooks entirely, each
# global hook first chains to the repo-local hook of the same name (so
# per-repo hooks and tools like husky keep working), then triggers the
# fish prompt broadcast.
#
# Usage: dispatch <hook-name> [hook args...]
hook="$1"
shift
# Hard recursion guard. Hooks inherit git config (including core.hooksPath)
# through the environment, so a git command run from inside a hook can fire
# these global hooks again. One nested level is where it stops.
if [ -n "$GIT_PROMPT_SYNC_DISPATCH" ]; then
exit 0
fi
GIT_PROMPT_SYNC_DISPATCH=1
export GIT_PROMPT_SYNC_DISPATCH
# Resolve the repo's own hooks dir via --git-dir. Do NOT use
# `git rev-parse --git-path hooks`: it respects core.hooksPath, which
# resolves right back to THIS directory and made dispatch exec itself in
# an infinite fork loop.
git_dir=$(git rev-parse --git-dir 2>/dev/null)
status=0
if [ -n "$git_dir" ]; then
local_hook="$git_dir/hooks/$hook"
if [ -x "$local_hook" ]; then
"$local_hook" "$@"
status=$?
fi
fi
# reference-transaction fires for prepared/committed/aborted states on every
# ref update in every repo operation; only a completed transaction is worth
# a repaint.
if [ "$hook" = "reference-transaction" ] && [ "$1" != "committed" ]; then
exit "$status"
fi
"$HOME/.config/git/hooks/git_prompt_broadcast"
exit "$status"