Skip to content

Commit fa4d8c7

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c4003c commit fa4d8c7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

setup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ int is_git_directory(const char *suspect)
283283
size_t len;
284284

285285
/* Check worktree-related signatures */
286-
strbuf_addf(&path, "%s/HEAD", suspect);
286+
strbuf_addstr(&path, suspect);
287+
strbuf_complete(&path, '/');
288+
strbuf_addstr(&path, "HEAD");
287289
if (validate_headref(path.buf))
288290
goto done;
289291

0 commit comments

Comments
 (0)