git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Brandon Williams <bmwill@google.com>
Subject: [PATCH v4 1/6] discover_git_directory(): avoid setting invalid git_dir
Date: Wed, 14 Jun 2017 13:35:26 +0200 (CEST)	[thread overview]
Message-ID: <77bc4209b6e1e782dca367c7b3b2500e0cb655d0.1497440104.git.johannes.schindelin@gmx.de> (raw)
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



  reply	other threads:[~2017-06-14 11:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-14 11:35 [PATCH v4 0/6] Avoid problem where git_dir is set after alias expansion Johannes Schindelin
2017-06-14 11:35 ` Johannes Schindelin [this message]
2017-06-14 11:35 ` [PATCH v4 2/6] config: report correct line number upon error Johannes Schindelin
2017-06-14 11:35 ` [PATCH v4 3/6] help: use early config when autocorrecting aliases Johannes Schindelin
2017-06-14 11:35 ` [PATCH v4 4/6] t1308: relax the test verifying that empty alias values are disallowed Johannes Schindelin
2017-06-14 11:35 ` [PATCH v4 5/6] t7006: demonstrate a problem with aliases in subdirectories Johannes Schindelin
2017-06-14 11:36 ` [PATCH v4 6/6] Use the early config machinery to expand aliases Johannes Schindelin
2017-06-15 19:36   ` Junio C Hamano
2017-06-15 19:44     ` Johannes Schindelin
2017-06-15  6:37 ` [PATCH v4 0/6] Avoid problem where git_dir is set after alias expansion Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=77bc4209b6e1e782dca367c7b3b2500e0cb655d0.1497440104.git.johannes.schindelin@gmx.de \
    --to=johannes.schindelin@gmx.de \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).