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