My personal dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_git-flow 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. #compdef git-flow
  2. # ------------------------------------------------------------------------------
  3. # Copyright (c) 2010-2015 Justin Hileman
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in all
  13. # copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  19. # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20. # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
  21. # OR OTHER DEALINGS IN THE SOFTWARE.
  22. # ------------------------------------------------------------------------------
  23. # Description
  24. # -----------
  25. #
  26. # Completion script for git-flow (http://github.com/nvie/gitflow).
  27. #
  28. # Source: https://github.com/bobthecow/git-flow-completion
  29. #
  30. # ------------------------------------------------------------------------------
  31. # Authors
  32. # -------
  33. #
  34. # * Justin Hileman (https://github.com/bobthecow)
  35. # * Yusuke Muraoka (https://github.com/jbking)
  36. # * Vincent Driessen (https://github.com/nvie)
  37. # * Zifei Tong (https://github.com/chevalun)
  38. # * Ben O'Hara (https://github.com/benohara)
  39. #
  40. # ------------------------------------------------------------------------------
  41. _git-flow ()
  42. {
  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. 'init:Initialize a new git repo with support for the branching model.'
  53. 'feature:Manage your feature branches.'
  54. 'release:Manage your release branches.'
  55. 'hotfix:Manage your hotfix branches.'
  56. 'support:Manage your support branches.'
  57. 'version:Shows version information.'
  58. 'status:Shows some status.'
  59. )
  60. _describe -t commands 'git flow' subcommands
  61. ;;
  62. (options)
  63. case $line[1] in
  64. (init)
  65. _arguments \
  66. -f'[Force setting of gitflow branches, even if already configured]' \
  67. -d'[Use default branch naming conventions and prefixes]'
  68. ;;
  69. (version)
  70. ;;
  71. (hotfix)
  72. __git-flow-hotfix
  73. ;;
  74. (release)
  75. __git-flow-release
  76. ;;
  77. (feature)
  78. __git-flow-feature
  79. ;;
  80. (support)
  81. __git-flow-support
  82. ;;
  83. esac
  84. ;;
  85. esac
  86. }
  87. __git-flow-release ()
  88. {
  89. local curcontext="$curcontext" state line
  90. typeset -A opt_args
  91. _arguments -C \
  92. ':command:->command' \
  93. '*::options:->options'
  94. case $state in
  95. (command)
  96. local -a subcommands
  97. subcommands=(
  98. 'start:Start a new release branch.'
  99. 'finish:Finish a release branch.'
  100. 'list:List all your release branches. (Alias to `git flow release`)'
  101. 'publish:Publish this release branch to origin.`)'
  102. 'track:Track a release branch from origin.`)'
  103. )
  104. _describe -t commands 'git flow release' subcommands
  105. _arguments \
  106. -v'[Verbose (more) output]'
  107. ;;
  108. (options)
  109. case $line[1] in
  110. (start)
  111. _arguments \
  112. -F'[Fetch from origin before performing finish]'\
  113. ':version:__git_flow_version_list'
  114. ;;
  115. (finish)
  116. _arguments \
  117. -F'[Fetch from origin before performing finish]' \
  118. -s'[Sign the release tag cryptographically]'\
  119. -u'[Use the given GPG-key for the digital signature (implies -s)]'\
  120. -m'[Use the given tag message]'\
  121. -n'[Dont tag this release ]'\
  122. -p'[Push to $ORIGIN after performing finish]'\
  123. -k'[Keep branch after performing finish]'\
  124. ':version:__git_flow_version_list'
  125. ;;
  126. (publish)
  127. _arguments \
  128. ':version:__git_flow_version_list'
  129. ;;
  130. (track)
  131. _arguments \
  132. ':version:__git_flow_version_list'
  133. ;;
  134. *)
  135. _arguments \
  136. -v'[Verbose (more) output]'
  137. ;;
  138. esac
  139. ;;
  140. esac
  141. }
  142. __git-flow-hotfix ()
  143. {
  144. local curcontext="$curcontext" state line
  145. typeset -A opt_args
  146. _arguments -C \
  147. ':command:->command' \
  148. '*::options:->options'
  149. case $state in
  150. (command)
  151. local -a subcommands
  152. subcommands=(
  153. 'start:Start a new hotfix branch.'
  154. 'finish:Finish a hotfix branch.'
  155. 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
  156. 'publish:Publish this hotfix branch to origin`)'
  157. )
  158. _describe -t commands 'git flow hotfix' subcommands
  159. _arguments \
  160. -v'[Verbose (more) output]'
  161. ;;
  162. (options)
  163. case $line[1] in
  164. (start)
  165. _arguments \
  166. -F'[Fetch from origin before performing finish]'\
  167. ':hotfix:__git_flow_version_list'\
  168. ':branch-name:__git_branch_names'
  169. ;;
  170. (finish)
  171. _arguments \
  172. -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'
  178. ;;
  179. (publish)
  180. _arguments \
  181. ':hotfix:__git_flow_hotfix_list'
  182. ;;
  183. *)
  184. _arguments \
  185. -v'[Verbose (more) output]'
  186. ;;
  187. esac
  188. ;;
  189. esac
  190. }
  191. __git-flow-feature ()
  192. {
  193. local curcontext="$curcontext" state line
  194. typeset -A opt_args
  195. _arguments -C \
  196. ':command:->command' \
  197. '*::options:->options'
  198. case $state in
  199. (command)
  200. local -a subcommands
  201. subcommands=(
  202. 'start:Start a new feature branch.'
  203. 'finish:Finish a feature branch.'
  204. 'list:List all your feature branches. (Alias to `git flow feature`)'
  205. 'publish:Publish this feature branch to origin.'
  206. 'track:Track a feature branch from origin.'
  207. 'diff:Show a diff of changes since this feature branched off.'
  208. 'rebase:Rebase a feature branch on top of develop.'
  209. 'checkout:Check out (switch to) the given feature branch.'
  210. 'pull:Pull a feature branch from a remote peer.'
  211. )
  212. _describe -t commands 'git flow feature' subcommands
  213. _arguments \
  214. -v'[Verbose (more) output]'
  215. ;;
  216. (options)
  217. case $line[1] in
  218. (start)
  219. _arguments \
  220. -F'[Fetch from origin before performing finish]'\
  221. ':feature:__git_flow_feature_list'\
  222. ':branch-name:__git_branch_names'
  223. ;;
  224. (finish)
  225. _arguments \
  226. -F'[Fetch from origin before performing finish]' \
  227. -r'[Finish branch by rebasing first]'\
  228. -k'[Keep branch after performing finish]'\
  229. -D'[Force delete feature branch after finish]'\
  230. ':feature:__git_flow_feature_list'
  231. ;;
  232. (publish)
  233. _arguments \
  234. ':feature:__git_flow_feature_list'\
  235. ;;
  236. (track)
  237. _arguments \
  238. ':feature:__git_flow_feature_list'\
  239. ;;
  240. (diff)
  241. _arguments \
  242. ':branch:__git_branch_names'\
  243. ;;
  244. (rebase)
  245. _arguments \
  246. -i'[Do an interactive rebase]' \
  247. ':branch:__git_branch_names'
  248. ;;
  249. (checkout)
  250. _arguments \
  251. ':branch:__git_flow_feature_list'\
  252. ;;
  253. (pull)
  254. _arguments \
  255. ':remote:__git_remotes'\
  256. ':branch:__git_branch_names'
  257. ;;
  258. *)
  259. _arguments \
  260. -v'[Verbose (more) output]'
  261. ;;
  262. esac
  263. ;;
  264. esac
  265. }
  266. __git-flow-support ()
  267. {
  268. local curcontext="$curcontext" state line
  269. typeset -A opt_args
  270. _arguments -C \
  271. ':command:->command' \
  272. '*::options:->options'
  273. case $state in
  274. (command)
  275. local -a subcommands
  276. subcommands=(
  277. 'start:Start a new support branch.'
  278. 'list:List all your support branches. (Alias to `git flow support`)'
  279. )
  280. _describe -t commands 'git flow support' subcommands
  281. _arguments \
  282. -v'[Verbose (more) output]'
  283. ;;
  284. (options)
  285. case $line[1] in
  286. (start)
  287. _arguments \
  288. -F'[Fetch from origin before performing finish]'\
  289. ':feature:__git_flow_support_list'\
  290. ':branch-name:__git_branch_names'
  291. ;;
  292. *)
  293. _arguments \
  294. -v'[Verbose (more) output]'
  295. ;;
  296. esac
  297. ;;
  298. esac
  299. }
  300. __git_flow_version_list ()
  301. {
  302. local expl
  303. declare -a versions
  304. versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
  305. __git_command_successful || return
  306. _wanted versions expl 'version' compadd $versions
  307. }
  308. __git_flow_feature_list ()
  309. {
  310. local expl
  311. declare -a features
  312. features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
  313. __git_command_successful || return
  314. _wanted features expl 'feature' compadd $features
  315. }
  316. __git_remotes () {
  317. local expl gitdir remotes
  318. gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
  319. __git_command_successful || return
  320. remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
  321. __git_command_successful || return
  322. # TODO: Should combine the two instead of either or.
  323. if (( $#remotes > 0 )); then
  324. _wanted remotes expl remote compadd $* - $remotes
  325. else
  326. _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
  327. fi
  328. }
  329. __git_flow_hotfix_list ()
  330. {
  331. local expl
  332. declare -a hotfixes
  333. hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
  334. __git_command_successful || return
  335. _wanted hotfixes expl 'hotfix' compadd $hotfixes
  336. }
  337. __git_flow_support_list ()
  338. {
  339. local expl
  340. declare -a support
  341. support=(${${(f)"$(_call_program support git flow support list 2> /dev/null | tr -d ' |*')"}})
  342. __git_command_successful || return
  343. _wanted hotfixes expl 'support' compadd $support
  344. }
  345. __git_branch_names () {
  346. local expl
  347. declare -a branch_names
  348. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
  349. __git_command_successful || return
  350. _wanted branch-names expl branch-name compadd $* - $branch_names
  351. }
  352. __git_command_successful () {
  353. if (( ${#pipestatus:#0} > 0 )); then
  354. _message 'not a git repository'
  355. return 1
  356. fi
  357. return 0
  358. }
  359. _git-flow "$@"
  360. # Local Variables:
  361. # mode: Shell-Script
  362. # sh-indentation: 2
  363. # indent-tabs-mode: nil
  364. # sh-basic-offset: 2
  365. # End:
  366. # vim: ft=zsh sw=2 ts=2 et