completion: support switch
Completion support for --guess could be made better. If no --detach is given, we should only provide a list of refs/heads/* and dwim ones, not the entire ref space. But I still can't penetrate that __git_refs() function yet. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 29, 2019 at 17:39 UTC
ae36fe694180ad2646983d43c5bf12841ac2db47
1 file changed
+36
-1
contrib/completion/git-completion.bash
+36
-1
@@ -37,7 +37,8 @@
37
# GIT_COMPLETION_CHECKOUT_NO_GUESS
38
#
39
# When set to "1", do not include "DWIM" suggestions in git-checkout
40
-# completion (e.g., completing "foo" when "origin/foo" exists).
40
+# and git-switch completion (e.g., completing "foo" when "origin/foo"
41
+# exists).
42
43
case "$COMP_WORDBREAKS" in
44
*:*) : great ;;
@@ -2158,6 +2159,40 @@ _git_status ()
2159
__git_complete_index_file "$complete_opt"
2160
}
2161
2162
+_git_switch ()
2163
+{
2164
+ case "$cur" in
2165
+ --conflict=*)
2166
+ __gitcomp "diff3 merge" "" "${cur##--conflict=}"
2167
+ ;;
2168
+ --*)
2169
+ __gitcomp_builtin switch
2170
+ ;;
2171
+ *)
2172
+ # check if --track, --no-track, or --no-guess was specified
2173
+ # if so, disable DWIM mode
2174
+ local track_opt="--track" only_local_ref=n
2175
+ if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
2176
+ [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then
2177
+ track_opt=''
2178
+ fi
2179
+ # explicit --guess enables DWIM mode regardless of
2180
+ # $GIT_COMPLETION_CHECKOUT_NO_GUESS
2181
+ if [ -n "$(__git_find_on_cmdline "--guess")" ]; then
2182
+ track_opt='--track'
2183
+ fi
2184
+ if [ -z "$(__git_find_on_cmdline "-d --detach")" ]; then
2185
+ only_local_ref=y
2186
+ fi
2187
+ if [ $only_local_ref = y -a -z "$track_opt" ]; then
2188
+ __gitcomp_direct "$(__git_heads "" "$cur" " ")"
2189
+ else
2190
+ __git_complete_refs $track_opt
2191
+ fi
2192
+ ;;
2193
+ esac
2194
+}
2195
+
2196
__git_config_get_set_variables ()
2197
{
2198
local prevword word config_file= c=$cword