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 <[email protected]>
---
builtin/config.c | 3 +++
t/t1308-config-set.sh | 9 +++++++++
2 files changed, 12 insertions(+)
The commit message was adjusted to reflect that this is not a bug fix
(except for Git for Windows), and a test was added.
Interdiff vs v1:
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index 91235b7..f62409e 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -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
diff --git a/builtin/config.c b/builtin/config.c
index adc7727..78aab95 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -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");
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index 91235b7..f62409e 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -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
--
2.7.2.windows.1.2.gbc859c8
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html