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