From patchwork Wed May 27 11:38:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 11572663 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA1FC14C0 for ; Wed, 27 May 2020 11:38:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAB0820873 for ; Wed, 27 May 2020 11:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728061AbgE0Lis (ORCPT ); Wed, 27 May 2020 07:38:48 -0400 Received: from mga18.intel.com ([134.134.136.126]:3343 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730075AbgE0Lig (ORCPT ); Wed, 27 May 2020 07:38:36 -0400 IronPort-SDR: /zBeaFpDqe4fQ9pQcWpYHtDqhWXfjsj6qkfv+ycDcf5HxcDZ6l7IP7vNOFsMlpKU9aJJWpdK98 GT+R4T+1z4bw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 04:38:34 -0700 IronPort-SDR: /LDSV9MZae240sa6HIrFzWOXBE9H13naiG+dk6f8isMu7k5klN47FwI/zIpkvOpo3PowVzWo2P 48iwPWI1195w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,441,1583222400"; d="scan'208";a="302431800" Received: from jekeller-desk.amr.corp.intel.com ([10.166.241.33]) by orsmga008.jf.intel.com with ESMTP; 27 May 2020 04:38:34 -0700 From: Jacob Keller To: git@vger.kernel.org Cc: Jonathan Nieder , Jacob Keller Subject: [PATCH v2 6/9] completion: improve handling of --detach in checkout Date: Wed, 27 May 2020 04:38:28 -0700 Message-Id: <20200527113831.3294409-7-jacob.e.keller@intel.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200527113831.3294409-1-jacob.e.keller@intel.com> References: <20200527113831.3294409-1-jacob.e.keller@intel.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jacob Keller 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 --- 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 &&