Skip to content

Commit 6486ca6

Browse files
szedergitster
authored andcommitted
completion: remove broken dead code from __git_heads() and __git_tags()
__git_heads() was introduced in 5de40f5 (Teach bash about git-repo-config., 2006-11-27), and __git_tags() in 88e21dc (Teach bash about completing arguments for git-tag, 2007-08-31). As their name suggests, __git_heads() is supposed to list only branches, and __git_tags() only tags. Since their introduction both of these functions consist of two distinct parts. The first part gets branches or tags, respectively, from a local repositoty using 'git for-each-ref'. The second part queries a remote repository given as argument using 'git ls-remote'. These remote-querying parts are broken in both functions since their introduction, because they list both branches and tags from the remote repository. (The 'git ls-remote' query is not limited to list only heads or tags, respectively, and the for loop filtering the query results prints everything except dereferenced tags.) This breakage could be easily fixed by passing the '--heads' or '--tags' options or appropriate refs patterns to the 'git ls-remote' invocations. However, that no one noticed this breakage yet is probably not a coincidence: neither of these two functions were used to query a remote repository, the remote-querying parts were dead code already upon thier introduction and remained dead ever since. Since those parts of code are broken, are and were never used, stop the bit-rotting and remove them. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d51a8ec commit 6486ca6

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -537,42 +537,24 @@ __gitcomp_nl ()
537537
COMPREPLY=($(compgen -P "${2-}" -S "$suffix" -W "$1" -- "$cur_"))
538538
}
539539

540-
# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
541540
__git_heads ()
542541
{
543-
local cmd i is_hash=y dir="$(__gitdir "${1-}")"
542+
local dir="$(__gitdir)"
544543
if [ -d "$dir" ]; then
545544
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
546545
refs/heads
547546
return
548547
fi
549-
for i in $(git ls-remote "${1-}" 2>/dev/null); do
550-
case "$is_hash,$i" in
551-
y,*) is_hash=n ;;
552-
n,*^{}) is_hash=y ;;
553-
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
554-
n,*) is_hash=y; echo "$i" ;;
555-
esac
556-
done
557548
}
558549

559-
# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
560550
__git_tags ()
561551
{
562-
local cmd i is_hash=y dir="$(__gitdir "${1-}")"
552+
local dir="$(__gitdir)"
563553
if [ -d "$dir" ]; then
564554
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
565555
refs/tags
566556
return
567557
fi
568-
for i in $(git ls-remote "${1-}" 2>/dev/null); do
569-
case "$is_hash,$i" in
570-
y,*) is_hash=n ;;
571-
n,*^{}) is_hash=y ;;
572-
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
573-
n,*) is_hash=y; echo "$i" ;;
574-
esac
575-
done
576558
}
577559

578560
# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments

0 commit comments

Comments
 (0)