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

[PATCH v4 1/6] discover_git_directory(): avoid setting invalid git_dir

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 14, 2017, 11:35 UTC
Message-ID
<77bc4209b6e1e782dca367c7b3b2500e0cb655d0.1497440104.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1497440104.git.johannes.schindelin@gmx.de>

When discovering a .git/ directory, we take pains to ensure that its repository format version matches Git's expectations, and we return NULL otherwise.

However, we still appended the invalid path to the strbuf passed as argument.

Let's just reset the strbuf to the state before we appended the .git/ directory that was eventually rejected.

There is another early return path in that function, when setup_git_directory_gently_1() returns GIT_DIR_NONE or an error. In that case, the gitdir parameter has not been touched, therefore there is no need for an equivalent change in that code path.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 setup.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/setup.c b/setup.c
index ba6e8551788..ad12d79ac02 100644
--- a/setup.c
+++ b/setup.c
@@ -982,6 +982,7 @@ const char *discover_git_directory(struct strbuf *gitdir)
 		warning("ignoring git dir '%s': %s",
 			gitdir->buf + gitdir_offset, err.buf);
 		strbuf_release(&err);
+		strbuf_setlen(gitdir, gitdir_offset);
 		return NULL;
 	}
 
-- 
2.13.1.windows.1.1.ga36e14b3aaa
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 2 of 10 in “Avoid problem where git_dir is set after alias expansion”
  1. 0/6 Avoid problem where git_dir is set after alias expansionJohannes Schindelin, Jun 14, 2017
  2. 1/6 discover_git_directory(): avoid setting invalid git_dirJohannes Schindelin, Jun 14, 2017
  3. 3/6 help: use early config when autocorrecting aliasesJohannes Schindelin, Jun 14, 2017
  4. 4/6 t1308: relax the test verifying that empty alias values are disallowedJohannes Schindelin, Jun 14, 2017
  5. 2/6 config: report correct line number upon errorJohannes Schindelin, Jun 14, 2017
  6. 5/6 t7006: demonstrate a problem with aliases in subdirectoriesJohannes Schindelin, Jun 14, 2017
  7. 6/6 Use the early config machinery to expand aliasesJohannes Schindelin, Jun 14, 2017
  8. Junio C HamanoJun 15, 2017
  9. Johannes SchindelinJun 15, 2017
  10. Jeff KingJun 15, 2017

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.