Skip to content

Commit a2f03b0

Browse files
szedergitster
authored andcommitted
completion: ensure that the repository path given on the command line exists
The __gitdir() helper function prints the path to the git repository to its stdout or 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 via 'git --git-dir=<path>', doesn't exist: __gitdir() still outputs it as if it were a real existing repository, making some completion functions believe that they operate on an existing repository. Check that the path in $__git_dir exists and return with error without printing anything to stdout if it doesn't. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb9cd42 commit a2f03b0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

contrib/completion/git-completion.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ __gitdir ()
4040
{
4141
if [ -z "${1-}" ]; then
4242
if [ -n "${__git_dir-}" ]; then
43+
test -d "$__git_dir" || return 1
4344
echo "$__git_dir"
4445
elif [ -n "${GIT_DIR-}" ]; then
4546
test -d "${GIT_DIR-}" || return 1

t/t9902-completion.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' '
211211
test_cmp expected "$actual"
212212
'
213213

214+
test_expect_success '__gitdir - non-existing path in $__git_dir' '
215+
(
216+
__git_dir="non-existing" &&
217+
test_must_fail __gitdir >"$actual"
218+
) &&
219+
test_must_be_empty "$actual"
220+
'
221+
214222
test_expect_success '__gitdir - non-existing $GIT_DIR' '
215223
(
216224
GIT_DIR="$ROOT/non-existing" &&

0 commit comments

Comments
 (0)