Skip to content

Commit 0e58b47

Browse files
committed
Merge branch 'js/config-set-in-non-repository' into maint
"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
2 parents 1191d60 + 638fa62 commit 0e58b47

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

builtin/config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ static int get_colorbool(const char *var, int print)
352352

353353
static void check_write(void)
354354
{
355+
if (!given_config_source.file && !startup_info->have_repository)
356+
die("not in a git directory");
357+
355358
if (given_config_source.use_stdin)
356359
die("writing to stdin is not supported");
357360

t/t1308-config-set.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,15 @@ test_expect_success 'check line errors for malformed values' '
218218
test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result
219219
'
220220

221+
test_expect_success 'error on modifying repo config without repo' '
222+
mkdir no-repo &&
223+
(
224+
GIT_CEILING_DIRECTORIES=$(pwd) &&
225+
export GIT_CEILING_DIRECTORIES &&
226+
cd no-repo &&
227+
test_must_fail git config a.b c 2>err &&
228+
grep "not in a git directory" err
229+
)
230+
'
231+
221232
test_done

0 commit comments

Comments
 (0)