_git-flow 7.8 KB

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