aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/completion/git-completion.bash3
-rwxr-xr-xt/t9903-bash-prompt.sh10
2 files changed, 12 insertions, 1 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index efcd875f9..5d70cc428 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -41,6 +41,9 @@ __gitdir ()
if [ -z "${1-}" ]; then
if [ -n "${__git_dir-}" ]; then
echo "$__git_dir"
+ elif [ -n "${GIT_DIR-}" ]; then
+ test -d "${GIT_DIR-}" || return 1
+ echo "$GIT_DIR"
elif [ -d .git ]; then
echo .git
else
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index f8fb93f68..f17c1f8b8 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -85,7 +85,7 @@ test_expect_success 'gitdir - parent is a .git directory' '
test_cmp expected "$actual"
'
-test_expect_failure 'gitdir - $GIT_DIR set while .git directory in cwd' '
+test_expect_success 'gitdir - $GIT_DIR set while .git directory in cwd' '
echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
(
GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
@@ -106,6 +106,14 @@ test_expect_success 'gitdir - $GIT_DIR set while .git directory in parent' '
test_cmp expected "$actual"
'
+test_expect_success 'gitdir - non-existing $GIT_DIR' '
+ (
+ GIT_DIR="$TRASH_DIRECTORY/non-existing" &&
+ export GIT_DIR &&
+ test_must_fail __gitdir
+ )
+'
+
test_expect_success 'gitdir - gitfile in cwd' '
echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" > subdir/.git &&