Skip to content

Commit 0408c6b

Browse files
jacob-kellergitster
authored andcommitted
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>
1 parent c81ca56 commit 0408c6b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

contrib/completion/git-completion.bash

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -749,20 +749,22 @@ __git_refs ()
749749
# Usage: __git_complete_refs [<option>]...
750750
# --remote=<remote>: The remote to list refs from, can be the name of a
751751
# 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.
753753
# --pfx=<prefix>: A prefix to be added to each ref.
754754
# --cur=<word>: The current ref to be completed. Defaults to the current
755755
# word to be completed.
756756
# --sfx=<suffix>: A suffix to be appended to each ref instead of the default
757757
# space.
758758
__git_complete_refs ()
759759
{
760-
local remote track pfx cur_="$cur" sfx=" "
760+
local remote dwim pfx cur_="$cur" sfx=" "
761761

762762
while test $# != 0; do
763763
case "$1" in
764764
--remote=*) remote="${1##--remote=}" ;;
765-
--track) track="yes" ;;
765+
--dwim) dwim="yes" ;;
766+
# --track is an old spelling of --dwim
767+
--track) dwim="yes" ;;
766768
--pfx=*) pfx="${1##--pfx=}" ;;
767769
--cur=*) cur_="${1##--cur=}" ;;
768770
--sfx=*) sfx="${1##--sfx=}" ;;
@@ -771,7 +773,7 @@ __git_complete_refs ()
771773
shift
772774
done
773775

774-
__gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
776+
__gitcomp_direct "$(__git_refs "$remote" "$dwim" "$pfx" "$cur_" "$sfx")"
775777
}
776778

777779
# __git_refs2 requires 1 argument (to pass to __git_refs)
@@ -1370,12 +1372,12 @@ _git_checkout ()
13701372
*)
13711373
# check if --track, --no-track, or --no-guess was specified
13721374
# 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"
13741376
if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
13751377
[ -n "$(__git_find_on_cmdline "$flags")" ]; then
1376-
track_opt=''
1378+
dwim_opt=''
13771379
fi
1378-
__git_complete_refs $track_opt
1380+
__git_complete_refs $dwim_opt
13791381
;;
13801382
esac
13811383
}
@@ -2225,27 +2227,27 @@ _git_switch ()
22252227
*)
22262228
# check if --track, --no-track, or --no-guess was specified
22272229
# if so, disable DWIM mode
2228-
local track_opt="--track" only_local_ref=n
2230+
local dwim_opt="--dwim" only_local_ref=n
22292231
if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
22302232
[ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then
2231-
track_opt=''
2233+
dwim_opt=''
22322234
fi
22332235
# explicit --guess enables DWIM mode regardless of
22342236
# $GIT_COMPLETION_CHECKOUT_NO_GUESS
22352237
if [ -n "$(__git_find_on_cmdline "--guess")" ]; then
2236-
track_opt='--track'
2238+
dwim_opt='--dwim'
22372239
fi
22382240
if [ -z "$(__git_find_on_cmdline "-d --detach")" ]; then
22392241
only_local_ref=y
22402242
else
22412243
# --guess --detach is invalid combination, no
22422244
# dwim will be done when --detach is specified
2243-
track_opt=
2245+
dwim_opt=
22442246
fi
2245-
if [ $only_local_ref = y -a -z "$track_opt" ]; then
2247+
if [ $only_local_ref = y -a -z "$dwim_opt" ]; then
22462248
__gitcomp_direct "$(__git_heads "" "$cur" " ")"
22472249
else
2248-
__git_complete_refs $track_opt
2250+
__git_complete_refs $dwim_opt
22492251
fi
22502252
;;
22512253
esac

0 commit comments

Comments
 (0)