Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Philippe Blain" <levraiphilippeblain@gmail.com>,
	"Britton Leo Kerin" <britton.kerin@gmail.com>,
	"Elijah Newren" <newren@gmail.com>,
	"Rubén Justo" <rjusto@gmail.com>,
	"Patrick Steinhardt" <ps@pks.im>,
	"D. Ben Knoble" <ben.knoble@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH v2 0/3] completion of 'git [-C <dir>] checkout'
Date: Wed, 12 Aug 2026 09:48:43 -0700	[thread overview]
Message-ID: <20260812164846.2236221-1-gitster@pobox.com> (raw)
In-Reply-To: <xmqq7blx5oor.fsf@gitster.g>

Continuing from the previous 'git [-C <dir>] diff' series, these two
patches correct completion for 'git checkout [-C <dir>] path<TAB>',
but without falling back to untracked paths, as "checkout paths out
of the index" is by definition about paths that appear in the index.

This has been rebuilt on the v6 iteration of the 'complete-diff'
topic to give the tests a more structured and logical organization.

Additionally, [PATCH 3/3] is new.  It teaches the completion
machinery to complete untracked paths in the working tree, which may
be of limited use, as it is unlikely that a file tracked on another
branch (and thus capable of being restored with 'git checkout
another-branch path') would be lying around untracked in the working
tree to begin with.

 1/3: completion: no-op refactoring of checkout completion
 2/3: completion: complete tracked paths for "git checkout"
 3/3: completion: 'git checkout' completes untracked paths as a last
        resort

 contrib/completion/git-completion.bash | 88 ++++++++++++++------------
 t/t9902-completion.sh                  | 56 ++++++++++++++++
 2 files changed, 105 insertions(+), 39 deletions(-)

Range-diff against v1:
1:  f35017f5c9 = 1:  d3b022ac73 completion: no-op refactoring of checkout completion
2:  20d57f0336 ! 2:  85019fbf97 completion: complete tracked paths for "git checkout"
    @@ contrib/completion/git-completion.bash: _git_checkout ()
      	fi
     +
     +	if [ ${#COMPREPLY[@]} -eq 0 ]; then
    -+		__git_complete_index_file
    ++		__git_complete_index_file ""
     +	fi
      }
      
    @@ t/t9902-completion.sh: test_expect_success 'git -C <path> checkout uses the righ
      '
      
     +test_expect_success 'git checkout completes tracked paths when no refs match' '
    -+	# file1 and file2 are tracked but ufile is not
    ++	# file1 and file2 are tracked but file3 is not
     +	# there is no ref that begins with f
     +	test_completion "git checkout f" <<-\EOF &&
     +	file1
    @@ t/t9902-completion.sh: test_expect_success 'git -C <path> checkout uses the righ
     +	EOF
     +'
     +
    -+test_expect_success 'git -C <path> checkout completes tracked paths in specified repo' '
    ++test_expect_success 'git -C <path> checkout completes paths in specified repo' '
    ++	# otherfile is tracked, oops is not
    ++	# lostfile is tracked but lost
     +	test_when_finished "rm -rf repo-for-checkout" &&
     +	git init repo-for-checkout &&
     +	echo content >repo-for-checkout/otherfile &&
    ++	echo content >repo-for-checkout/lostfile &&
     +	git -C repo-for-checkout add otherfile &&
    ++	git -C repo-for-checkout add lostfile &&
     +	git -C repo-for-checkout commit -m otherfile &&
    ++	echo untracked >repo-for-checkout/oops &&
    ++	rm -f repo-for-checkout/lostfile &&
     +	test_completion "git -C repo-for-checkout checkout o" <<-\EOF &&
     +	otherfile
     +	EOF
    -+	test_completion "git -C repo-for-checkout checkout -- o" <<-\EOF
    ++	test_completion "git -C repo-for-checkout checkout -- o" <<-\EOF &&
     +	otherfile
     +	EOF
    ++	test_completion "git -C repo-for-checkout checkout l" <<-\EOF &&
    ++	lostfile
    ++	EOF
    ++	test_completion "git -C repo-for-checkout checkout -- l" <<-\EOF
    ++	lostfile
    ++	EOF
     +'
     +
      test_expect_success 'git diff completes tracked paths when no refs match' '
-:  ---------- > 3:  56aade8759 completion: 'git checkout' completes untracked paths as a last resort

  parent reply	other threads:[~2026-08-12 16:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11  3:19 [PATCH 0/2] completion of 'git [-C <dir>] checkout' Junio C Hamano
2026-08-11  3:21 ` [PATCH 1/2] completion: no-op refactoring of checkout completion Junio C Hamano
2026-08-11  3:21 ` [PATCH 2/2] completion: complete tracked paths for "git checkout" Junio C Hamano
2026-08-11 16:32   ` Ben Knoble
2026-08-11 17:25     ` Junio C Hamano
2026-08-11  4:04 ` [PATCH 0/2] completion of 'git [-C <dir>] checkout' Junio C Hamano
2026-08-11 16:33   ` Ben Knoble
2026-08-12  1:45     ` Junio C Hamano
2026-08-12 16:48 ` Junio C Hamano [this message]
2026-08-12 16:48   ` [PATCH v2 1/3] completion: no-op refactoring of checkout completion Junio C Hamano
2026-08-12 16:48   ` [PATCH v2 2/3] completion: complete tracked paths for "git checkout" Junio C Hamano
2026-08-12 16:48   ` [PATCH v2 3/3] completion: 'git checkout' completes untracked paths as a last resort Junio C Hamano
2026-08-12 19:57     ` Elijah Newren
2026-08-12 20:18       ` Junio C Hamano

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260812164846.2236221-1-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=ben.knoble@gmail.com \
    --cc=britton.kerin@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=levraiphilippeblain@gmail.com \
    --cc=newren@gmail.com \
    --cc=ps@pks.im \
    --cc=rjusto@gmail.com \
    --cc=szeder.dev@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox