diff options
author | SZEDER Gábor <szeder@ira.uka.de> | 2016-02-25 23:50:36 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-02-28 16:37:15 -0800 |
commit | b3e189d0bef0aa4fa03d2a277f7b902415adbc4e (patch) | |
tree | b89352c9e7deb1ee54e9a9104a95fbc91ebba993 | |
parent | 70f17430721f587b9fcd1b6b3f26a859a30b4680 (diff) | |
download | git-b3e189d0bef0aa4fa03d2a277f7b902415adbc4e.tar.gz |
completion: ensure that the repository path given on the command line exists
The __gitdir() helper function stays silent and returns with error
when it can't find a repository or when the repository given via
$GIT_DIR doesn't exist.
This is not the case, however, when the path in $__git_dir, i.e. the
path to the repository specified on the command line as 'git
--git-dir=<path>', doesn't exist: __gitdir() still outputs it and
returns with success, making completion functions believe that they
operate on an existing repository.
Check that the path in $__git_dir exists and return with error if it
doesn't.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | contrib/completion/git-completion.bash | 1 | ||||
-rwxr-xr-x | t/t9902-completion.sh | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0e1fd778bf..0ec988c0ee 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -40,6 +40,7 @@ __gitdir () { if [ -z "${1-}" ]; then if [ -n "${__git_dir-}" ]; then + test -d "$__git_dir" || return 1 echo "$__git_dir" elif [ -n "${GIT_DIR-}" ]; then test -d "${GIT_DIR-}" || return 1 diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 7ab3985685..8098561102 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -211,6 +211,14 @@ test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' ' test_cmp expected "$actual" ' +test_expect_success '__gitdir - non-existing path in $__git_dir' ' + ( + __git_dir="non-existing" && + test_must_fail __gitdir >"$actual" + ) && + test_must_be_empty "$actual" +' + test_expect_success '__gitdir - non-existing $GIT_DIR' ' ( GIT_DIR="$ROOT/non-existing" && |