Navigation Menu

Skip to content

Commit

Permalink
setup: avoid double slashes when looking for HEAD
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Nov 3, 2017
1 parent 5c4003c commit fa4d8c7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion setup.c
Expand Up @@ -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;

Expand Down

0 comments on commit fa4d8c7

Please sign in to comment.