lfshttp: handle bare repos in standalone adapter

The Go test suite adds remotes in the form of temporary bare Git
repositories, which lack a ".git" directory.  These are then configured
with their local paths as the value of the "remote.origin.url" key,
which the EndpointFinder returns, but with "/.git" appended by the
EndpointFromLocalPath() function.

When the standalone transfer adapter attempts to chdir(2) to one of
these file paths in order to run the "git rev-parse --git-dir" command
when setting up a new handler, it obviously fails.

We can address this by simply removing any trailing "/.git" path
segment in the gitDirAtPath() function in the standalone adapter.
The "git rev-parse --git-dir" command will succeed in either case,
whether in a bare repository or a regular one.

This should permit any users who have Git LFS configurations with
custom adapters that depend on the EndpointFinder's current logic
to continue to work, while allowing our Go test suite to succeed
with its bare remote repositories.
This commit is contained in:
Chris Darroch 2020-03-27 19:51:37 -07:00
parent 0f2cccb481
commit b6b0b6fef0

@ -101,6 +101,11 @@ func gitDirAtPath(path string) (string, error) {
}
env = env[:n]
// Trim any trailing .git path segment.
if filepath.Base(path) == ".git" {
path = filepath.Dir(path)
}
curdir, err := os.Getwd()
if err != nil {
return "", err