-
Notifications
You must be signed in to change notification settings - Fork 1
/
_git-hooks
143 lines (127 loc) · 4.04 KB
/
_git-hooks
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#compdef git-hooks
#description zsh completions for the git-hooks command
__git_standard_hooks () {
local -a standard_hooks
standard_hooks=(
applypatch-msg
commit-msg
fsmonitor-watchman
post-applypatch
post-checkout
post-commit
post-merge
post-receive
post-rewrite
post-update
pre-applypatch
pre-auto-gc
pre-commit
pre-push
pre-rebase
pre-receive
prepare-commit-msg
push-to-checkout
sendemail-validate
update
);
_alternative \
"standard_hooks:standard_hook:(${standard_hooks[*]})"
}
__git_hooks () {
local repo
if repo=$(git rev-parse --show-toplevel) 2>/dev/null; then
_alternative \
"standard_hooks:standard_hook:__git_standard_hooks" \
"repo__git_hooks:repo_git_hook:_files -W $repo/.githooks"
fi
}
_git-hooks () {
local curcontext=$curcontext state line ret=1
_arguments -C \
': :->command' \
'*:: :->option-or-argument' \
&& ret=0
case $state in
(command)
local -a commands
local repo
commands=(
check-support:'view difference between the git hooks supported by git and git-hooks'
install-command:'install the "git hooks" command'
uninstall-command:'remove the "git hooks" command'
install-template:'install multiplexer hooks for all future repositories'
uninstall-template:'stop installing multiplexer hooks for all future repositories'
config:'display all the config settings managed by git-hooks'
help:'display the help text'
)
if repo=$(git rev-parse --show-toplevel 2>/dev/null); then
commands+=(
install:'install the multiplexer hooks into the .git/hooks directory'
uninstall:'remove the multiplexer hooks from the .git/hooks directory'
include:"copy a bundled script into your repository's .githooks directory"
)
if [[ -d "$repo/.githooks" ]]; then
commands+=(
parallel:'configure your hooks to be run in parallel'
list:'display all available hooks and their enabled status'
enable:'enable a set of hooks or an individual hook'
disable:'disable a set of hooks or an individual hook'
run:'run a set of hooks or an individual hook'
show-input:'configure your hooks to display the arguments and data they were invoked with'
)
fi
fi
_describe -t commands command commands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*}-$line[1]:
case ${line[1]} in
(list)
_arguments -S -s \
': :__git_standard_hooks' \
&& ret=0
;;
(install)
_arguments -S -s \
'(-e --examples)'{-e,--examples}'[install bundled example hook handlers]' \
'(:)--no-preserve[discard any existing git hook scripts found in .git/hooks]' \
"(:)--no-alias[do not install \"git hooks\" into your repository's config]" \
&& ret=0
;;
(install-command)
_arguments -S -s \
'(:)--local[add alias to repository config]' \
'(:)--global[add alias to git global config]' \
'(:)--core[add git-hooks command to git exec-path]' \
&& ret=0
;;
(uninstall-command)
_arguments -S -s \
'(:)--local[remove alias from repository config]' \
'(:)--global[remove alias from git global config]' \
'(:)--core[remove git-hooks command from git exec-path]' \
&& ret=0
;;
(help)
_arguments -S -s \
'(:)--markdown[generate markdown output]' \
&& ret=0
;;
(enable|disable)
_arguments -S -s \
'*:: :__git_hooks' \
&& ret=0
;;
(run)
_arguments -S -s \
': :__git_hooks' \
&& ret=0
;;
(uninstall|install-template|uninstall-template|check-support|config)
ret=0
;;
esac
;;
esac
return ret
}