diff options
author | Jacob Keller <jacob.keller@gmail.com> | 2020-05-28 11:10:48 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-05-28 12:57:07 -0700 |
commit | 91439928ecfcb402856dc5dffacdc36ca070d84e (patch) | |
tree | 5716544b26cf8ef683672a0a4f2a3b5be0d8f17e /contrib/completion | |
parent | completion: improve handling of -c/-C and -b/-B in switch/checkout (diff) | |
download | tgif-91439928ecfcb402856dc5dffacdc36ca070d84e.tar.xz |
completion: improve handling of --orphan option of switch/checkout
The --orphan option is used to create a local branch which is detached
from the current history. In git switch, it always resets to the empty
tree, and thus the only completion we can provide is a branch name.
Follow the same rules for -c/-C (and -b/-B) when completing the argument
to --orphan.
In the case of git switch, after we complete the argument, there is
nothing more we can complete for git switch, so do not even try. Nothing
else would be valid.
In the case of git checkout, --orphan takes a start point which it uses
to determine the checked out tree, even though it created orphaned
history.
Update the previously added test cases as they are now passing.
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/completion')
-rw-r--r-- | contrib/completion/git-completion.bash | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 9dd0412ecc..6df1e8013d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1508,7 +1508,7 @@ _git_checkout () local prevword prevword="${words[cword-1]}" case "$prevword" in - -b|-B) + -b|-B|--orphan) # Complete local branches (and DWIM branch # remote branch names) for an option argument # specifying a new branch name. This is for @@ -1522,14 +1522,14 @@ _git_checkout () esac # At this point, we've already handled special completion for - # the arguments to -b/-B. There are 3 main things left we can - # possibly complete: - # 1) a start-point for -b/-B or -d/--detach + # the arguments to -b/-B, and --orphan. There are 3 main + # things left we can possibly complete: + # 1) a start-point for -b/-B, -d/--detach, or --orphan # 2) a remote head, for --track # 3) an arbitrary reference, possibly including DWIM names # - if [ -n "$(__git_find_on_cmdline "-b -B -d --detach")" ]; then + if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then __git_complete_refs --mode="refs" elif [ -n "$(__git_find_on_cmdline "--track")" ]; then __git_complete_refs --mode="remote-heads" @@ -2387,7 +2387,7 @@ _git_switch () local prevword prevword="${words[cword-1]}" case "$prevword" in - -c|-C) + -c|-C|--orphan) # Complete local branches (and DWIM branch # remote branch names) for an option argument # specifying a new branch name. This is for @@ -2400,8 +2400,15 @@ _git_switch () ;; esac + # Unlike in git checkout, git switch --orphan does not take + # a start point. Thus we really have nothing to complete after + # the branch name. + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then + return + fi + # At this point, we've already handled special completion for - # -c/-C. There are 3 main things left to + # -c/-C, and --orphan. There are 3 main things left to # complete: # 1) a start-point for -c/-C or -d/--detach # 2) a remote head, for --track |