From: Jacob Keller <jacob.e.keller@intel.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
Jacob Keller <jacob.keller@gmail.com>
Subject: [PATCH v2 6/9] completion: improve handling of --detach in checkout
Date: Wed, 27 May 2020 04:38:28 -0700 [thread overview]
Message-ID: <20200527113831.3294409-7-jacob.e.keller@intel.com> (raw)
In-Reply-To: <20200527113831.3294409-1-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>
Just like git switch, we should not complete DWIM remote branch names
if --detach has been specified. To avoid this, refactor _git_checkout in
a similar way to _git_switch.
Note that we don't simply clear dwim_opt when we find -d or --detach, as
we will be adding other modes and checks, making this flow easier to
follow.
Add new tests for the expected --detach behavior for both git switch and
git checkout.
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
contrib/completion/git-completion.bash | 7 +++-
t/t9902-completion.sh | 44 ++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 53afd72d0e4e..38b5a5a0d874 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1489,7 +1489,12 @@ _git_checkout ()
;;
*)
local dwim_opt="$(__git_checkout_default_dwim_mode)"
- __git_complete_refs $dwim_opt
+
+ if [ -n "$(__git_find_on_cmdline "-d --detach")" ]; then
+ __git_complete_refs --mode="refs"
+ else
+ __git_complete_refs $dwim_opt --mode="refs"
+ fi
;;
esac
}
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index ec9437688cd7..5b1868e43632 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1360,6 +1360,50 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues
EOF
'
+test_expect_success 'git switch - with --detach, complete all references' '
+ test_completion "git switch --detach " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
+test_expect_success 'git checkout - with --detach, complete only references' '
+ test_completion "git checkout --detach " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
+test_expect_success 'git switch - with -d, complete all references' '
+ test_completion "git switch -d " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
+test_expect_success 'git checkout - with -d, complete only references' '
+ test_completion "git checkout -d " <<-\EOF
+ HEAD Z
+ master Z
+ matching-branch Z
+ matching-tag Z
+ other/branch-in-other Z
+ other/master-in-other Z
+ EOF
+'
+
test_expect_success 'teardown after ref completion' '
git branch -d matching-branch &&
git tag -d matching-tag &&
--
2.25.2
next prev parent reply other threads:[~2020-05-27 11:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 11:38 [PATCH v2 0/9] refactor completion for switch and checkout Jacob Keller
2020-05-27 11:38 ` [PATCH v2 1/9] completion: replace overloaded track term for __git_complete_refs Jacob Keller
2020-05-27 11:38 ` [PATCH v2 2/9] completion: improve handling of DWIM mode for switch/checkout Jacob Keller
2020-05-27 18:03 ` Junio C Hamano
2020-05-27 19:41 ` Jacob Keller
2020-05-28 8:53 ` Jacob Keller
2020-05-27 11:38 ` [PATCH v2 3/9] completion: extract function __git_dwim_remote_heads Jacob Keller
2020-05-27 11:38 ` [PATCH v2 4/9] completion: perform DWIM logic directly in __git_complete_refs Jacob Keller
2020-05-27 11:38 ` [PATCH v2 5/9] completion: improve completion for git switch with no options Jacob Keller
2020-05-27 11:38 ` Jacob Keller [this message]
2020-05-27 11:38 ` [PATCH v2 7/9] completion: improve handling of --track in switch/checkout Jacob Keller
2020-05-27 11:38 ` [PATCH v2 8/9] completion: improve handling of -c/-C and -b/-B " Jacob Keller
2020-05-27 11:38 ` [PATCH v2 9/9] completion: improve handling of --orphan option of switch/checkout Jacob Keller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200527113831.3294409-7-jacob.e.keller@intel.com \
--to=jacob.e.keller@intel.com \
--cc=git@vger.kernel.org \
--cc=jacob.keller@gmail.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).