Skip to content

Commit 62a1b73

Browse files
szedergitster
authored andcommitted
completion: don't list 'HEAD' when trying refs completion outside of a repo
When refs completion is attempted while not in a git repository, the completion script offers 'HEAD' erroneously. Check early in __git_refs() that there is either a repository or a remote to work on, and return early if neither is given. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69a7759 commit 62a1b73

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

contrib/completion/git-completion.bash

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,11 @@ __git_refs ()
346346
local list_refs_from=path remote="${1-}"
347347
local format refs pfx
348348

349-
if [ -n "$remote" ]; then
349+
if [ -z "$remote" ]; then
350+
if [ -z "$dir" ]; then
351+
return
352+
fi
353+
else
350354
if __git_is_configured_remote "$remote"; then
351355
# configured remote takes precedence over a
352356
# local directory with the same name
@@ -360,7 +364,7 @@ __git_refs ()
360364
fi
361365
fi
362366

363-
if [ "$list_refs_from" = path ] && [ -d "$dir" ]; then
367+
if [ "$list_refs_from" = path ]; then
364368
case "$cur" in
365369
refs|refs/*)
366370
format="refname"

t/t9902-completion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ test_expect_success '__git_refs - non-existing URL remote - full refs' '
599599
test_must_be_empty "$actual"
600600
'
601601

602-
test_expect_failure '__git_refs - not in a git repository' '
602+
test_expect_success '__git_refs - not in a git repository' '
603603
(
604604
GIT_CEILING_DIRECTORIES="$ROOT" &&
605605
export GIT_CEILING_DIRECTORIES &&

0 commit comments

Comments
 (0)