Merge branch 'js/config-set-in-non-repository'
authorJunio C Hamano <gitster@pobox.com>
Fri, 26 Feb 2016 21:37:26 +0000 (13:37 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Feb 2016 21:37:26 +0000 (13:37 -0800)
"git config section.var value" to set a value in per-repository
configuration file failed when it was run outside any repository,
but didn't say the reason correctly.

* js/config-set-in-non-repository:
git config: report when trying to modify a non-existing repo config

builtin/config.c
t/t1308-config-set.sh
index 8602b216d876e5f68c725bd004350d8bdfe819a5..ca9f834ae648177a67e1c9fea9481dfe58ff3972 100644 (file)
@@ -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");
 
index 82f82a16d961486b7a8f3d68229436393baa64e3..005d66dbef6c361363752b37087bbbc6a3098833 100755 (executable)
@@ -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