blob: 270bcbe389b79224d4725e45be39abb4c3823829 [file] [log] [blame]
Zifei Tong5eda7412010-08-22 13:22:27 +08001#!zsh
Justin Hileman56ff8b42011-01-18 09:58:31 -05002#
Zifei Tong5eda7412010-08-22 13:22:27 +08003# Installation
4# ------------
Justin Hileman56ff8b42011-01-18 09:58:31 -05005#
Zifei Tong5eda7412010-08-22 13:22:27 +08006# To achieve git-flow completion nirvana:
Justin Hileman56ff8b42011-01-18 09:58:31 -05007#
Zifei Tong5eda7412010-08-22 13:22:27 +08008# 0. Update your zsh's git-completion module to the newest verion.
Justin Hileman56ff8b42011-01-18 09:58:31 -05009# From here. http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=blob_plain;f=Completion/Unix/Command/_git;hb=HEAD
10#
Zifei Tong5eda7412010-08-22 13:22:27 +080011# 1. Install this file. Either:
Justin Hileman56ff8b42011-01-18 09:58:31 -050012#
Zifei Tong5eda7412010-08-22 13:22:27 +080013# a. Place it in your .zshrc:
Justin Hileman56ff8b42011-01-18 09:58:31 -050014#
Zifei Tong5eda7412010-08-22 13:22:27 +080015# b. Or, copy it somewhere (e.g. ~/.git-flow-completion.zsh) and put the following line in
16# your .zshrc:
Justin Hileman56ff8b42011-01-18 09:58:31 -050017#
Zifei Tong5eda7412010-08-22 13:22:27 +080018# source ~/.git-flow-completion.zsh
19#
Justin Hileman56ff8b42011-01-18 09:58:31 -050020# c. Or, use this file as a oh-my-zsh plugin.
Zifei Tong5eda7412010-08-22 13:22:27 +080021#
22
Zifei Tong85b504a2010-08-22 10:37:55 +080023_git-flow ()
Zifei Tong4b64ecc2010-08-21 11:20:29 +080024{
Zifei Tong85b504a2010-08-22 10:37:55 +080025 local curcontext="$curcontext" state line
26 typeset -A opt_args
27
28 _arguments -C \
Justin Hileman56ff8b42011-01-18 09:58:31 -050029 ':command:->command' \
30 '*::options:->options'
Zifei Tong85b504a2010-08-22 10:37:55 +080031
32 case $state in
33 (command)
Justin Hileman56ff8b42011-01-18 09:58:31 -050034
Zifei Tong85b504a2010-08-22 10:37:55 +080035 local -a subcommands
36 subcommands=(
37 'init:Initialize a new git repo with support for the branching model.'
38 'feature:Manage your feature branches.'
39 'release:Manage your release branches.'
40 'hotfix:Manage your hotfix branches.'
41 'support:Manage your support branches.'
42 'version:Shows version information.'
43 )
44 _describe -t commands 'git flow' subcommands
45 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050046
Zifei Tong85b504a2010-08-22 10:37:55 +080047 (options)
48 case $line[1] in
Justin Hileman56ff8b42011-01-18 09:58:31 -050049
Zifei Tong85b504a2010-08-22 10:37:55 +080050 (init)
51 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -050052 -f'[Force setting of gitflow branches, even if already configured]'
Zifei Tong85b504a2010-08-22 10:37:55 +080053 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050054
Zifei Tong85b504a2010-08-22 10:37:55 +080055 (version)
56 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050057
Zifei Tong85b504a2010-08-22 10:37:55 +080058 (hotfix)
59 __git-flow-hotfix
60 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050061
Zifei Tong85b504a2010-08-22 10:37:55 +080062 (release)
63 __git-flow-release
64 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050065
Zifei Tong85b504a2010-08-22 10:37:55 +080066 (feature)
67 __git-flow-feature
68 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050069 esac
70 ;;
71 esac
Zifei Tong4b64ecc2010-08-21 11:20:29 +080072}
73
Zifei Tong85b504a2010-08-22 10:37:55 +080074__git-flow-release ()
75{
76 local curcontext="$curcontext" state line
77 typeset -A opt_args
78
79 _arguments -C \
Justin Hileman56ff8b42011-01-18 09:58:31 -050080 ':command:->command' \
81 '*::options:->options'
Zifei Tong85b504a2010-08-22 10:37:55 +080082
83 case $state in
84 (command)
Justin Hileman56ff8b42011-01-18 09:58:31 -050085
Zifei Tong85b504a2010-08-22 10:37:55 +080086 local -a subcommands
87 subcommands=(
Justin Hileman66847ba2011-01-18 09:49:58 -050088 'start:Start a new release branch.'
89 'finish:Finish a release branch.'
Zifei Tong85b504a2010-08-22 10:37:55 +080090 'list:List all your release branches. (Alias to `git flow release`)'
91 )
92 _describe -t commands 'git flow release' subcommands
Zifei Tong9414b222010-08-22 12:41:36 +080093 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -050094 -v'[Verbose (more) output]'
Zifei Tong85b504a2010-08-22 10:37:55 +080095 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050096
Zifei Tong85b504a2010-08-22 10:37:55 +080097 (options)
98 case $line[1] in
Justin Hileman56ff8b42011-01-18 09:58:31 -050099
Zifei Tong85b504a2010-08-22 10:37:55 +0800100 (start)
101 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500102 -F'[Fetch from origin before performing finish]'\
103 ':version:__git_flow_version_list'
104 ;;
105
Zifei Tong9414b222010-08-22 12:41:36 +0800106 (finish)
107 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500108 -F'[Fetch from origin before performing finish]' \
109 -s'[Sign the release tag cryptographically]'\
110 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
111 -m'[Use the given tag message]'\
112 -p'[Push to $ORIGIN after performing finish]'\
113 ':version:__git_flow_version_list'
Zifei Tong85b504a2010-08-22 10:37:55 +0800114 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500115
Zifei Tong9414b222010-08-22 12:41:36 +0800116 *)
117 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500118 -v'[Verbose (more) output]'
119 ;;
120 esac
121 ;;
122 esac
Zifei Tong85b504a2010-08-22 10:37:55 +0800123}
124
Zifei Tong9414b222010-08-22 12:41:36 +0800125__git-flow-hotfix ()
126{
127 local curcontext="$curcontext" state line
128 typeset -A opt_args
129
130 _arguments -C \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500131 ':command:->command' \
132 '*::options:->options'
Zifei Tong9414b222010-08-22 12:41:36 +0800133
134 case $state in
135 (command)
Justin Hileman56ff8b42011-01-18 09:58:31 -0500136
Zifei Tong9414b222010-08-22 12:41:36 +0800137 local -a subcommands
138 subcommands=(
Justin Hileman66847ba2011-01-18 09:49:58 -0500139 'start:Start a new hotfix branch.'
140 'finish:Finish a hotfix branch.'
Zifei Tong9414b222010-08-22 12:41:36 +0800141 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
142 )
143 _describe -t commands 'git flow hotfix' subcommands
144 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500145 -v'[Verbose (more) output]'
Zifei Tong9414b222010-08-22 12:41:36 +0800146 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500147
Zifei Tong9414b222010-08-22 12:41:36 +0800148 (options)
149 case $line[1] in
Justin Hileman56ff8b42011-01-18 09:58:31 -0500150
Zifei Tong9414b222010-08-22 12:41:36 +0800151 (start)
152 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500153 -F'[Fetch from origin before performing finish]'\
Zifei Tong9414b222010-08-22 12:41:36 +0800154 ':hotfix:__git_flow_version_list'\
155 ':branch-name:__git_branch_names'
Justin Hileman56ff8b42011-01-18 09:58:31 -0500156 ;;
157
Zifei Tong9414b222010-08-22 12:41:36 +0800158 (finish)
159 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500160 -F'[Fetch from origin before performing finish]' \
161 -s'[Sign the release tag cryptographically]'\
162 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
163 -m'[Use the given tag message]'\
164 -p'[Push to $ORIGIN after performing finish]'\
165 ':hotfix:__git_flow_hotfix_list'
Zifei Tong9414b222010-08-22 12:41:36 +0800166 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500167
Zifei Tong9414b222010-08-22 12:41:36 +0800168 *)
169 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500170 -v'[Verbose (more) output]'
171 ;;
172 esac
173 ;;
174 esac
Zifei Tong9414b222010-08-22 12:41:36 +0800175}
176
177__git-flow-feature ()
178{
179 local curcontext="$curcontext" state line
180 typeset -A opt_args
181
182 _arguments -C \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500183 ':command:->command' \
184 '*::options:->options'
Zifei Tong9414b222010-08-22 12:41:36 +0800185
186 case $state in
187 (command)
Justin Hileman56ff8b42011-01-18 09:58:31 -0500188
Zifei Tong9414b222010-08-22 12:41:36 +0800189 local -a subcommands
190 subcommands=(
Justin Hileman66847ba2011-01-18 09:49:58 -0500191 'start:Start a new feature branch.'
192 'finish:Finish a feature branch.'
MURAOKA Yusukec58f8c22011-01-18 06:42:31 +0900193 'list:List all your feature branches. (Alias to `git flow feature`)'
Zifei Tong9414b222010-08-22 12:41:36 +0800194 'publish: public'
195 'track: track'
196 'diff: diff'
197 'rebase: rebase'
198 'checkout: checkout'
199 'pull: pull'
200 )
MURAOKA Yusukec58f8c22011-01-18 06:42:31 +0900201 _describe -t commands 'git flow feature' subcommands
Zifei Tong9414b222010-08-22 12:41:36 +0800202 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500203 -v'[Verbose (more) output]'
Zifei Tong9414b222010-08-22 12:41:36 +0800204 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500205
Zifei Tong9414b222010-08-22 12:41:36 +0800206 (options)
207 case $line[1] in
Justin Hileman56ff8b42011-01-18 09:58:31 -0500208
Zifei Tong9414b222010-08-22 12:41:36 +0800209 (start)
210 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500211 -F'[Fetch from origin before performing finish]'\
Zifei Tong9414b222010-08-22 12:41:36 +0800212 ':feature:__git_flow_feature_list'\
213 ':branch-name:__git_branch_names'
Justin Hileman56ff8b42011-01-18 09:58:31 -0500214 ;;
215
Zifei Tong9414b222010-08-22 12:41:36 +0800216 (finish)
217 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500218 -F'[Fetch from origin before performing finish]' \
219 -r'[Rebase instead of merge]'\
220 ':feature:__git_flow_feature_list'
Zifei Tong9414b222010-08-22 12:41:36 +0800221 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500222
Zifei Tong9414b222010-08-22 12:41:36 +0800223 (publish)
224 _arguments \
225 ':feature:__git_flow_feature_list'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500226 ;;
227
Zifei Tong9414b222010-08-22 12:41:36 +0800228 (track)
229 _arguments \
230 ':feature:__git_flow_feature_list'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500231 ;;
232
Zifei Tong9414b222010-08-22 12:41:36 +0800233 (diff)
234 _arguments \
235 ':branch:__git_branch_names'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500236 ;;
Zifei Tong9414b222010-08-22 12:41:36 +0800237
238 (rebase)
239 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500240 -i'[Do an interactive rebase]' \
241 ':branch:__git_branch_names'
Zifei Tong9414b222010-08-22 12:41:36 +0800242 ;;
243
244 (checkout)
245 _arguments \
Vincent Driessenbee82182010-08-22 21:01:01 +0800246 ':branch:__git_flow_feature_list'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500247 ;;
Zifei Tong9414b222010-08-22 12:41:36 +0800248
249 (pull)
250 _arguments \
251 ':remote:__git_remotes'\
252 ':branch:__git_branch_names'
Justin Hileman56ff8b42011-01-18 09:58:31 -0500253 ;;
254
Zifei Tong9414b222010-08-22 12:41:36 +0800255 *)
256 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500257 -v'[Verbose (more) output]'
258 ;;
259 esac
260 ;;
261 esac
Zifei Tong9414b222010-08-22 12:41:36 +0800262}
263
264__git_flow_version_list ()
265{
Justin Hileman56ff8b42011-01-18 09:58:31 -0500266 local expl
267 declare -a versions
Zifei Tong9414b222010-08-22 12:41:36 +0800268
Justin Hileman56ff8b42011-01-18 09:58:31 -0500269 versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
270 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800271
Justin Hileman56ff8b42011-01-18 09:58:31 -0500272 _wanted versions expl 'version' compadd $versions
Zifei Tong9414b222010-08-22 12:41:36 +0800273}
274
275__git_flow_feature_list ()
276{
Justin Hileman56ff8b42011-01-18 09:58:31 -0500277 local expl
278 declare -a features
Zifei Tong9414b222010-08-22 12:41:36 +0800279
Justin Hileman56ff8b42011-01-18 09:58:31 -0500280 features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
281 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800282
Justin Hileman56ff8b42011-01-18 09:58:31 -0500283 _wanted features expl 'feature' compadd $features
Zifei Tong9414b222010-08-22 12:41:36 +0800284}
285
286__git_remotes () {
Justin Hileman56ff8b42011-01-18 09:58:31 -0500287 local expl gitdir remotes
Zifei Tong9414b222010-08-22 12:41:36 +0800288
Justin Hileman56ff8b42011-01-18 09:58:31 -0500289 gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
290 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800291
Justin Hileman56ff8b42011-01-18 09:58:31 -0500292 remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
293 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800294
Justin Hileman56ff8b42011-01-18 09:58:31 -0500295 # TODO: Should combine the two instead of either or.
296 if (( $#remotes > 0 )); then
297 _wanted remotes expl remote compadd $* - $remotes
298 else
299 _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
300 fi
Zifei Tong9414b222010-08-22 12:41:36 +0800301}
302
303__git_flow_hotfix_list ()
304{
Justin Hileman56ff8b42011-01-18 09:58:31 -0500305 local expl
306 declare -a hotfixes
Zifei Tong9414b222010-08-22 12:41:36 +0800307
Justin Hileman56ff8b42011-01-18 09:58:31 -0500308 hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
309 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800310
Justin Hileman56ff8b42011-01-18 09:58:31 -0500311 _wanted hotfixes expl 'hotfix' compadd $hotfixes
Zifei Tong9414b222010-08-22 12:41:36 +0800312}
313
314__git_branch_names () {
Justin Hileman56ff8b42011-01-18 09:58:31 -0500315 local expl
316 declare -a branch_names
Zifei Tong9414b222010-08-22 12:41:36 +0800317
Justin Hileman56ff8b42011-01-18 09:58:31 -0500318 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
319 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800320
Justin Hileman56ff8b42011-01-18 09:58:31 -0500321 _wanted branch-names expl branch-name compadd $* - $branch_names
Zifei Tong9414b222010-08-22 12:41:36 +0800322}
323
324__git_command_successful () {
Justin Hileman56ff8b42011-01-18 09:58:31 -0500325 if (( ${#pipestatus:#0} > 0 )); then
326 _message 'not a git repository'
327 return 1
328 fi
329 return 0
Zifei Tong9414b222010-08-22 12:41:36 +0800330}
331
Zifei Tong85b504a2010-08-22 10:37:55 +0800332zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'