@matheusbsbs / matheus-bagliano / commits / 0408c6b412
Fork 0

completion: replace overloaded track term for __git_complete_refs

The __git_complete_refs uses the "--track" option to specify when to enable listing of unique remote branches which are used by the DWIM logic of git checkout and git switch. Using the term '--track' here is confusing because the git commands themselves have '--track' as an argument. Additionally, the completion logic for _git_switch also checks for --track. Keeping the meaning of track_opt and --track for __git_complete_refs straight from the --track git switch and git checkout option is difficult when reading this code. Use the option '--dwim' instead, indicating this is about enabling or disabling logic related to DWIM mode. Also rename the local variable track_opt to dwim_opt to further reduce the confusion when reading the completion code for _git_switch. Because it is plausible for users to have developed their own completions which rely on __git_complete_ref, keep --track as a synonym for --dwim, even though we no longer use it in any of the core git completion logic. Add a comment explaining why it remains as an alternative spelling for --dwim. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Keller committed May 28, 2020 at 11:10 UTC 0408c6b412a6b6f5fa7d1c33424ef00ad8c93533
1 file changed +15 -13
contrib/completion/git-completion.bash
+15 -13
@@ -749,7 +749,7 @@ __git_refs ()
749 # Usage: __git_complete_refs [<option>]...
750 # --remote=<remote>: The remote to list refs from, can be the name of a
751 # configured remote, a path, or a URL.
752 -# --track: List unique remote branches for 'git checkout's tracking DWIMery.
752 +# --dwim: List unique remote branches for 'git switch's tracking DWIMery.
753 # --pfx=<prefix>: A prefix to be added to each ref.
754 # --cur=<word>: The current ref to be completed. Defaults to the current
755 # word to be completed.
@@ -757,12 +757,14 @@ __git_refs ()
757 # space.
758 __git_complete_refs ()
759 {
760 - local remote track pfx cur_="$cur" sfx=" "
760 + local remote dwim pfx cur_="$cur" sfx=" "
761
762 while test $# != 0; do
763 case "$1" in
764 --remote=*) remote="${1##--remote=}" ;;
765 - --track) track="yes" ;;
765 + --dwim) dwim="yes" ;;
766 + # --track is an old spelling of --dwim
767 + --track) dwim="yes" ;;
768 --pfx=*) pfx="${1##--pfx=}" ;;
769 --cur=*) cur_="${1##--cur=}" ;;
770 --sfx=*) sfx="${1##--sfx=}" ;;
@@ -771,7 +773,7 @@ __git_complete_refs ()
773 shift
774 done
775
774 - __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
776 + __gitcomp_direct "$(__git_refs "$remote" "$dwim" "$pfx" "$cur_" "$sfx")"
777 }
778
779 # __git_refs2 requires 1 argument (to pass to __git_refs)
@@ -1370,12 +1372,12 @@ _git_checkout ()
1372 *)
1373 # check if --track, --no-track, or --no-guess was specified
1374 # if so, disable DWIM mode
1373 - local flags="--track --no-track --no-guess" track_opt="--track"
1375 + local flags="--track --no-track --no-guess" dwim_opt="--dwim"
1376 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1377 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1376 - track_opt=''
1378 + dwim_opt=''
1379 fi
1378 - __git_complete_refs $track_opt
1380 + __git_complete_refs $dwim_opt
1381 ;;
1382 esac
1383 }
@@ -2225,27 +2227,27 @@ _git_switch ()
2227 *)
2228 # check if --track, --no-track, or --no-guess was specified
2229 # if so, disable DWIM mode
2228 - local track_opt="--track" only_local_ref=n
2230 + local dwim_opt="--dwim" only_local_ref=n
2231 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
2232 [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then
2231 - track_opt=''
2233 + dwim_opt=''
2234 fi
2235 # explicit --guess enables DWIM mode regardless of
2236 # $GIT_COMPLETION_CHECKOUT_NO_GUESS
2237 if [ -n "$(__git_find_on_cmdline "--guess")" ]; then
2236 - track_opt='--track'
2238 + dwim_opt='--dwim'
2239 fi
2240 if [ -z "$(__git_find_on_cmdline "-d --detach")" ]; then
2241 only_local_ref=y
2242 else
2243 # --guess --detach is invalid combination, no
2244 # dwim will be done when --detach is specified
2243 - track_opt=
2245 + dwim_opt=
2246 fi
2245 - if [ $only_local_ref = y -a -z "$track_opt" ]; then
2247 + if [ $only_local_ref = y -a -z "$dwim_opt" ]; then
2248 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
2249 else
2248 - __git_complete_refs $track_opt
2250 + __git_complete_refs $dwim_opt
2251 fi
2252 ;;
2253 esac