bash completion: teach fetch, pull, and push to complete their options
fetch, pull, and push didn't know their options. They do now. merge's options are factored into a variable so they can be shared between _git_merge and _git_pull Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jay Soffian committed
Mar 5, 2009 at 23:39 UTC
0a4e14727f53ba2e8263622ba5de917b2f9d1575
1 file changed
+56
-5
contrib/completion/git-completion.bash
+56
-5
@@ -391,10 +391,11 @@ __git_complete_remote_or_refspec ()
391
{
392
local cmd="${COMP_WORDS[1]}"
393
local cur="${COMP_WORDS[COMP_CWORD]}"
394
- local i c=2 remote="" pfx="" lhs=1
394
+ local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
395
while [ $c -lt $COMP_CWORD ]; do
396
i="${COMP_WORDS[c]}"
397
case "$i" in
398
+ --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
399
-*) ;;
400
*) remote="$i"; break ;;
401
esac
@@ -404,6 +405,10 @@ __git_complete_remote_or_refspec ()
405
__gitcomp "$(__git_remotes)"
406
return
407
fi
408
+ if [ $no_complete_refspec = 1 ]; then
409
+ COMPREPLY=()
410
+ return
411
+ fi
412
[ "$remote" = "." ] && remote=
413
case "$cur" in
414
*:*)
@@ -904,8 +909,20 @@ _git_diff ()
909
__git_complete_file
910
}
911
912
+__git_fetch_options="
913
+ --quiet --verbose --append --upload-pack --force --keep --depth=
914
+ --tags --no-tags
915
+"
916
+
917
_git_fetch ()
918
{
919
+ local cur="${COMP_WORDS[COMP_CWORD]}"
920
+ case "$cur" in
921
+ --*)
922
+ __gitcomp "$__git_fetch_options"
923
+ return
924
+ ;;
925
+ esac
926
__git_complete_remote_or_refspec
927
}
928
@@ -1110,6 +1127,11 @@ _git_log ()
1127
__git_complete_revlist
1128
}
1129
1130
+__git_merge_options="
1131
+ --no-commit --no-stat --log --no-log --squash --strategy
1132
+ --commit --stat --no-squash --ff --no-ff
1133
+"
1134
+
1135
_git_merge ()
1136
{
1137
__git_complete_strategy && return
@@ -1117,10 +1139,7 @@ _git_merge ()
1139
local cur="${COMP_WORDS[COMP_CWORD]}"
1140
case "$cur" in
1141
--*)
1120
- __gitcomp "
1121
- --no-commit --no-stat --log --no-log --squash --strategy
1122
- --commit --stat --no-squash --ff --no-ff
1123
- "
1142
+ __gitcomp "$__git_merge_options"
1143
return
1144
esac
1145
__gitcomp "$(__git_refs)"
@@ -1169,11 +1188,43 @@ _git_name_rev ()
1188
1189
_git_pull ()
1190
{
1191
+ __git_complete_strategy && return
1192
+
1193
+ local cur="${COMP_WORDS[COMP_CWORD]}"
1194
+ case "$cur" in
1195
+ --*)
1196
+ __gitcomp "
1197
+ --rebase --no-rebase
1198
+ $__git_merge_options
1199
+ $__git_fetch_options
1200
+ "
1201
+ return
1202
+ ;;
1203
+ esac
1204
__git_complete_remote_or_refspec
1205
}
1206
1207
_git_push ()
1208
{
1209
+ local cur="${COMP_WORDS[COMP_CWORD]}"
1210
+ case "${COMP_WORDS[COMP_CWORD-1]}" in
1211
+ --repo)
1212
+ __gitcomp "$(__git_remotes)"
1213
+ return
1214
+ esac
1215
+ case "$cur" in
1216
+ --repo=*)
1217
+ __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1218
+ return
1219
+ ;;
1220
+ --*)
1221
+ __gitcomp "
1222
+ --all --mirror --tags --dry-run --force --verbose
1223
+ --receive-pack= --repo=
1224
+ "
1225
+ return
1226
+ ;;
1227
+ esac
1228
__git_complete_remote_or_refspec
1229
}
1230