Merge branch 'js/config-set-in-non-repository' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 10 Mar 2016 19:13:45 +0000 (11:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Mar 2016 19:13:45 +0000 (11:13 -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 c26d6e7fdd5d2896850ac909cb9ce04960520b0d..746233e4bbaffc6d7f2d4d1849bd89cd13286d02 100644 (file)
@@ -352,6 +352,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 91235b76ba76f7e7e9338e37da7106eb550969e6..9863d0d0ed7e07457f5f541897ac3959df9c9aa7 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