]> git.neil.brown.name Git - git.git/commitdiff
discover_git_directory(): avoid setting invalid git_dir
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 14 Jun 2017 11:35:26 +0000 (13:35 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Jun 2017 19:31:43 +0000 (12:31 -0700)
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>
setup.c

diff --git a/setup.c b/setup.c
index 0309c278218f96cb6b11e6a9d60011efce54cf62..ba3241bf026e87414d8f652c59fef0d120c92c19 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -977,6 +977,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;
        }