_repo 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. "(-r --rev --revision)"{-r,--rev,--revision=}"[point branch at this revision instead of upstream]":branch_or_rev:__repo__repo_branch_or_rev\
  111. "(--head)--head[abbreviation for --rev HEAD]"\
  112. ':branch name:__repo_new__repo_branch_name' \
  113. ':projects:__repo_projects_or_all' \
  114. && ret=0
  115. ;;
  116. (rebase)
  117. _arguments : \
  118. "(-h --help)"{-h,--help}"[Show help]" \
  119. "(-i --interactive)"{-i,--interactive}"[interactive rebase (single project only)]: :__repo_projects" \
  120. "(-f --force-rebase)"{-f,--force-rebase}"[Pass --force-rebase to git rebase]" \
  121. "(--no-ff)--no-ff=[Pass --no-ff to git rebase]"\
  122. "(-q --quiet)"{-q,--quiet}"[Pass --quiet to git rebase]" \
  123. "(--autosquash)--no-ff[Pass --autosquash to git rebase]"\
  124. "(--whitespace=)--whitespace=[Pass --whitespace to git rebase]: :__git_apply_whitespace_strategies"\
  125. "(--auto-stash)--auto-stash[Stash local modifications before starting]"\
  126. && ret=0
  127. ;;
  128. (checkout)
  129. _arguments : \
  130. "(-h --help)"{-h,--help}"[Show help]" \
  131. ':branch name:__git_branch_names' \
  132. ':projects:__repo_projects' \
  133. && ret=0
  134. ;;
  135. (list)
  136. _arguments : \
  137. "(-h --help)"{-h,--help}"[Show help]" \
  138. && ret=0
  139. ;;
  140. (stage)
  141. _arguments : \
  142. "(-h --help)"{-h,--help}"[Show help]" \
  143. "(-i --interactive)"{-i,--interactive}"[use interactive staging]" \
  144. ':projects:__repo_projects' \
  145. && ret=0
  146. ;;
  147. (status)
  148. _arguments : \
  149. "(-h --help)"{-h,--help}"[Show help]" \
  150. "(-j --jobs)"{-j,--jobs}"[number of projects to check simultaneously]" \
  151. ':projects:__repo_projects' \
  152. && ret=0
  153. ;;
  154. (sync)
  155. _arguments : \
  156. "(-h --help)"{-h,--help}"[Show help]" \
  157. "(--no-force-broken)--no-force-broken[stop sync if a project fails to sync (probably because of permissions)]" \
  158. "(-l --local-only)"{-l,--local-only}"[only update working tree, don't fetch]" \
  159. "(-n --network-only)"{-n,--network-branch}"[fetch only, don't update working tree]" \
  160. "(-d --detach)"{-d,--detach}"[detach projects back to manifest revision]" \
  161. "(-c --current-branch)"{-c,--current-branch}"[fetch only current branch from server]" \
  162. "(-q --quiet)"{-q,--quiet}"[be more quiet]" \
  163. "(-j --jobs=)"{-j,--jobs=}"[projects to fetch simultaneously (default 1) (limited to 5)]:projects to fetch simultaneously (default 1) (limited to 5)" \
  164. "(-m --manifest-name=)"{-m,--manifest-name=}"[temporary manifest to use for this sync]:manifest xml file:_files -g *.xml" \
  165. "(--no-clone-bundle)--no-clone-bundle[disable use of /clone.bundle on HTTP/HTTPS]" \
  166. "(-s --smart-sync)"{-s,--smart-sync=}"[smart sync using manifest from a known tag]:tag:" \
  167. '(--no-repo-verify)--no-repo-verify[do not verify repo source code]' \
  168. ': :__repo_projects' \
  169. && ret=0
  170. ;;
  171. (upload)
  172. _arguments : \
  173. "(-h --help)"{-h,--help}"[Show help]" \
  174. "(-t)-t[Send local branch name to Gerrit Code Review]" \
  175. "(--re= --reviewers=)"{--re=,--reviewers=}"[Request reviews from these people]:Request reviews from these people:" \
  176. "(--cc=)--cc=[Also send email to these email addresses.]:email addresses:_email_addresses" \
  177. "(--br=)--br=[Branch to upload.]:branch:__repo_branch" \
  178. "(--cbr --current-branch)"{--cbr,--current-branch}"[Upload current git branch]" \
  179. "(-d --draft)"{-d,--draft}"[If specified, upload as a draft.]" \
  180. "(--verify --no-verify)--no-verify[Do not run the upload hook.]" \
  181. '(--verify --no-verify)--verify[Run the upload hook without prompting]' \
  182. ': :__repo_projects' \
  183. && ret=0
  184. ;;
  185. (forall)
  186. _arguments : \
  187. "(-h --help)"{-h,--help}"[Show help]" \
  188. "(-v --verbose)"{-v,--verbose}"[Show command error messages]" \
  189. '(-p)-p[Show project headers before output]' \
  190. ': :__repo_projects_mandatory' \
  191. "(-c --command -h --help -v --verbose -p)"{-c,--command}"[Command (and arguments) to execute]" \
  192. && ret=0
  193. ;;
  194. *)
  195. ret=0
  196. esac
  197. ;;
  198. esac
  199. return $ret
  200. }
  201. __repo_reviewers()
  202. {
  203. # _message -e url 'reviewers'
  204. }
  205. __repo_url_prompt()
  206. {
  207. _message -e url 'url'
  208. }
  209. __repo_manifest_name()
  210. {
  211. _message -e manifest_name 'manifest name'
  212. }
  213. _group()
  214. {
  215. _message -e group 'group'
  216. }
  217. __repo_branch()
  218. {
  219. #_message -e branch 'Repo branch'
  220. branches=($(repo branches| cut -c4- | grep '|' | cut -d' ' -f1))
  221. _describe -t branches 'Select repo branch' branches
  222. }
  223. __repo__repo_branch_or_rev()
  224. {
  225. _message -e branch_or_rev 'repo branch or revision'
  226. }
  227. __repo_depth_prompt()
  228. {
  229. _message -e depth 'depth'
  230. }
  231. __repo_projects()
  232. {
  233. _message -e depth 'Optional option : <projects>...'
  234. projects=($(repo list | cut -d' ' -f1))
  235. _describe -t projects 'Select projects (keep empty for selecting all projects)' projects
  236. }
  237. __repo_projects_mandatory()
  238. {
  239. projects=($(repo list | cut -d' ' -f1))
  240. #_describe -t projects 'Select projects to apply commands' projects
  241. _values -s ' ' "Select projects to apply commands" $projects
  242. }
  243. __repo_new__repo_branch_name()
  244. {
  245. branches=($(repo branches| cut -c4- | grep '|' | cut -d' ' -f1))
  246. _describe "" branches
  247. _message -e "branch name" 'Enter new branch name or select an existing repo branch'
  248. }
  249. __repo_projects_or_all()
  250. {
  251. #_message -e depth '[--all | <project>...]'
  252. projects=(--all $(repo list | cut -d' ' -f1))
  253. _describe -t projects 'Select projects or --all' projects
  254. _describe -t --all 'All projects'
  255. }
  256. _repo "$@"
  257. return $?