blob: 8607b5fe3a6e22f9fe2344967a914768dc94ab17 [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`)'
Serhiy Oplakanets27905112012-07-23 12:32:50 +030091 'publish:Publish release branch to remote.'
Serhiy Oplakanetsca710d12012-07-23 15:41:51 +030092 'track:Checkout remote release branch.'
Zifei Tong85b504a2010-08-22 10:37:55 +080093 )
94 _describe -t commands 'git flow release' subcommands
Zifei Tong9414b222010-08-22 12:41:36 +080095 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -050096 -v'[Verbose (more) output]'
Zifei Tong85b504a2010-08-22 10:37:55 +080097 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -050098
Zifei Tong85b504a2010-08-22 10:37:55 +080099 (options)
100 case $line[1] in
Justin Hileman56ff8b42011-01-18 09:58:31 -0500101
Zifei Tong85b504a2010-08-22 10:37:55 +0800102 (start)
103 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500104 -F'[Fetch from origin before performing finish]'\
105 ':version:__git_flow_version_list'
106 ;;
107
Zifei Tong9414b222010-08-22 12:41:36 +0800108 (finish)
109 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500110 -F'[Fetch from origin before performing finish]' \
111 -s'[Sign the release tag cryptographically]'\
112 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
113 -m'[Use the given tag message]'\
114 -p'[Push to $ORIGIN after performing finish]'\
115 ':version:__git_flow_version_list'
Zifei Tong85b504a2010-08-22 10:37:55 +0800116 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500117
Serhiy Oplakanets27905112012-07-23 12:32:50 +0300118 (publish)
119 _arguments \
120 ':version:__git_flow_version_list'
121 ;;
122
123 (track)
124 _arguments \
125 ':version:__git_flow_version_list'
126 ;;
127
Zifei Tong9414b222010-08-22 12:41:36 +0800128 *)
129 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500130 -v'[Verbose (more) output]'
131 ;;
132 esac
133 ;;
134 esac
Zifei Tong85b504a2010-08-22 10:37:55 +0800135}
136
Zifei Tong9414b222010-08-22 12:41:36 +0800137__git-flow-hotfix ()
138{
139 local curcontext="$curcontext" state line
140 typeset -A opt_args
141
142 _arguments -C \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500143 ':command:->command' \
144 '*::options:->options'
Zifei Tong9414b222010-08-22 12:41:36 +0800145
146 case $state in
147 (command)
Justin Hileman56ff8b42011-01-18 09:58:31 -0500148
Zifei Tong9414b222010-08-22 12:41:36 +0800149 local -a subcommands
150 subcommands=(
Justin Hileman66847ba2011-01-18 09:49:58 -0500151 'start:Start a new hotfix branch.'
152 'finish:Finish a hotfix branch.'
Zifei Tong9414b222010-08-22 12:41:36 +0800153 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
154 )
155 _describe -t commands 'git flow hotfix' subcommands
156 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500157 -v'[Verbose (more) output]'
Zifei Tong9414b222010-08-22 12:41:36 +0800158 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500159
Zifei Tong9414b222010-08-22 12:41:36 +0800160 (options)
161 case $line[1] in
Justin Hileman56ff8b42011-01-18 09:58:31 -0500162
Zifei Tong9414b222010-08-22 12:41:36 +0800163 (start)
164 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500165 -F'[Fetch from origin before performing finish]'\
Zifei Tong9414b222010-08-22 12:41:36 +0800166 ':hotfix:__git_flow_version_list'\
167 ':branch-name:__git_branch_names'
Justin Hileman56ff8b42011-01-18 09:58:31 -0500168 ;;
169
Zifei Tong9414b222010-08-22 12:41:36 +0800170 (finish)
171 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500172 -F'[Fetch from origin before performing finish]' \
173 -s'[Sign the release tag cryptographically]'\
174 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
175 -m'[Use the given tag message]'\
176 -p'[Push to $ORIGIN after performing finish]'\
177 ':hotfix:__git_flow_hotfix_list'
Zifei Tong9414b222010-08-22 12:41:36 +0800178 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500179
Zifei Tong9414b222010-08-22 12:41:36 +0800180 *)
181 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500182 -v'[Verbose (more) output]'
183 ;;
184 esac
185 ;;
186 esac
Zifei Tong9414b222010-08-22 12:41:36 +0800187}
188
189__git-flow-feature ()
190{
191 local curcontext="$curcontext" state line
192 typeset -A opt_args
193
194 _arguments -C \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500195 ':command:->command' \
196 '*::options:->options'
Zifei Tong9414b222010-08-22 12:41:36 +0800197
198 case $state in
199 (command)
Justin Hileman56ff8b42011-01-18 09:58:31 -0500200
Zifei Tong9414b222010-08-22 12:41:36 +0800201 local -a subcommands
202 subcommands=(
Justin Hileman66847ba2011-01-18 09:49:58 -0500203 'start:Start a new feature branch.'
204 'finish:Finish a feature branch.'
MURAOKA Yusukec58f8c22011-01-18 06:42:31 +0900205 'list:List all your feature branches. (Alias to `git flow feature`)'
Serhiy Oplakanetsca710d12012-07-23 15:41:51 +0300206 'publish:Publish feature branch to remote.'
207 'track:Checkout remote feature branch.'
208 'diff:Show all changes.'
209 'rebase:Rebase from integration branch.'
210 'checkout:Checkout local feature branch.'
211 'pull:Pull changes from remote.'
Zifei Tong9414b222010-08-22 12:41:36 +0800212 )
MURAOKA Yusukec58f8c22011-01-18 06:42:31 +0900213 _describe -t commands 'git flow feature' subcommands
Zifei Tong9414b222010-08-22 12:41:36 +0800214 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500215 -v'[Verbose (more) output]'
Zifei Tong9414b222010-08-22 12:41:36 +0800216 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500217
Zifei Tong9414b222010-08-22 12:41:36 +0800218 (options)
219 case $line[1] in
Justin Hileman56ff8b42011-01-18 09:58:31 -0500220
Zifei Tong9414b222010-08-22 12:41:36 +0800221 (start)
222 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500223 -F'[Fetch from origin before performing finish]'\
Zifei Tong9414b222010-08-22 12:41:36 +0800224 ':feature:__git_flow_feature_list'\
225 ':branch-name:__git_branch_names'
Justin Hileman56ff8b42011-01-18 09:58:31 -0500226 ;;
227
Zifei Tong9414b222010-08-22 12:41:36 +0800228 (finish)
229 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500230 -F'[Fetch from origin before performing finish]' \
231 -r'[Rebase instead of merge]'\
232 ':feature:__git_flow_feature_list'
Zifei Tong9414b222010-08-22 12:41:36 +0800233 ;;
Justin Hileman56ff8b42011-01-18 09:58:31 -0500234
Zifei Tong9414b222010-08-22 12:41:36 +0800235 (publish)
236 _arguments \
237 ':feature:__git_flow_feature_list'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500238 ;;
239
Zifei Tong9414b222010-08-22 12:41:36 +0800240 (track)
241 _arguments \
242 ':feature:__git_flow_feature_list'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500243 ;;
244
Zifei Tong9414b222010-08-22 12:41:36 +0800245 (diff)
246 _arguments \
247 ':branch:__git_branch_names'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500248 ;;
Zifei Tong9414b222010-08-22 12:41:36 +0800249
250 (rebase)
251 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500252 -i'[Do an interactive rebase]' \
253 ':branch:__git_branch_names'
Zifei Tong9414b222010-08-22 12:41:36 +0800254 ;;
255
256 (checkout)
257 _arguments \
Vincent Driessenbee82182010-08-22 21:01:01 +0800258 ':branch:__git_flow_feature_list'\
Justin Hileman56ff8b42011-01-18 09:58:31 -0500259 ;;
Zifei Tong9414b222010-08-22 12:41:36 +0800260
261 (pull)
262 _arguments \
263 ':remote:__git_remotes'\
264 ':branch:__git_branch_names'
Justin Hileman56ff8b42011-01-18 09:58:31 -0500265 ;;
266
Zifei Tong9414b222010-08-22 12:41:36 +0800267 *)
268 _arguments \
Justin Hileman56ff8b42011-01-18 09:58:31 -0500269 -v'[Verbose (more) output]'
270 ;;
271 esac
272 ;;
273 esac
Zifei Tong9414b222010-08-22 12:41:36 +0800274}
275
276__git_flow_version_list ()
277{
Justin Hileman56ff8b42011-01-18 09:58:31 -0500278 local expl
279 declare -a versions
Zifei Tong9414b222010-08-22 12:41:36 +0800280
Justin Hileman56ff8b42011-01-18 09:58:31 -0500281 versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
282 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800283
Justin Hileman56ff8b42011-01-18 09:58:31 -0500284 _wanted versions expl 'version' compadd $versions
Zifei Tong9414b222010-08-22 12:41:36 +0800285}
286
287__git_flow_feature_list ()
288{
Justin Hileman56ff8b42011-01-18 09:58:31 -0500289 local expl
290 declare -a features
Zifei Tong9414b222010-08-22 12:41:36 +0800291
Justin Hileman56ff8b42011-01-18 09:58:31 -0500292 features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
293 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800294
Justin Hileman56ff8b42011-01-18 09:58:31 -0500295 _wanted features expl 'feature' compadd $features
Zifei Tong9414b222010-08-22 12:41:36 +0800296}
297
298__git_remotes () {
Justin Hileman56ff8b42011-01-18 09:58:31 -0500299 local expl gitdir remotes
Zifei Tong9414b222010-08-22 12:41:36 +0800300
Justin Hileman56ff8b42011-01-18 09:58:31 -0500301 gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
302 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800303
Justin Hileman56ff8b42011-01-18 09:58:31 -0500304 remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
305 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800306
Justin Hileman56ff8b42011-01-18 09:58:31 -0500307 # TODO: Should combine the two instead of either or.
308 if (( $#remotes > 0 )); then
309 _wanted remotes expl remote compadd $* - $remotes
310 else
311 _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
312 fi
Zifei Tong9414b222010-08-22 12:41:36 +0800313}
314
315__git_flow_hotfix_list ()
316{
Justin Hileman56ff8b42011-01-18 09:58:31 -0500317 local expl
318 declare -a hotfixes
Zifei Tong9414b222010-08-22 12:41:36 +0800319
Justin Hileman56ff8b42011-01-18 09:58:31 -0500320 hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
321 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800322
Justin Hileman56ff8b42011-01-18 09:58:31 -0500323 _wanted hotfixes expl 'hotfix' compadd $hotfixes
Zifei Tong9414b222010-08-22 12:41:36 +0800324}
325
326__git_branch_names () {
Justin Hileman56ff8b42011-01-18 09:58:31 -0500327 local expl
328 declare -a branch_names
Zifei Tong9414b222010-08-22 12:41:36 +0800329
Justin Hileman56ff8b42011-01-18 09:58:31 -0500330 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
331 __git_command_successful || return
Zifei Tong9414b222010-08-22 12:41:36 +0800332
Justin Hileman56ff8b42011-01-18 09:58:31 -0500333 _wanted branch-names expl branch-name compadd $* - $branch_names
Zifei Tong9414b222010-08-22 12:41:36 +0800334}
335
336__git_command_successful () {
Justin Hileman56ff8b42011-01-18 09:58:31 -0500337 if (( ${#pipestatus:#0} > 0 )); then
338 _message 'not a git repository'
339 return 1
340 fi
341 return 0
Zifei Tong9414b222010-08-22 12:41:36 +0800342}
343
Dominique Lasserredace0bb2012-09-26 14:54:08 +0200344zstyle ':completion:*:*:git:*' user-commands flow:'provide high-level repository operations'