completion: silence "fatal: Not a git repository" error
authorJohn Szakmeister <john@szakmeister.net>
Tue, 14 Oct 2014 10:49:45 +0000 (06:49 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Oct 2014 20:06:13 +0000 (13:06 -0700)
It is possible that a user is trying to run a git command and fail
to realize that they are not in a git repository or working tree.
When trying to complete an operation, __git_refs would fall to a
degenerate case and attempt to use "git for-each-ref", which would
emit the error.

Hide this error message coming from "git for-each-ref".

Signed-off-by: John Szakmeister <john@szakmeister.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
index 2ed230a861248f510e8e9d4597faef6f14ffd552..80e422f9d933307cac43572828c49de6feb0e03e 100644 (file)
@@ -388,7 +388,8 @@ __git_refs ()
                ;;
        *)
                echo "HEAD"
-               git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
+               git for-each-ref --format="%(refname:short)" -- \
+                       "refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
                ;;
        esac
 }