# [PATCH] setup: avoid double slashes when looking for HEAD

2 messages from 2017-11-03 to 2017-11-03. Participants: Johannes Schindelin, Jeff King.
Thread: https://gitlist.dev/t/47109

## Johannes Schindelin, 2017-11-03 12:58

Subject: [PATCH] setup: avoid double slashes when looking for HEAD
Message-ID: <9322728aaa3010c0b71574eb5876548487d66885.1509713589.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/9322728aaa3010c0b71574eb5876548487d66885.1509713589.git.johannes.schindelin%40gmx.de

```
From: Jeff King <peff@peff.net>

Andrew Baumann reported that when called outside of any Git worktree,
`git rev-parse --is-inside-work-tree` eventually tries to access
`//HEAD`, i.e.  any `HEAD` file in the root directory, but with a double
slash.

This double slash is not only unintentional, but is allowed by the POSIX
standard to have a special meaning. And most notably on Windows, it
does, where it refers to a UNC path of the form `//server/share/`.

As a consequence, afore-mentioned `rev-parse` call not only looks for
the wrong thing, but it also causes serious delays, as Windows will try
to access a server called `HEAD`.  Let's simply avoid the unintended
double slash.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Published-As: https://github.com/dscho/git/releases/tag/double-slash-HEAD-v1
Fetch-It-Via: git fetch https://github.com/dscho/git double-slash-HEAD-v1

	And here it is, as a proper, easy-to-pull branch, and also in the
	form Junio prefers.

 setup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/setup.c b/setup.c
index 03f51e056cd..94768512b79 100644
--- a/setup.c
+++ b/setup.c
@@ -312,7 +312,9 @@ int is_git_directory(const char *suspect)
 	size_t len;
 
 	/* Check worktree-related signatures */
-	strbuf_addf(&path, "%s/HEAD", suspect);
+	strbuf_addstr(&path, suspect);
+	strbuf_complete(&path, '/');
+	strbuf_addstr(&path, "HEAD");
 	if (validate_headref(path.buf))
 		goto done;
 

base-commit: cb5918aa0d50f50e83787f65c2ddc3dcb10159fe
-- 
2.15.0.windows.1

```

## Jeff King, 2017-11-03 18:38

Subject: Re: [PATCH] setup: avoid double slashes when looking for HEAD
Message-ID: <20171103183836.zpsspuj2xbufuu7u@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20171103183836.zpsspuj2xbufuu7u%40sigill.intra.peff.net
In-Reply-To: <9322728aaa3010c0b71574eb5876548487d66885.1509713589.git.johannes.schindelin@gmx.de>

```
On Fri, Nov 03, 2017 at 01:58:02PM +0100, Johannes Schindelin wrote:

> From: Jeff King <peff@peff.net>
> 
> Andrew Baumann reported that when called outside of any Git worktree,
> `git rev-parse --is-inside-work-tree` eventually tries to access
> `//HEAD`, i.e.  any `HEAD` file in the root directory, but with a double
> slash.
> 
> This double slash is not only unintentional, but is allowed by the POSIX
> standard to have a special meaning. And most notably on Windows, it
> does, where it refers to a UNC path of the form `//server/share/`.
> 
> As a consequence, afore-mentioned `rev-parse` call not only looks for
> the wrong thing, but it also causes serious delays, as Windows will try
> to access a server called `HEAD`.  Let's simply avoid the unintended
> double slash.
> 
> Signed-off-by: Jeff King <peff@peff.net>
> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>

Thanks, this explanation looks good to me (and the patch is flawless, of
course ;) ).

-Peff

```
