Skip to content

Commit

Permalink
Merge branch 'config-wo-repo'
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho committed Feb 24, 2016
2 parents bc859c8 + 041cc8c commit 64acc33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions builtin/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 0 additions & 4 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,10 +1951,6 @@ static int lock_config_file(const char *config_filename,
{
int fd;

/* make sure the parent directory exists */
if (safe_create_leading_directories_const(config_filename))
return error("could not create parent directory of %s",
config_filename);
*result = xcalloc(1, sizeof(struct lock_file));
fd = hold_lock_file_for_update(*result, config_filename, 0);
if (fd < 0)
Expand Down
9 changes: 9 additions & 0 deletions t/t1308-config-set.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,13 @@ 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

0 comments on commit 64acc33

Please sign in to comment.