diff options
-rw-r--r-- | builtin/config.c | 3 | ||||
-rwxr-xr-x | t/t1308-config-set.sh | 11 |
2 files changed, 14 insertions, 0 deletions
diff --git a/builtin/config.c b/builtin/config.c index 8602b216d..ca9f834ae 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -377,6 +377,9 @@ static int get_colorbool(const char *var, int print) static void check_write(void) { + if (!given_config_source.file && !startup_info->have_repository) + die("not in a git directory"); + if (given_config_source.use_stdin) die("writing to stdin is not supported"); diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index 82f82a16d..005d66dbe 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -218,4 +218,15 @@ test_expect_success 'check line errors for malformed values' ' test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result ' +test_expect_success 'error on modifying repo config without repo' ' + mkdir no-repo && + ( + GIT_CEILING_DIRECTORIES=$(pwd) && + export GIT_CEILING_DIRECTORIES && + cd no-repo && + test_must_fail git config a.b c 2>err && + grep "not in a git directory" err + ) +' + test_done |