Skip to content

Commit 7b9cda2

Browse files
pks-tgitster
authored andcommitted
completion: improve existence check for pseudo-refs
Improve the existence check along the following lines: - Stop stripping the "ref :" prefix and compare to the expected value directly. This allows us to drop a now-unused variable that was previously leaking into the user's shell. - Mark the "head" variable as local so that we don't leak its value into the user's shell. - Stop manually handling the `-C $__git_repo_path` option, which the `__git ()` wrapper aleady does for us. - In simlar spirit, stop redirecting stderr, which is also handled by the wrapper already. Suggested-by: SZEDER Gábor <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6807d39 commit 7b9cda2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

contrib/completion/git-completion.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ __git_eread ()
137137
__git_pseudoref_exists ()
138138
{
139139
local ref=$1
140+
local head
140141

141142
__git_find_repo_path
142143

@@ -146,9 +147,8 @@ __git_pseudoref_exists ()
146147
# Bash builtins since executing Git commands are expensive on some
147148
# platforms.
148149
if __git_eread "$__git_repo_path/HEAD" head; then
149-
b="${head#ref: }"
150-
if [ "$b" == "refs/heads/.invalid" ]; then
151-
__git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" 2>/dev/null
150+
if [ "$head" == "ref: refs/heads/.invalid" ]; then
151+
__git rev-parse --verify --quiet "$ref"
152152
return $?
153153
fi
154154
fi

0 commit comments

Comments
 (0)