git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/3] completion of 'git [-C <dir>] checkout'

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 12, 2026, 16:48 UTC
Message-ID
<20260812164846.2236221-1-gitster@pobox.com>
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 19 in “completion of 'git [-C <dir>] checkout'”
  1. 0/2 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 11, 2026
  2. 1/2 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 11, 2026
  3. 2/2 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 11, 2026
  4. Ben KnobleAug 11, 2026
  5. Junio C HamanoAug 11, 2026
  6. Junio C HamanoAug 11, 2026
  7. Ben KnobleAug 11, 2026
  8. Junio C HamanoAug 12, 2026
  9. 0/3 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 12, 2026
  10. 1/3 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 12, 2026
  11. 2/3 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 12, 2026
  12. 3/3 completion: 'git checkout' completes untracked paths as a last resortJunio C Hamano, Aug 12, 2026
  13. Elijah NewrenAug 12, 2026
  14. Junio C HamanoAug 12, 2026
  15. 0/3 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 13, 2026
  16. 1/3 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 13, 2026
  17. 2/3 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 13, 2026
  18. 3/3 completion: 'git checkout' completes untracked paths as a last resortJunio C Hamano, Aug 13, 2026
  19. Elijah NewrenAug 14, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.