From: Jeff King Date: Fri, 3 Nov 2017 12:58:02 +0000 (+0100) Subject: setup: avoid double slashes when looking for HEAD X-Git-Tag: v2.15.1~26^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fa4d8c783d780191d98fe1f68ad2dea2fe78d19c;p=thirdparty%2Fgit.git setup: avoid double slashes when looking for HEAD 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 Acked-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff --git a/setup.c b/setup.c index 98b8dee8b8..600410777b 100644 --- a/setup.c +++ b/setup.c @@ -283,7 +283,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;