Parent directory

git-flow-avh.plugin.zsh

15876 bytes
  1_git-flow ()
  2{
  3    local curcontext="$curcontext" state line
  4    typeset -A opt_args
  5
  6    _arguments -C \
  7        ':command:->command' \
  8        '*::options:->options'
  9
 10    case $state in
 11        (command)
 12
 13            local -a subcommands
 14            subcommands=(
 15                'init:Initialize a new git repo with support for the branching model.'
 16                'feature:Manage your feature branches.'
 17                'bugfix:Manage your bugfix branches.'
 18                'config:Manage your configuration.'
 19                'release:Manage your release branches.'
 20                'hotfix:Manage your hotfix branches.'
 21                'support:Manage your support branches.'
 22                'version:Shows version information.'
 23                'finish:Finish the branch you are currently on.'
 24                'delete:Delete the branch you are currently on.'
 25                'publish:Publish the branch you are currently on.'
 26                'rebase:Rebase the branch you are currently on.'
 27            )
 28            _describe -t commands 'git flow' subcommands
 29        ;;
 30
 31        (options)
 32            case $line[1] in
 33
 34                (init)
 35                    _arguments \
 36                        -f'[Force setting of gitflow branches, even if already configured]'
 37                    ;;
 38
 39                    (version)
 40                    ;;
 41
 42                    (hotfix)
 43                        __git-flow-hotfix
 44                    ;;
 45
 46                    (release)
 47                        __git-flow-release
 48                    ;;
 49
 50                    (feature)
 51                        __git-flow-feature
 52                    ;;
 53                    (bugfix)
 54                        __git-flow-bugfix
 55                    ;;
 56
 57                    (config)
 58                    __git-flow-config
 59                    ;;
 60
 61            esac
 62        ;;
 63    esac
 64}
 65
 66__git-flow-release ()
 67{
 68    local curcontext="$curcontext" state line
 69    typeset -A opt_args
 70
 71    _arguments -C \
 72        ':command:->command' \
 73        '*::options:->options'
 74
 75    case $state in
 76        (command)
 77
 78            local -a subcommands
 79            subcommands=(
 80                'start:Start a new release branch.'
 81                'finish:Finish a release branch.'
 82                'list:List all your release branches. (Alias to `git flow release`)'
 83                'publish:Publish release branch to remote.'
 84                'track:Checkout remote release branch.'
 85                'rebase:Rebase from integration branch.'
 86                'delete:Delete a release branch.'
 87            )
 88            _describe -t commands 'git flow release' subcommands
 89            _arguments \
 90                -v'[Verbose (more) output]'
 91        ;;
 92
 93        (options)
 94            case $line[1] in
 95
 96                (start)
 97                    _arguments \
 98                        -F'[Fetch from origin before performing finish]'\
 99                        ':version:__git_flow_version_list'
100                ;;
101
102                (finish)
103                    _arguments \
104                        -F'[Fetch from origin before performing finish]' \
105                        -s'[Sign the release tag cryptographically]'\
106                        -u'[Use the given GPG-key for the digital signature (implies -s)]'\
107                        -m'[Use the given tag message]'\
108                        -p'[Push to $ORIGIN after performing finish]'\
109                        ':version:__git_flow_version_list'
110                ;;
111
112                (delete)
113                    _arguments \
114                        -f'[Force deletion]' \
115                        -r'[Delete remote branch]' \
116                        ':version:__git_flow_version_list'
117                ;;
118
119                (publish)
120                    _arguments \
121                        ':version:__git_flow_version_list'
122                ;;
123
124                (track)
125                    _arguments \
126                        ':version:__git_flow_version_list'
127                ;;
128
129                (rebase)
130                    _arguments \
131                        -i'[Do an interactive rebase]' \
132                        ':branch:__git_branch_names'
133                ;;
134
135                *)
136                    _arguments \
137                        -v'[Verbose (more) output]'
138                ;;
139            esac
140        ;;
141    esac
142}
143
144__git-flow-hotfix ()
145{
146    local curcontext="$curcontext" state line
147    typeset -A opt_args
148
149    _arguments -C \
150        ':command:->command' \
151        '*::options:->options'
152
153    case $state in
154        (command)
155
156            local -a subcommands
157            subcommands=(
158                'start:Start a new hotfix branch.'
159                'finish:Finish a hotfix branch.'
160                'delete:Delete a hotfix branch.'
161                'rebase:Rebase from integration branch.'
162                'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
163                'rename:Rename a hotfix branch.'
164            )
165            _describe -t commands 'git flow hotfix' subcommands
166            _arguments \
167                -v'[Verbose (more) output]'
168        ;;
169
170        (options)
171            case $line[1] in
172
173                (start)
174                    _arguments \
175                        -F'[Fetch from origin before performing finish]'\
176                        ':hotfix:__git_flow_version_list'\
177                        ':branch-name:__git_branch_names'
178                ;;
179
180                (finish)
181                    _arguments \
182                        -F'[Fetch from origin before performing finish]' \
183                        -s'[Sign the release tag cryptographically]'\
184                        -u'[Use the given GPG-key for the digital signature (implies -s)]'\
185                        -m'[Use the given tag message]'\
186                        -p'[Push to $ORIGIN after performing finish]'\
187                        ':hotfix:__git_flow_hotfix_list'
188                ;;
189
190                (delete)
191                    _arguments \
192                        -f'[Force deletion]' \
193                        -r'[Delete remote branch]' \
194                        ':hotfix:__git_flow_hotfix_list'
195                ;;
196
197                (rebase)
198                    _arguments \
199                        -i'[Do an interactive rebase]' \
200                        ':branch:__git_branch_names'
201                ;;
202
203                *)
204                    _arguments \
205                        -v'[Verbose (more) output]'
206                ;;
207            esac
208        ;;
209    esac
210}
211
212__git-flow-feature ()
213{
214    local curcontext="$curcontext" state line
215    typeset -A opt_args
216
217    _arguments -C \
218        ':command:->command' \
219        '*::options:->options'
220
221    case $state in
222        (command)
223
224            local -a subcommands
225            subcommands=(
226                'start:Start a new feature branch.'
227                'finish:Finish a feature branch.'
228                'delete:Delete a feature branch.'
229                'list:List all your feature branches. (Alias to `git flow feature`)'
230                'publish:Publish feature branch to remote.'
231                'track:Checkout remote feature branch.'
232                'diff:Show all changes.'
233                'rebase:Rebase from integration branch.'
234                'checkout:Checkout local feature branch.'
235                'pull:Pull changes from remote.'
236                'rename:Rename a feature branch.'
237            )
238            _describe -t commands 'git flow feature' subcommands
239            _arguments \
240                -v'[Verbose (more) output]'
241        ;;
242
243        (options)
244            case $line[1] in
245
246                (start)
247                    _arguments \
248                        -F'[Fetch from origin before performing finish]'\
249                        ':feature:__git_flow_feature_list'\
250                        ':branch-name:__git_branch_names'
251                ;;
252
253                (finish)
254                    _arguments \
255                        -F'[Fetch from origin before performing finish]' \
256                        -r'[Rebase instead of merge]'\
257                        ':feature:__git_flow_feature_list'
258                ;;
259
260                (delete)
261                    _arguments \
262                        -f'[Force deletion]' \
263                        -r'[Delete remote branch]' \
264                        ':feature:__git_flow_feature_list'
265                ;;
266
267                (publish)
268                    _arguments \
269                        ':feature:__git_flow_feature_list'\
270                ;;
271
272                (track)
273                    _arguments \
274                        ':feature:__git_flow_feature_list'\
275                ;;
276
277                (diff)
278                    _arguments \
279                        ':branch:__git_branch_names'\
280                ;;
281
282                (rebase)
283                    _arguments \
284                        -i'[Do an interactive rebase]' \
285                        ':branch:__git_branch_names'
286                ;;
287
288                (checkout)
289                    _arguments \
290                        ':branch:__git_flow_feature_list'\
291                ;;
292
293                (pull)
294                    _arguments \
295                        ':remote:__git_remotes'\
296                        ':branch:__git_branch_names'
297                ;;
298
299                *)
300                    _arguments \
301                        -v'[Verbose (more) output]'
302                ;;
303            esac
304        ;;
305    esac
306}
307
308__git-flow-bugfix ()
309{
310    local curcontext="$curcontext" state line
311    typeset -A opt_args
312
313    _arguments -C \
314        ':command:->command' \
315        '*::options:->options'
316
317    case $state in
318        (command)
319
320            local -a subcommands
321            subcommands=(
322                'start:Start a new bugfix branch.'
323                'finish:Finish a bugfix branch.'
324                'delete:Delete a bugfix branch.'
325                'list:List all your bugfix branches. (Alias to `git flow bugfix`)'
326                'publish:Publish bugfix branch to remote.'
327                'track:Checkout remote bugfix branch.'
328                'diff:Show all changes.'
329                'rebase:Rebase from integration branch.'
330                'checkout:Checkout local bugfix branch.'
331                'pull:Pull changes from remote.'
332                'rename:Rename a bugfix branch.'
333            )
334            _describe -t commands 'git flow bugfix' subcommands
335            _arguments \
336                -v'[Verbose (more) output]'
337        ;;
338
339        (options)
340            case $line[1] in
341
342                (start)
343                    _arguments \
344                        -F'[Fetch from origin before performing finish]'\
345                        ':bugfix:__git_flow_bugfix_list'\
346                        ':branch-name:__git_branch_names'
347                ;;
348
349                (finish)
350                    _arguments \
351                        -F'[Fetch from origin before performing finish]' \
352                        -r'[Rebase instead of merge]'\
353                        ':bugfix:__git_flow_bugfix_list'
354                ;;
355
356                (delete)
357                    _arguments \
358                        -f'[Force deletion]' \
359                        -r'[Delete remote branch]' \
360                        ':bugfix:__git_flow_bugfix_list'
361                ;;
362
363                (publish)
364                    _arguments \
365                        ':bugfix:__git_flow_bugfix_list'\
366                ;;
367
368                (track)
369                    _arguments \
370                        ':bugfix:__git_flow_bugfix_list'\
371                ;;
372
373                (diff)
374                    _arguments \
375                        ':branch:__git_branch_names'\
376                ;;
377
378                (rebase)
379                    _arguments \
380                        -i'[Do an interactive rebase]' \
381                        ':branch:__git_branch_names'
382                ;;
383
384                (checkout)
385                    _arguments \
386                        ':branch:__git_flow_bugfix_list'\
387                ;;
388
389                (pull)
390                    _arguments \
391                        ':remote:__git_remotes'\
392                        ':branch:__git_branch_names'
393                ;;
394
395                *)
396                    _arguments \
397                        -v'[Verbose (more) output]'
398                ;;
399            esac
400        ;;
401    esac
402}
403
404__git-flow-config ()
405{
406    local curcontext="$curcontext" state line
407    typeset -A opt_args
408
409    _arguments -C \
410        ':command:->command' \
411        '*::options:->options'
412
413    case $state in
414        (command)
415
416            local -a subcommands
417            subcommands=(
418                'list:List the configuration. (Alias to `git flow config`)'
419                'set:Set the configuration option'
420            )
421            _describe -t commands 'git flow config' subcommands
422        ;;
423
424        (options)
425            case $line[1] in
426
427                (set)
428                    _arguments \
429                        --local'[Use repository config file]' \
430                        --global'[Use global config file]'\
431                        --system'[Use system config file]'\
432                        --file'[Use given config file]'\
433                        ':option:(master develop feature hotfix release support versiontagprefix)'
434                ;;
435
436                *)
437                    _arguments \
438                        --local'[Use repository config file]' \
439                        --global'[Use global config file]'\
440                        --system'[Use system config file]'\
441                        --file'[Use given config file]'
442                ;;
443            esac
444        ;;
445    esac
446}
447__git_flow_version_list ()
448{
449    local expl
450    declare -a versions
451
452    versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
453    __git_command_successful || return
454
455    _wanted versions expl 'version' compadd $versions
456}
457
458__git_flow_feature_list ()
459{
460    local expl
461    declare -a features
462
463    features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
464    __git_command_successful || return
465
466    _wanted features expl 'feature' compadd $features
467}
468
469__git_flow_bugfix_list ()
470{
471    local expl
472    declare -a bugfixes
473
474    bugfixes=(${${(f)"$(_call_program bugfixes git flow bugfix list 2> /dev/null | tr -d ' |*')"}})
475    __git_command_successful || return
476
477    _wanted bugfixes expl 'bugfix' compadd $bugfixes
478}
479
480__git_remotes () {
481    local expl gitdir remotes
482
483    gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
484    __git_command_successful || return
485
486    remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
487    __git_command_successful || return
488
489    # TODO: Should combine the two instead of either or.
490    if (( $#remotes > 0 )); then
491        _wanted remotes expl remote compadd $* - $remotes
492    else
493        _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
494    fi
495}
496
497__git_flow_hotfix_list ()
498{
499    local expl
500    declare -a hotfixes
501
502    hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
503    __git_command_successful || return
504
505    _wanted hotfixes expl 'hotfix' compadd $hotfixes
506}
507
508__git_branch_names () {
509    local expl
510    declare -a branch_names
511
512    branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
513    __git_command_successful || return
514
515    _wanted branch-names expl branch-name compadd $* - $branch_names
516}
517
518__git_command_successful () {
519    if (( ${#pipestatus:#0} > 0 )); then
520        _message 'not a git repository'
521        return 1
522    fi
523    return 0
524}
525
526zstyle ':completion:*:*:git:*' user-commands flow:'provide high-level repository operations'