From patchwork Sat Apr 25 02:20:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Keller, Jacob E" X-Patchwork-Id: 11509619 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 2DF0F15AB for ; Sat, 25 Apr 2020 02:21:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15E6920857 for ; Sat, 25 Apr 2020 02:21:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726208AbgDYCVF (ORCPT ); Fri, 24 Apr 2020 22:21:05 -0400 Received: from mga12.intel.com ([192.55.52.136]:47708 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726059AbgDYCUz (ORCPT ); Fri, 24 Apr 2020 22:20:55 -0400 IronPort-SDR: f2f+VHRdIL3u9uAfavhSSKs9OvzJKbiO/AualTEGd6KgE/7KPbKFF1BXjzmTUENFW/Q+VrZ0yj e0Aidgv/7tyg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2020 19:20:53 -0700 IronPort-SDR: OjD57f2Ny25n3HhEkO+Bif/PDGqtHNm5WWZV9fA8OC6HKLhl2ba53KQqjlJBnXO8VrXECx8Ozu cWo3t57vquoA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,314,1583222400"; d="scan'208";a="281056781" Received: from jekeller-desk.amr.corp.intel.com ([10.166.241.33]) by fmsmga004.fm.intel.com with ESMTP; 24 Apr 2020 19:20:52 -0700 From: Jacob Keller To: git@vger.kernel.org Cc: Jonathan Nieder , Jacob Keller Subject: [PATCH 05/11] completion: remove completion for git switch --orphan Date: Fri, 24 Apr 2020 19:20:39 -0700 Message-Id: <20200425022045.1089291-7-jacob.e.keller@intel.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200425022045.1089291-1-jacob.e.keller@intel.com> References: <20200425022045.1089291-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 git switch with the --orphan option is used to create a new branch that is not connected to any history and is instead based on the empty tree. It does not make sense for completion to return anything in this case, because there is nothing to complete. Check for --orphan, and if it's found, immediately return from _git_switch() without completing anything. Add a test case which documents this expected behavior. Signed-off-by: Jacob Keller --- contrib/completion/git-completion.bash | 11 ++++++++++- t/t9902-completion.sh | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c21786f2fd00..08d3406cf3e4 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2223,9 +2223,18 @@ _git_switch () __gitcomp_builtin switch ;; *) + local track_opt="--track" only_local_ref=n + + # --orphan is used to create a branch disconnected from the + # current history, based on the empty tree. Since the only + # option required is the branch name, it doesn't make sense to + # complete anything here. + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then + return + fi + # check if --track, --no-track, or --no-guess was specified # if so, disable DWIM mode - local track_opt="--track" only_local_ref=n if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] || [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then track_opt='' diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index a134a8791076..9d02de167219 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference EOF ' +# TODO: completion does not yet recognize --orphan +test_expect_failure 'git switch - with --orphan, do not complete anything' ' + test_completion "git switch --orphan " <<-\EOF + + EOF +' + test_expect_success 'teardown after ref completion' ' git branch -d matching-branch && git tag -d matching-tag &&