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 <szeder.dev@gmail.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
6807d3942c
commit
7b9cda2d3d
|
@ -137,6 +137,7 @@ __git_eread ()
|
||||||
__git_pseudoref_exists ()
|
__git_pseudoref_exists ()
|
||||||
{
|
{
|
||||||
local ref=$1
|
local ref=$1
|
||||||
|
local head
|
||||||
|
|
||||||
__git_find_repo_path
|
__git_find_repo_path
|
||||||
|
|
||||||
|
@ -146,9 +147,8 @@ __git_pseudoref_exists ()
|
||||||
# Bash builtins since executing Git commands are expensive on some
|
# Bash builtins since executing Git commands are expensive on some
|
||||||
# platforms.
|
# platforms.
|
||||||
if __git_eread "$__git_repo_path/HEAD" head; then
|
if __git_eread "$__git_repo_path/HEAD" head; then
|
||||||
b="${head#ref: }"
|
if [ "$head" == "ref: refs/heads/.invalid" ]; then
|
||||||
if [ "$b" == "refs/heads/.invalid" ]; then
|
__git rev-parse --verify --quiet "$ref"
|
||||||
__git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" 2>/dev/null
|
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue