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 exit early if neither is given.

Signed-off-by: SZEDER Gábor <[email protected]>
---
 contrib/completion/git-completion.bash | 4 ++++
 t/t9902-completion.sh                  | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index b85ab27fb18a..f6ccfb708451 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -346,6 +346,10 @@ __git_refs ()
        local from_local=y remote="${1-}"
        local format refs
 
+       if [ -z "$dir" ] && [ -z "$remote" ]; then
+               return
+       fi
+
        if [ -n "$remote" ]; then
                if __git_is_configured_remote "$remote"; then
                        # configured remote takes precedence over a
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 9f8be9ab1f3b..f42a9ba9058f 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -629,7 +629,7 @@ test_expect_success '__git_refs - unique remote branches 
for git checkout DWIMer
        test_cmp expected "$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.7.2.410.g92cb358

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to