Skip to content

Commit 69743f9

Browse files
dschogitster
authored andcommitted
discover_git_directory(): avoid setting invalid git_dir
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> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b06d364 commit 69743f9

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

setup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ const char *discover_git_directory(struct strbuf *gitdir)
977977
warning("ignoring git dir '%s': %s",
978978
gitdir->buf + gitdir_offset, err.buf);
979979
strbuf_release(&err);
980+
strbuf_setlen(gitdir, gitdir_offset);
980981
return NULL;
981982
}
982983

0 commit comments

Comments
 (0)