Skip to content

Commit 3ad8ea7

Browse files
szedergitster
authored andcommitted
completion: don't disambiguate tags and branches
When the completion script has to list only tags or only branches, it uses the 'git for-each-ref' format 'refname:short', which makes sure that all listed tags and branches are unambiguous. However, disambiguating tags and branches in these cases is wrong, because: - __git_tags(), the helper function listing possible tagname arguments for 'git tag', lists an ambiguous tag 'refs/tags/ambiguous' as 'tags/ambiguous'. Its only consumer, 'git tag' expects its tagname argument to be under 'refs/tags/', thus it interprets that abgiguous tag as 'refs/tags/tags/ambiguous'. Clearly wrong. - __git_heads() lists possible branchname arguments for 'git branch' and possible 'branch.<branchname>' configuration subsections. Both of these expect branchnames to be under 'refs/heads/' and misinterpret a disambiguated branchname like 'heads/ambiguous'. Furthermore, disambiguation involves several stat() syscalls for each tag or branch, thus comes at a steep cost especially on Windows and/or when there are a lot of tags or branches to be listed. Use the 'git for-each-ref' format 'refname:strip=2' instead of 'refname:short' to avoid harmful disambiguation of tags and branches in __git_tags() and __git_heads(). Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent aed3881 commit 3ad8ea7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,12 @@ __git_index_files ()
340340

341341
__git_heads ()
342342
{
343-
__git for-each-ref --format='%(refname:short)' refs/heads
343+
__git for-each-ref --format='%(refname:strip=2)' refs/heads
344344
}
345345

346346
__git_tags ()
347347
{
348-
__git for-each-ref --format='%(refname:short)' refs/tags
348+
__git for-each-ref --format='%(refname:strip=2)' refs/tags
349349
}
350350

351351
# Lists refs from the local (by default) or from a remote repository.

0 commit comments

Comments
 (0)