]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/git-hubflow/git-hubflow.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / git-hubflow / git-hubflow.plugin.zsh
1 alias ghf='git hf'
2 alias ghff='git hf feature'
3 alias ghfr='git hf release'
4 alias ghfh='git hf hotfix'
5 alias ghfs='git hf support'
6 alias ghfu='git hf update'
7
8 _git-hf ()
9 {
10     local curcontext="$curcontext" state line
11     typeset -A opt_args
12
13     _arguments -C \
14         ':command:->command' \
15         '*::options:->options'
16
17     case $state in
18         (command)
19
20             local -a subcommands
21             subcommands=(
22                 'init:Initialize a new git repo with support for the branching model.'
23                 'feature:Manage your feature branches.'
24                 'release:Manage your release branches.'
25                 'hotfix:Manage your hotfix branches.'
26                 'support:Manage your support branches.'
27                 'update:Pull upstream changes down into your master and develop branches.'
28                 'version:Shows version information.'
29             )
30             _describe -t commands 'git hf' subcommands
31         ;;
32
33         (options)
34             case $line[1] in
35
36                 (init)
37                     _arguments \
38                         -f'[Force setting of gitflow branches, even if already configured]'
39                 ;;
40
41                 (version)
42                 ;;
43
44                 (hotfix)
45                     __git-hf-hotfix
46                 ;;
47
48                 (release)
49                     __git-hf-release
50                 ;;
51
52                 (feature)
53                     __git-hf-feature
54                 ;;
55             esac
56         ;;
57     esac
58 }
59
60 __git-hf-release ()
61 {
62     local curcontext="$curcontext" state line
63     typeset -A opt_args
64
65     _arguments -C \
66         ':command:->command' \
67         '*::options:->options'
68
69     case $state in
70         (command)
71
72             local -a subcommands
73             subcommands=(
74                 'start:Start a new release branch.'
75                 'finish:Finish a release branch.'
76                 'list:List all your release branches. (Alias to `git hf release`)'
77                 'cancel:Cancel release'
78                 'push:Push release to GitHub'
79                 'pull:Pull release from GitHub'
80                 'track:Track release'
81             )
82             _describe -t commands 'git hf release' subcommands
83             _arguments \
84                 -v'[Verbose (more) output]'
85         ;;
86
87         (options)
88             case $line[1] in
89
90                 (start)
91                     _arguments \
92                         -F'[Fetch from origin before performing finish]'\
93                         ':version:__git_hf_version_list'
94                 ;;
95
96                 (finish)
97                     _arguments \
98                         -F'[Fetch from origin before performing finish]' \
99                         -s'[Sign the release tag cryptographically]'\
100                         -u'[Use the given GPG-key for the digital signature (implies -s)]'\
101                         -m'[Use the given tag message]'\
102                         -p'[Push to $ORIGIN after performing finish]'\
103                         -k'[Keep branch after performing finish]'\
104                         -n"[Don't tag this release]"\
105                         ':version:__git_hf_version_list'
106                 ;;
107
108                 *)
109                     _arguments \
110                         -v'[Verbose (more) output]'
111                 ;;
112             esac
113         ;;
114     esac
115 }
116
117 __git-hf-hotfix ()
118 {
119     local curcontext="$curcontext" state line
120     typeset -A opt_args
121
122     _arguments -C \
123         ':command:->command' \
124         '*::options:->options'
125
126     case $state in
127         (command)
128
129             local -a subcommands
130             subcommands=(
131                 'start:Start a new hotfix branch.'
132                 'finish:Finish a hotfix branch.'
133                 'list:List all your hotfix branches. (Alias to `git hf hotfix`)'
134                 'publish:Publish the hotfix branch.'
135                 'track:Track the hotfix branch.'
136                 'pull:Pull the hotfix from GitHub.'
137                 'push:Push the hotfix to GitHub.'
138                 'cancel:Cancel the hotfix.'
139             )
140             _describe -t commands 'git hf hotfix' subcommands
141             _arguments \
142                 -v'[Verbose (more) output]'
143         ;;
144
145         (options)
146             case $line[1] in
147
148                 (start)
149                     _arguments \
150                         -F'[Fetch from origin before performing finish]'\
151                         ':hotfix:__git_hf_version_list'\
152                         ':branch-name:__git_branch_names'
153                 ;;
154
155                 (finish)
156                     _arguments \
157                         -F'[Fetch from origin before performing finish]' \
158                         -s'[Sign the release tag cryptographically]'\
159                         -u'[Use the given GPG-key for the digital signature (implies -s)]'\
160                         -m'[Use the given tag message]'\
161                         -p'[Push to $ORIGIN after performing finish]'\
162                         -k'[Keep branch after performing finish]'\
163                         -n"[Don't tag this release]"\
164                         ':hotfix:__git_hf_hotfix_list'
165                 ;;
166
167                 *)
168                     _arguments \
169                         -v'[Verbose (more) output]'
170                 ;;
171             esac
172         ;;
173     esac
174 }
175
176 __git-hf-feature ()
177 {
178     local curcontext="$curcontext" state line
179     typeset -A opt_args
180
181     _arguments -C \
182         ':command:->command' \
183         '*::options:->options'
184
185     case $state in
186         (command)
187
188             local -a subcommands
189             subcommands=(
190                 'list:List all your feature branches. (Alias to `git hf feature`)'
191                 'start:Start a new feature branch'
192                 'finish:Finish a feature branch'
193                 'submit:submit'
194                 'track:track'
195                 'diff:Diff'
196                 'rebase:Rebase feature branch against develop'
197                 'checkout:Checkout feature'
198                 'pull:Pull feature branch from GitHub'
199                 'push:Push feature branch to GitHub'
200                 'cancel:Cancel feature'
201             )
202             _describe -t commands 'git hf feature' subcommands
203             _arguments \
204                 -v'[Verbose (more) output]'
205         ;;
206
207         (options)
208             case $line[1] in
209
210                 (start)
211                     _arguments \
212                         -F'[Fetch from origin before performing finish]'\
213                         ':feature:__git_hf_feature_list'\
214                         ':branch-name:__git_branch_names'
215                 ;;
216
217                 (finish)
218                     _arguments \
219                         -F'[Fetch from origin before performing finish]' \
220                         -r'[Rebase instead of merge]'\
221                         ':feature:__git_hf_feature_list'
222                 ;;
223
224                 (publish)
225                     _arguments \
226                         ':feature:__git_hf_feature_list'\
227                 ;;
228
229                 (track)
230                     _arguments \
231                         ':feature:__git_hf_feature_list'\
232                 ;;
233
234                 (diff)
235                     _arguments \
236                         ':branch:__git_branch_names'\
237                 ;;
238
239                 (rebase)
240                     _arguments \
241                         -i'[Do an interactive rebase]' \
242                         ':branch:__git_branch_names'
243                 ;;
244
245                 (checkout)
246                     _arguments \
247                         ':branch:__git_hf_feature_list'\
248                 ;;
249
250                 (pull)
251                     _arguments \
252                         ':remote:__git_remotes'\
253                         ':branch:__git_branch_names'
254                 ;;
255
256                 *)
257                     _arguments \
258                         -v'[Verbose (more) output]'
259                 ;;
260             esac
261         ;;
262     esac
263 }
264
265 __git_hf_version_list ()
266 {
267     local expl
268     declare -a versions
269
270     versions=(${${(f)"$(_call_program versions git hf release list 2> /dev/null | tr -d ' |*')"}})
271     __git_command_successful || return
272
273     _wanted versions expl 'version' compadd $versions
274 }
275
276 __git_hf_feature_list ()
277 {
278     local expl
279     declare -a features
280
281     features=(${${(f)"$(_call_program features git hf feature list 2> /dev/null | tr -d ' |*')"}})
282     __git_command_successful || return
283
284     _wanted features expl 'feature' compadd $features
285 }
286
287 __git_remotes () {
288     local expl gitdir remotes
289
290     gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
291     __git_command_successful || return
292
293     remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
294     __git_command_successful || return
295
296     # TODO: Should combine the two instead of either or.
297     if (( $#remotes > 0 )); then
298         _wanted remotes expl remote compadd $* - $remotes
299     else
300         _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
301     fi
302 }
303
304 __git_hf_hotfix_list ()
305 {
306     local expl
307     declare -a hotfixes
308
309     hotfixes=(${${(f)"$(_call_program hotfixes git hf hotfix list 2> /dev/null | tr -d ' |*')"}})
310     __git_command_successful || return
311
312     _wanted hotfixes expl 'hotfix' compadd $hotfixes
313 }
314
315 __git_branch_names () {
316     local expl
317     declare -a branch_names
318
319     branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
320     __git_command_successful || return
321
322     _wanted branch-names expl branch-name compadd $* - $branch_names
323 }
324
325 __git_command_successful () {
326     if (( ${#pipestatus:#0} > 0 )); then
327         _message 'not a git repository'
328         return 1
329     fi
330     return 0
331 }
332
333 zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'