If no repository is found, do not bother calling git_pathdup(). If a
command forgets to call setup_git_directory*() or enter_repo(),
$GIT_DIR/config will be missed, though.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
config.c | 3 ++-
t/t1300-repo-config.sh | 13 +++++++++++++
2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/config.c b/config.c
index 2d38096..07d854a 100644
--- a/config.c
+++ b/config.c
@@ -737,7 +737,8 @@ int git_config(config_fn_t fn, void *data)
char *repo_config = NULL;
int ret;
- repo_config = git_pathdup("config");
+ if (!startup_info || startup_info->have_repository)
+ repo_config = git_pathdup("config");
ret = git_config_early(fn, data, repo_config);
if (repo_config)
free(repo_config);diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index f11f98c..cfb70e2 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -824,4 +824,17 @@ test_expect_success 'check split_cmdline return' "
test_must_fail git merge master
"
+test_expect_success 'skip .git/config if there is no repository' '
+ (
+ mkdir -p a/b/.git &&
+ cd a &&
+ GIT_CEILING_DIRECTORIES="`pwd`" &&
+ export GIT_CEILING_DIRECTORIES &&
+ cd b &&
+ echo "[core]" > .git/config &&
+ echo "wrong = true" >> .git/config &&
+ test -z "$(git var -l | grep core.wrong)"
+ )
+'
+
test_done
--
1.7.0.1.384.g6abcaa