From 62a1b732160c363a84be310f801b5dec59196b9c Mon Sep 17 00:00:00 2001 From: =?utf8?q?SZEDER=20G=C3=A1bor?= Date: Fri, 3 Feb 2017 03:48:19 +0100 Subject: [PATCH] completion: don't list 'HEAD' when trying refs completion outside of a repo MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 8 ++++++-- t/t9902-completion.sh | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index af5ad52bb..19f60931b 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -346,7 +346,11 @@ __git_refs () local list_refs_from=path remote="${1-}" local format refs pfx - if [ -n "$remote" ]; then + if [ -z "$remote" ]; then + if [ -z "$dir" ]; then + return + fi + else if __git_is_configured_remote "$remote"; then # configured remote takes precedence over a # local directory with the same name @@ -360,7 +364,7 @@ __git_refs () fi fi - if [ "$list_refs_from" = path ] && [ -d "$dir" ]; then + if [ "$list_refs_from" = path ]; then case "$cur" in refs|refs/*) format="refname" diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index a201b5212..5b4defaa5 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -599,7 +599,7 @@ test_expect_success '__git_refs - non-existing URL remote - full refs' ' test_must_be_empty "$actual" ' -test_expect_failure '__git_refs - not in a git repository' ' +test_expect_success '__git_refs - not in a git repository' ' ( GIT_CEILING_DIRECTORIES="$ROOT" && export GIT_CEILING_DIRECTORIES && -- 2.11.0