Skip to content

Commit d3faba8

Browse files
committed
Merge branch 'js/config-set-in-non-repository'
"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 8ef250c + 638fa62 commit d3faba8

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
@@ -377,6 +377,9 @@ static int get_colorbool(const char *var, int print)
377377

378378
static void check_write(void)
379379
{
380+
if (!given_config_source.file && !startup_info->have_repository)
381+
die("not in a git directory");
382+
380383
if (given_config_source.use_stdin)
381384
die("writing to stdin is not supported");
382385

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)