diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 54ce58f73d..6662db221d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -148,7 +148,7 @@ __git_pseudoref_exists () # platforms. if __git_eread "$__git_repo_path/HEAD" head; then if [ "$head" == "ref: refs/heads/.invalid" ]; then - __git rev-parse --verify --quiet "$ref" >/dev/null + __git show-ref --exists "$ref" return $? fi fi diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 56dc7343a2..35eb534fdd 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2743,6 +2743,10 @@ test_expect_success '__git_pseudoref_exists' ' cd repo && sane_unset __git_repo_path && + # HEAD should exist, even if it points to an unborn branch. + __git_pseudoref_exists HEAD >output 2>&1 && + test_must_be_empty output && + # HEAD points to an existing branch, so it should exist. test_commit A && __git_pseudoref_exists HEAD >output 2>&1 &&