cmd/go/internal/modfetch/gitrepo: fix problem with Git LFS Git LFS would prefer we use "git fetch origin" instead of "git fetch <URL>". Do that. Abandon any preexisting git checkouts by changing the hash key from git1 to git2. Fixes golang/go#25605. Change-Id: I2152376452cc18d97150f37d6ec0a4a75e15d83d Reviewed-on: https://go-review.googlesource.com/116758 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
diff --git a/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go b/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go index 7212e8f..49c9a5b 100644 --- a/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go +++ b/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go
@@ -34,7 +34,7 @@ return newRepo(remote, root, true) } -const workDirType = "git1" +const workDirType = "git2" func newRepo(remote, root string, localOK bool) (codehost.Repo, error) { r := &repo{remote: remote, root: root, canArchive: true} @@ -47,8 +47,18 @@ r.dir = dir if _, err := os.Stat(filepath.Join(dir, "objects")); err != nil { if _, err := codehost.Run(dir, "git", "init", "--bare"); err != nil { + os.RemoveAll(dir) return nil, err } + // We could just say git fetch https://whatever later, + // but this lets us say git fetch origin instead, which + // is a little nicer. More importantly, using a named remote + // avoids a problem with Git LFS. See golang.org/issue/25605. + if _, err := codehost.Run(dir, "git", "remote", "add", "origin", r.remote); err != nil { + os.RemoveAll(dir) + return nil, err + } + r.remote = "origin" } } else { // Local path.