Skip to content

Commit e1dc209

Browse files
Bryan C. Millsheschi
authored andcommitted
[release-branch.go1.20] cmd/go/internal/modfetch/codehost: set core.longpaths in Git repos on Windows
This setting appears to be needed to avoid “Filename too long” errors when downloading modules from repos with long branch names, particularly if the path to the module cache is already fairly long (as may be the case in CI systems and in tests of cmd/go itself). Fixes #63988. Change-Id: I3aa89ea872b29eb0460c8a8afc94f182a68982fd Reviewed-on: https://go-review.googlesource.com/c/go/+/482819 Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit 0c89487) Reviewed-on: https://go-review.googlesource.com/c/go/+/539278 LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 1d0d4b1 commit e1dc209

File tree

1 file changed

+16
-0
lines changed
  • src/cmd/go/internal/modfetch/codehost

1 file changed

+16
-0
lines changed

src/cmd/go/internal/modfetch/codehost/git.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"os"
1717
"os/exec"
1818
"path/filepath"
19+
"runtime"
1920
"sort"
2021
"strconv"
2122
"strings"
@@ -95,6 +96,21 @@ func newGitRepo(remote string, localOK bool) (Repo, error) {
9596
os.RemoveAll(r.dir)
9697
return nil, err
9798
}
99+
if runtime.GOOS == "windows" {
100+
// Git for Windows by default does not support paths longer than
101+
// MAX_PATH (260 characters) because that may interfere with navigation
102+
// in some Windows programs. However, cmd/go should be able to handle
103+
// long paths just fine, and we expect people to use 'go clean' to
104+
// manipulate the module cache, so it should be harmless to set here,
105+
// and in some cases may be necessary in order to download modules with
106+
// long branch names.
107+
//
108+
// See https://github.com/git-for-windows/git/wiki/Git-cannot-create-a-file-or-directory-with-a-long-path.
109+
if _, err := Run(r.dir, "git", "config", "core.longpaths", "true"); err != nil {
110+
os.RemoveAll(r.dir)
111+
return nil, err
112+
}
113+
}
98114
}
99115
r.remoteURL = r.remote
100116
r.remote = "origin"

0 commit comments

Comments
 (0)