Skip to content

Commit

Permalink
[release-branch.go1.20] cmd/go/internal/modfetch/codehost: set core.l…
Browse files Browse the repository at this point in the history
…ongpaths 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]>
  • Loading branch information
Bryan C. Mills authored and heschi committed Nov 7, 2023
1 parent 1d0d4b1 commit e1dc209
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cmd/go/internal/modfetch/codehost/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -95,6 +96,21 @@ func newGitRepo(remote string, localOK bool) (Repo, error) {
os.RemoveAll(r.dir)
return nil, err
}
if runtime.GOOS == "windows" {
// Git for Windows by default does not support paths longer than
// MAX_PATH (260 characters) because that may interfere with navigation
// in some Windows programs. However, cmd/go should be able to handle
// long paths just fine, and we expect people to use 'go clean' to
// manipulate the module cache, so it should be harmless to set here,
// and in some cases may be necessary in order to download modules with
// long branch names.
//
// See https://github.com/git-for-windows/git/wiki/Git-cannot-create-a-file-or-directory-with-a-long-path.
if _, err := Run(r.dir, "git", "config", "core.longpaths", "true"); err != nil {
os.RemoveAll(r.dir)
return nil, err
}
}
}
r.remoteURL = r.remote
r.remote = "origin"
Expand Down

0 comments on commit e1dc209

Please sign in to comment.