_repo 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #compdef repo
  2. __git_apply_whitespace_strategies ()
  3. {
  4. declare -a strategies
  5. strategies=(
  6. 'nowarn:turn off the trailing-whitespace warning'
  7. 'warn:output trailing-whitespace warning, but apply patch'
  8. 'fix:output trailing-whitespace warning and strip trailing whitespace'
  9. 'error:output trailing-whitespace warning and refuse to apply patch'
  10. 'error-all:same as "error", but output warnings for all files')
  11. _describe -t strategies 'trailing-whitespace resolution strategy' strategies $*
  12. }
  13. _repo()
  14. {
  15. local context state state_descr line curcontext="$curcontext"
  16. typeset -A opt_args
  17. local ret=1
  18. _arguments -C \
  19. '(- 1 *)--help[show usage]'\
  20. '1:command:->command'\
  21. '*::args:->args' && ret=0
  22. case $state in
  23. (command)
  24. repo list 2> /dev/null > /dev/null
  25. if [[ $? == 0 ]]; then
  26. local commands;
  27. commands=(
  28. 'abandon:Permanently abandon a development branch'
  29. 'branch:View current topic branches'
  30. 'branches:View current topic branches'
  31. 'checkout:Checkout a branch for development'
  32. 'cherry-pick:Cherry-pick a change.'
  33. 'diff:Show changes between commit and working tree'
  34. 'download:Download and checkout a change'
  35. 'forall:execute command on several project'
  36. 'grep:Print lines matching a pattern'
  37. 'help:Display detailed help on a command'
  38. 'init:Initialize repo in the current directory'
  39. 'list:List projects and their associated directories'
  40. 'manifest:Manifest inspection utility'
  41. 'overview:Display overview of unmerged project branches'
  42. 'prune:Prune (delete) already merged topics'
  43. 'rebase:Rebase local branches on upstream branch'
  44. 'selfupdate:Update repo to the latest version'
  45. 'smartsync:Update working tree to the latest known good revision'
  46. 'stage:Stage file(s) for commit'
  47. 'start:Start a new branch for development'
  48. 'status:Show the working tree status'
  49. 'sync:Update working tree to the latest revision'
  50. 'upload:Upload changes for code review'
  51. 'version:Display the version of repo'
  52. )
  53. _describe -t commands 'command' commands && ret=0
  54. else
  55. local commands;
  56. commands=(
  57. 'init:Install repo in the current working directory'
  58. 'help:Display detailed help on a command'
  59. )
  60. _describe -t commands 'command' commands && ret=0
  61. fi
  62. ;;
  63. (args)
  64. case $words[1] in
  65. (branch | branches)
  66. # TODO : list available projects and add them in list to feed compadd with
  67. _arguments : \
  68. "(-h --help)"{-h,--help}"[Show help]" \
  69. ': :__repo_projects' \
  70. && ret=0
  71. ;;
  72. (abandon)
  73. # TODO : list available projects and add them in list to feed compadd with
  74. _arguments : \
  75. "(-h --help)"{-h,--help}"[Show help]" \
  76. ':branch name:__repo_branch' \
  77. ': :__repo_projects'\
  78. && ret=0
  79. ;;
  80. (checkout)
  81. # TODO : list available projects and add them in list to feed compadd with
  82. _arguments : \
  83. "(-h --help)"{-h,--help}"[Show help]" \
  84. ':branch name:__repo_branch' \
  85. ': :__repo_projects'\
  86. && ret=0
  87. ;;
  88. (init)
  89. _arguments : \
  90. "(-h --help)"{-h,--help}"[Show help]" \
  91. "(-q --quiet)"{-q,--quiet}"[be quiet]" \
  92. "(-u --manifest-url)"{-u,--manifest-url=}"[manifest repository location]":url:__repo_url_prompt \
  93. "(-b --manifest-branch)"{-b,--manifest-branch=}"[manifest branch or revision]":branch:__repo_branch\
  94. "(-m --manifest-name)"{-m,--manifest-name=}"[initial manifest file]":manifest_name:__repo_manifest_name\
  95. "(--mirror)--mirror[mirror the forrest]"\
  96. "(--reference)--reference=[location of mirror directory]":dir:_dirs\
  97. "(--depth)--depth=[create a shallow clone with given depth; see git clone]":depth:__repo_depth_prompt\
  98. "(-g --group=)"{-g,--group=}"[restrict manifest projects to ones with a specified group]":group:_group\
  99. "(-p --platform=)"{-p,--platform=}"[restrict manifest projects to ones with a specified platform group(auto|all|none|linux|darwin|...)]":platform:"(auto all none linux darwin)"\
  100. "(--repo-url)--repo-url=[repo repository location]":url:__repo_url_prompt\
  101. "(--repo-branch)--repo-branch[repo branch or revision]":branch_or_rev:__repo__repo_branch_or_rev\
  102. "(--no-repo-verify)--no-repo-verify[do not verify repo source code]"\
  103. "(--config-name)--config-name[Always prompt for name/e-mail]"\
  104. && ret=0
  105. ;;
  106. (start)
  107. _arguments : \
  108. "(-h --help)"{-h,--help}"[Show help]" \
  109. "(--all)--all=[begin branch in all projects]"\
  110. ':branch name:__repo_new__repo_branch_name' \
  111. ':projects:__repo_projects_or_all' \
  112. && ret=0
  113. ;;
  114. (rebase)
  115. _arguments : \
  116. "(-h --help)"{-h,--help}"[Show help]" \
  117. "(-i --interactive)"{-i,--interactive}"[interactive rebase (single project only)]: :__repo_projects" \
  118. "(-f --force-rebase)"{-f,--force-rebase}"[Pass --force-rebase to git rebase]" \
  119. "(--no-ff)--no-ff=[Pass --no-ff to git rebase]"\
  120. "(-q --quiet)"{-q,--quiet}"[Pass --quiet to git rebase]" \
  121. "(--autosquash)--no-ff[Pass --autosquash to git rebase]"\
  122. "(--whitespace=)--whitespace=[Pass --whitespace to git rebase]: :__git_apply_whitespace_strategies"\
  123. "(--auto-stash)--auto-stash[Stash local modifications before starting]"\
  124. && ret=0
  125. ;;
  126. (checkout)
  127. _arguments : \
  128. "(-h --help)"{-h,--help}"[Show help]" \
  129. ':branch name:__git_branch_names' \
  130. ':projects:__repo_projects' \
  131. && ret=0
  132. ;;
  133. (list)
  134. _arguments : \
  135. "(-h --help)"{-h,--help}"[Show help]" \
  136. && ret=0
  137. ;;
  138. (status)
  139. _arguments : \
  140. "(-h --help)"{-h,--help}"[Show help]" \
  141. "(-j --jobs)"{-j,--jobs}"[number of projects to check simultaneously]" \
  142. ':projects:__repo_projects' \
  143. && ret=0
  144. ;;
  145. (sync)
  146. _arguments : \
  147. "(-h --help)"{-h,--help}"[Show help]" \
  148. "(--no-force-broken)--no-force-broken[stop sync if a project fails to sync (probably because of permissions)]" \
  149. "(-l --local-only)"{-l,--local-only}"[only update working tree, don't fetch]" \
  150. "(-n --network-only)"{-n,--network-branch}"[fetch only, don't update working tree]" \
  151. "(-d --detach)"{-d,--detach}"[detach projects back to manifest revision]" \
  152. "(-c --current-branch)"{-c,--current-branch}"[fetch only current branch from server]" \
  153. "(-q --quiet)"{-q,--quiet}"[be more quiet]" \
  154. "(-j --jobs=)"{-j,--jobs=}"[projects to fetch simultaneously (default 1) (limited to 5)]:projects to fetch simultaneously (default 1) (limited to 5)" \
  155. "(-m --manifest-name=)"{-m,--manifest-name=}"[temporary manifest to use for this sync]:manifest xml file:_files -g *.xml" \
  156. "(--no-clone-bundle)--no-clone-bundle[disable use of /clone.bundle on HTTP/HTTPS]" \
  157. "(-s --smart-sync)"{-s,--smart-sync=}"[smart sync using manifest from a known tag]:tag:" \
  158. '(--no-repo-verify)--no-repo-verify[do not verify repo source code]' \
  159. ': :__repo_projects' \
  160. && ret=0
  161. ;;
  162. (upload)
  163. _arguments : \
  164. "(-h --help)"{-h,--help}"[Show help]" \
  165. "(-t)-t[Send local branch name to Gerrit Code Review]" \
  166. "(--re= --reviewers=)"{--re=,--reviewers=}"[Request reviews from these people]:Request reviews from these people:" \
  167. "(--cc=)--cc=[Also send email to these email addresses.]:email addresses:_email_addresses" \
  168. "(--br=)--br=[Branch to upload.]:branch:__repo_branch" \
  169. "(--cbr --current-branch)"{--cbr,--current-branch}"[Upload current git branch]" \
  170. "(-d --draft)"{-d,--draft}"[If specified, upload as a draft.]" \
  171. "(--verify --no-verify)--no-verify[Do not run the upload hook.]" \
  172. '(--verify --no-verify)--verify[Run the upload hook without prompting]' \
  173. ': :__repo_projects' \
  174. && ret=0
  175. ;;
  176. (forall)
  177. _arguments : \
  178. "(-h --help)"{-h,--help}"[Show help]" \
  179. "(-v --verbose)"{-v,--verbose}"[Show command error messages]" \
  180. '(-p)-p[Show project headers before output]' \
  181. ': :__repo_projects_mandatory' \
  182. "(-c --command -h --help -v --verbose -p)"{-c,--command}"[Command (and arguments) to execute]" \
  183. && ret=0
  184. ;;
  185. *)
  186. ret=0
  187. esac
  188. ;;
  189. esac
  190. return $ret
  191. }
  192. __repo_reviewers()
  193. {
  194. # _message -e url 'reviewers'
  195. }
  196. __repo_url_prompt()
  197. {
  198. _message -e url 'url'
  199. }
  200. __repo_manifest_name()
  201. {
  202. _message -e manifest_name 'manifest name'
  203. }
  204. _group()
  205. {
  206. _message -e group 'group'
  207. }
  208. __repo_branch()
  209. {
  210. #_message -e branch 'Repo branch'
  211. branches=($(repo branches| cut -c4- | grep '|' | cut -d' ' -f1))
  212. _describe -t branches 'Select repo branch' branches
  213. }
  214. __repo__repo_branch_or_rev()
  215. {
  216. _message -e branch_or_rev 'repo branch or revision'
  217. }
  218. __repo_depth_prompt()
  219. {
  220. _message -e depth 'depth'
  221. }
  222. __repo_projects()
  223. {
  224. _message -e depth 'Optional option : <projects>...'
  225. projects=($(repo list | cut -d' ' -f1))
  226. _describe -t projects 'Select projects (keep empty for selecting all projects)' projects
  227. }
  228. __repo_projects_mandatory()
  229. {
  230. projects=($(repo list | cut -d' ' -f1))
  231. #_describe -t projects 'Select projects to apply commands' projects
  232. _values -s ' ' "Select projects to apply commands" $projects
  233. }
  234. __repo_new__repo_branch_name()
  235. {
  236. branches=($(repo branches| cut -c4- | grep '|' | cut -d' ' -f1))
  237. _describe "" branches
  238. _message -e "branch name" 'Enter new branch name or select an existing repo branch'
  239. }
  240. __repo_projects_or_all()
  241. {
  242. #_message -e depth '[--all | <project>...]'
  243. projects=(--all $(repo list | cut -d' ' -f1))
  244. _describe -t projects 'Select projects or --all' projects
  245. _describe -t --all 'All projects'
  246. }
  247. _repo "$@"
  248. return $?