summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache.h6
-rw-r--r--config.c2
-rw-r--r--environment.c7
-rwxr-xr-xt/t0001-init.sh9
-rwxr-xr-xt/t1301-shared-repo.sh9
-rwxr-xr-xt/t1302-repo-version.sh4
6 files changed, 33 insertions, 4 deletions
diff --git a/cache.h b/cache.h
index 5e50887d63..67ec356c7a 100644
--- a/cache.h
+++ b/cache.h
@@ -453,6 +453,12 @@ static inline enum object_type object_type(unsigned int mode)
*/
extern const char * const local_repo_env[];
+/*
+ * Returns true iff we have a configured git repository (either via
+ * setup_git_directory, or in the environment via $GIT_DIR).
+ */
+int have_git_dir(void);
+
extern int is_bare_repository_cfg;
extern int is_bare_repository(void);
extern int is_inside_git_dir(void);
diff --git a/config.c b/config.c
index 1d2331aa08..5e50fb1a31 100644
--- a/config.c
+++ b/config.c
@@ -1194,7 +1194,7 @@ static int do_git_config_sequence(config_fn_t fn, void *data)
int ret = 0, found = 0;
char *xdg_config = xdg_config_home("config");
char *user_config = expand_user_path("~/.gitconfig");
- char *repo_config = git_pathdup("config");
+ char *repo_config = have_git_dir() ? git_pathdup("config") : NULL;
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
ret += git_config_from_file(fn, git_etc_gitconfig(),
diff --git a/environment.c b/environment.c
index bccdee9d0b..20a870c3d7 100644
--- a/environment.c
+++ b/environment.c
@@ -194,6 +194,13 @@ int is_bare_repository(void)
return is_bare_repository_cfg && !get_git_work_tree();
}
+int have_git_dir(void)
+{
+ return startup_info->have_repository
+ || git_dir
+ || getenv(GIT_DIR_ENVIRONMENT);
+}
+
const char *get_git_dir(void)
{
if (!git_dir)
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index a6fdd5ef3a..8ffbbea4d6 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -384,4 +384,13 @@ test_expect_success MINGW 'bare git dir not hidden' '
! is_hidden newdir
'
+test_expect_success 'remote init from does not use config from cwd' '
+ rm -rf newdir &&
+ test_config core.logallrefupdates true &&
+ git init newdir &&
+ echo true >expect &&
+ git -C newdir config --bool core.logallrefupdates >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index ac10875408..7c28642f2e 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -172,4 +172,13 @@ test_expect_success POSIXPERM 'forced modes' '
}" actual)"
'
+test_expect_success POSIXPERM 'remote init does not use config from cwd' '
+ git config core.sharedrepository 0666 &&
+ umask 0022 &&
+ git init --bare child.git &&
+ echo "-rw-r--r--" >expect &&
+ modebits child.git/config >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index f859809b36..ce4cff13bb 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -32,9 +32,7 @@ test_expect_success 'gitdir selection on normal repos' '
test_expect_success 'gitdir selection on unsupported repo' '
# Make sure it would stop at test2, not trash
- echo 99 >expect &&
- git -C test2 config core.repositoryformatversion >actual &&
- test_cmp expect actual
+ test_expect_code 1 git -C test2 config core.repositoryformatversion >actual
'
test_expect_success 'gitdir not required mode' '