Parent directory

_git-flow

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