Skip to content

Commit 020e0a0

Browse files
pks-tgitster
authored andcommitted
completion: treat dangling symrefs as existing pseudorefs
The `__git_pseudoref_exists ()` helper function back to git-rev-parse(1) in case the reftable backend is in use. This is not in the same spirit as the simple existence check that the "files" backend does though, because there we only check for the pseudo-ref to exist with `test -f`. With git-rev-parse(1) we not only check for existence, but also verify that the pseudo-ref resolves to an object, which may not be the case when the pseudo-ref points to an unborn branch. Fix this issue by using `git show-ref --exists` instead. Note that we do not have to silence stdout anymore as git-show-ref(1) will not print anything. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a9c311 commit 020e0a0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ __git_pseudoref_exists ()
148148
# platforms.
149149
if __git_eread "$__git_repo_path/HEAD" head; then
150150
if [ "$head" == "ref: refs/heads/.invalid" ]; then
151-
__git rev-parse --verify --quiet "$ref" >/dev/null
151+
__git show-ref --exists "$ref"
152152
return $?
153153
fi
154154
fi

t/t9902-completion.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,10 @@ test_expect_success '__git_pseudoref_exists' '
27432743
cd repo &&
27442744
sane_unset __git_repo_path &&
27452745
2746+
# HEAD should exist, even if it points to an unborn branch.
2747+
__git_pseudoref_exists HEAD >output 2>&1 &&
2748+
test_must_be_empty output &&
2749+
27462750
# HEAD points to an existing branch, so it should exist.
27472751
test_commit A &&
27482752
__git_pseudoref_exists HEAD >output 2>&1 &&

0 commit comments

Comments
 (0)