Skip to content

Commit 4f46af0

Browse files
committed
_repo: more commands
1 parent 4a1da31 commit 4f46af0

File tree

1 file changed

+115
-11
lines changed
  • Functions/Completion

1 file changed

+115
-11
lines changed

Functions/Completion/_repo

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands
77
# TODO: list programs, function and styles used
88

9+
# TODO: review _arguments to see if -C is really needed everywhere it is used, I
10+
# may have overused it
11+
912
(( $+functions[__repo-help] )) ||
1013
_repo-help() {
1114
_arguments \
@@ -60,7 +63,7 @@ _repo-abandon() {
6063
_repo-branch() {
6164
_arguments \
6265
'(- :)'{-h,--help}'[show help message and exit]' \
63-
"(-)*::projects:__repo_projects"
66+
'(-)*::projects:__repo_projects'
6467
}
6568

6669
(( $+functions[__repo-branches] )) ||
@@ -99,7 +102,93 @@ _repo-diff() {
99102
_arguments -C \
100103
'(- :)'{-h,--help}'[show help message and exit]' \
101104
'(-u --absolute)'{-u,--absolute}'[paths are relative to the repository root]' \
102-
"(-)*::projects:__repo_projects"
105+
'(-)*::projects:__repo_projects'
106+
}
107+
108+
(( $+functions[_repo-diffmanifests] )) ||
109+
_repo-diffmanifests() {
110+
_arguments -C \
111+
'(- :)'{-h,--help}'[show help message and exit]' \
112+
'--raw[display raw diff]' \
113+
'--no-color[does not display the diff in color]' \
114+
'(-):manifest1:_files -g \*.xml' \
115+
'(-)::manifest2:_files -g \*.xml'
116+
}
117+
118+
# TODO: it is a pair of parameters that repo download takes
119+
# can -c be interleaved between the set?
120+
# TODO: completion from open reviews on gerrit
121+
(( $+functions[_repo-download] )) ||
122+
_repo-download() {
123+
_arguments -C \
124+
'(- :)'{-h,--help}'[show help message and exit]' \
125+
'(-c --cherry-pick)'{-c,--cherry-pick}'[cherry-pick instead of checkout]' \
126+
'(-r --revert)'{-r,--revert}'[revert instead of checkout]' \
127+
'(-f --ff-only)'{-f,--ff-only}'[force fast-forward merge]' \
128+
':project:__repo_projects' \
129+
':change/patchset: '
130+
}
131+
132+
(( $+functions[_repo-grep] )) ||
133+
_repo-grep() {
134+
# TODO: implement this
135+
}
136+
137+
# TODO: short options can be shortened like with tar -d -l -> -dl
138+
(( $+functions[_repo-info] )) ||
139+
_repo-info() {
140+
_arguments \
141+
'(- :)'{-h,--help}'[show help message and exit]' \
142+
'(-d --diff)'{-d,--diff}'[show full info and commit diff including remote branches]' \
143+
'(-o --overview)'{-o,--overview}'[show overview of all local commits]' \
144+
'(-b --current-branch)'{-b,--current-branch}'[consider only checked out branches]' \
145+
'(-l --local-only)'{-l,--local-only}'[disable all remote operations]' \
146+
'(-)*::projects:__repo_projects'
147+
}
148+
149+
# TODO: implement the regex usage
150+
# TODO: short option can be combined
151+
(( $+functions[_repo-list] )) ||
152+
_repo-list() {
153+
_arguments -C \
154+
'(- :)'{-h,--help}'[show help message and exit]' \
155+
'(-r --regex)'{-r,--regex}'[filter the project list based on regex or wildcard matching of strings]' \
156+
'(-g --groups)'{-g,--groups=-}'[filter the project list based on the groups the project is in]:group:' \
157+
'(-f --fullpath)'{-f,--fullpath}'[display the full work tree path instead of the relative path]' \
158+
'(-n --name-only)'{-n,--name-only}'[display only the name of the repository]' \
159+
'(-p --path-only)'{-p,--path-only}'[display only the path of the repository]' \
160+
'(-)*::projects:__repo_projects'
161+
}
162+
163+
(( $+functions[_repo-overview] )) ||
164+
_repo-overview() {
165+
_arguments \
166+
'(- :)'{-h,--help}'[show help message and exit]' \
167+
'(-b --current-branch)'{-b,--current-branch}'[consider only checked out branches]' \
168+
'(-)*::projects:__repo_projects'
169+
}
170+
171+
# TODO: complete only projects with active (merged?) branches
172+
(( $+functions[_repo-prune] )) ||
173+
_repo-prune() {
174+
_arguments \
175+
'(- :)'{-h,--help}'[show help message and exit]' \
176+
'(-)*::projects:__repo_projects'
177+
}
178+
179+
# TODO: --interactive is single project only
180+
(( $+functions[_repo-rebase] )) ||
181+
_repo-rebase() {
182+
_arguments \
183+
'(- :)'{-h,--help}'[show help message and exit]' \
184+
'(-i --interactive)'{-i,--interactive}'[interactive rebase (single project only)]' \
185+
'(-f --force-rebase)'{-f,--force-rebase}'[pass --force-rebase to git rebase]' \
186+
'--no-ff[pass --no-ff to git rebase]' \
187+
'(-q --quiet)'{-q,--quiet}'[pass --quiet to git rebase]' \
188+
'--autosquash[pass --autosquash to git rebase]' \
189+
'--whitespace=-[pass --whitespace to git rebase]: :__repo_whitespace_action' \
190+
'--auto-stash[stash local modifications before starting]' \
191+
'(-)*::projects:__repo_projects'
103192
}
104193

105194
# 2 categories
@@ -122,16 +211,15 @@ _repo_commands() {
122211
branches:"view current topic branches"
123212
checkout:"checkout a branch for development"
124213
diff:"show changes between commit and working tree"
214+
diffmanifests:"manifest diff utility"
215+
download:"download and checkout a change"
216+
grep:"print lines matching a pattern"
217+
info:"get info on the manifest branch, current branch or unmerged branches"
218+
list:"list projects and their associated directories"
219+
overview:"display overview of unmerged project branches"
220+
prune:"prune (delete) already merged topics"
221+
rebase:"rebase local branches on upstream branch"
125222

126-
# diffmanifests:"manifest diff utility"
127-
# download:"download and checkout a change"
128-
# grep:"print lines matching a pattern"
129-
# info:"get info on the manifest branch, current branch or unmerged branches"
130-
# init:"initialize repo in the current directory"
131-
# list:"list projects and their associated directories"
132-
# overview:"display overview of unmerged project branches"
133-
# prune:"prune (delete) already merged topics"
134-
# rebase:"rebase local branches on upstream branch"
135223
# smartsync:"update working tree to the latest known good revision"
136224
# stage:"stage file(s) for commit"
137225
# start:"start a new branch for development"
@@ -234,6 +322,7 @@ __repo_branch () {
234322
# if not at the repo root
235323
# TODO: paths with only .. / ../.. / etc should have a description with the path
236324
# relative to the repo root to make it easier to understand
325+
# TODO: could use repo list -fp . to determine the current project
237326
(( $+functions[__repo_projects] )) ||
238327
__repo_projects () {
239328
local p current_project p_rel mydir=$(pwd) keep
@@ -277,6 +366,21 @@ __repo_projects () {
277366
done
278367
}
279368

369+
(( $+functions[__repo_whitespace_action] )) ||
370+
__repo_whitespace_action () {
371+
local -a actions
372+
373+
actions=(
374+
nowarn:"turns off the trailing whitespace warning"
375+
warn:"outputs warnings for a few such errors, but applies the patch as-is (default)"
376+
{fix,strip}:"outputs warnings for a few such errors, and applies the patch after fixing them"
377+
error:"outputs warnings for a few such errors, and refuses to apply the patch"
378+
error-all:"is similar to error but shows all errors"
379+
)
380+
381+
_describe -t whitespace-action "action" actions $*
382+
}
383+
280384
# stolen from _git
281385
(( $+functions[__repo_color_whens] )) ||
282386
__repo_color_whens () {

0 commit comments

Comments
 (0)