Skip to content

Commit

Permalink
git config: report when trying to modify a non-existing repo config
Browse files Browse the repository at this point in the history
It is a pilot error to call `git config section.key value` outside of
any Git worktree. The message

	error: could not lock config file .git/config: No such file or
	directory

is not very helpful in that situation, though. Let's print a helpful
message instead.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Feb 25, 2016
1 parent 326e5bc commit 638fa62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 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
11 changes: 11 additions & 0 deletions t/t1308-config-set.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,15 @@ 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 638fa62

Please sign in to comment.