Skip to content

Commit 64acc33

Browse files
committed
Merge branch 'config-wo-repo'
This branch contains fixes that let `git config` report appropriately when the user tries to modify a repository config outside of any Git worktree. These changes were triggered by the bug report at #643 Signed-off-by: Johannes Schindelin <[email protected]>
2 parents bc859c8 + 041cc8c commit 64acc33

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
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

config.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,10 +1951,6 @@ static int lock_config_file(const char *config_filename,
19511951
{
19521952
int fd;
19531953

1954-
/* make sure the parent directory exists */
1955-
if (safe_create_leading_directories_const(config_filename))
1956-
return error("could not create parent directory of %s",
1957-
config_filename);
19581954
*result = xcalloc(1, sizeof(struct lock_file));
19591955
fd = hold_lock_file_for_update(*result, config_filename, 0);
19601956
if (fd < 0)

t/t1308-config-set.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,13 @@ 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+
GIT_CEILING_DIRECTORIES=$(pwd) &&
224+
export GIT_CEILING_DIRECTORIES &&
225+
cd no-repo &&
226+
test_must_fail git config a.b c 2>err &&
227+
grep "not in a git directory" err
228+
'
229+
221230
test_done

0 commit comments

Comments
 (0)