completion: don't list 'HEAD' when trying refs completion outside of a repo
authorSZEDER Gábor <szeder.dev@gmail.com>
Fri, 3 Feb 2017 02:48:19 +0000 (03:48 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 4 Feb 2017 06:18:40 +0000 (22:18 -0800)
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 <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
t/t9902-completion.sh
index af5ad52bb189273ed77072ba473ed0871992538a..19f60931b0cde2f60e502325da0b693ecb7cf96a 100644 (file)
@@ -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"
index a201b5212977e4d760494e33dc07486dee86d73c..5b4defaa5c6352c4791b4c38f523fbd06d2f74fc 100755 (executable)
@@ -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 &&