git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git config: do not create .git/ if it does not exist yet

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 24, 2016, 07:47 UTC
Message-ID
<c4027d758b0914dbc2e1ff5df344b0669aac4447.1456299545.git.johannes.schindelin@gmx.de>

It is a pilot error to call `git config section.key value` outside of any Git worktree.

Let's report that error instead of creating the .git/ directory and writing a fresh config into it.

This addresses https://github.com/git-for-windows/git/issues/643 and https://groups.google.com/forum/#!topic/git-for-windows/fVRdnDIKVuw

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	I cannot think of a way how to test this: all of the regression
	tests run inside Git's own worktree, and we cannot even assume
	that /tmp/ is outside of a worktree (or that it exists).
 builtin/config.c | 3 +++
 1 file changed, 3 insertions(+)
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");
 
-- 
2.7.2.windows.1.2.gbc859c8
Next: Jeff King
Message 1 of 16 in “git config: do not create .git/ if it does not exist yet”
  1. git config: do not create .git/ if it does not exist yetJohannes Schindelin, Feb 24, 2016
  2. Jeff KingFeb 24, 2016
  3. John KeepingFeb 24, 2016
  4. Jeff KingFeb 24, 2016
  5. Johannes SchindelinFeb 24, 2016
  6. Johannes SchindelinFeb 24, 2016
  7. Jeff KingFeb 24, 2016
  8. Junio C HamanoFeb 24, 2016
  9. Duy NguyenFeb 24, 2016
  10. git config: report when trying to modify a non-existing repo configJohannes Schindelin, Feb 24, 2016
  11. Duy NguyenFeb 24, 2016
  12. Johannes SchindelinFeb 24, 2016
  13. Duy NguyenFeb 24, 2016
  14. Junio C HamanoFeb 24, 2016
  15. Junio C HamanoFeb 24, 2016
  16. Johannes SchindelinFeb 25, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.