问题
I have a fancy shell prompt that executes git rev-parse --is-inside-work-tree
to determine whether we're currently inside a working directory. This causes git to walk up the directory hierarchy looking for a containing git repo. For example, when invoked from my home directory, it stats the following paths, in order:
/home/me/.git
/home/me/.git/HEAD
/home/me/HEAD
/home
/home/.git
/home/.git/HEAD
/home/HEAD
/
/.git
/.git/HEAD
//HEAD
The last name (//HEAD
) interacts badly with Cygwin, which interprets it as a UNC file share, and so demand-loads a bunch of extra DLLs and attempts to resolve/contact the server named HEAD
. This obviously doesn't work too well, especially over a slow network link.
This smells like a bug in git, albeit one that's probably harmless on platforms without the strange interpretation of //, so I'm looking for a workaround.
I've tested with the latest Cygwin git (2.15.0); this was also present in a prior version.
回答1:
git tries to stat
//HEAD
It has indeed been fixed in upstream, for Git 2.15.x/2.16 (Q1 2018), and it corrects the start-up sequence so that a repository could be placed immediately under the root directory again (which was broken at around Git 2.13).
See commit fa4d8c7 (03 Nov 2017) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 57dd3dd, 09 Nov 2017)
setup
: avoid double slashes when looking forHEAD
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. anyHEAD
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 calledHEAD
.
Let's simply avoid the unintended double slash.
回答2:
Cygwin doesn't seem to have any way of turning off the UNC path support, but you can shortcut the search by setting GIT_CEILING_DIRECTORIES
in your environment. My .zshenv
has:
export GIT_CEILING_DIRECTORIES=/:$HOME
Which terminates any search at / (avoiding //HEAD) but also at $HOME, since I know it's not inside a repo.
回答3:
This looks like it will be fixed in upstream git. Refs: discussion thread, patch
来源:https://stackoverflow.com/questions/47084672/git-tries-to-stat-head-when-searching-for-a-repo-leading-to-huge-delays-on-cy