|
37 | 37 | # GIT_COMPLETION_CHECKOUT_NO_GUESS
|
38 | 38 | #
|
39 | 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). |
41 | 42 |
|
42 | 43 | case "$COMP_WORDBREAKS" in
|
43 | 44 | *:*) : great ;;
|
@@ -2158,6 +2159,40 @@ _git_status ()
|
2158 | 2159 | __git_complete_index_file "$complete_opt"
|
2159 | 2160 | }
|
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 | + |
2161 | 2196 | __git_config_get_set_variables ()
|
2162 | 2197 | {
|
2163 | 2198 | local prevword word config_file= c=$cword
|
|
0 commit comments