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

	https://github.com/git-for-windows/git/issues/643

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2016-02-24 13:14:59 +01:00
3 changed files with 12 additions and 4 deletions

View 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");

View File

@@ -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)

View File

@@ -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