cmd/go/internal/modfetch/codehost: fix git code export on Windows
Git was helpfully putting \r\n line endings into the files during "git archive",
which meant that the hash validation didn't work. Fix that.
I believe this bug would have made TestModVerify fail on a
Windows system with git installed and with the default git settings,
but I don't have such a system easily available to test with.
Thanks to CJ-Jackson on GitHub for identifying the right Git flags.
Fixes golang/go#26229.
Change-Id: Ic33ef7272eb3a5cc6b43c361a7d3a1b1d55db714
Reviewed-on: https://go-review.googlesource.com/122480
Reviewed-by: Bryan C. Mills <bcmills@google.com>
diff --git a/vendor/cmd/go/internal/modfetch/codehost/git.go b/vendor/cmd/go/internal/modfetch/codehost/git.go
index 599d63e..afa0467 100644
--- a/vendor/cmd/go/internal/modfetch/codehost/git.go
+++ b/vendor/cmd/go/internal/modfetch/codehost/git.go
@@ -448,7 +448,13 @@
if err != nil {
return nil, "", err
}
- archive, err := Run(r.dir, "git", "archive", "--format=zip", "--prefix=prefix/", info.Name, args)
+
+ // Incredibly, git produces different archives depending on whether
+ // it is running on a Windows system or not, in an attempt to normalize
+ // text file line endings. Setting -c core.autocrlf=input means only
+ // translate files on the way into the repo, not on the way out (archive).
+ // The -c core.eol=lf should be unnecessary but set it anyway.
+ archive, err := Run(r.dir, "git", "-c", "core.autocrlf=input", "-c", "core.eol=lf", "archive", "--format=zip", "--prefix=prefix/", info.Name, args)
if err != nil {
if bytes.Contains(err.(*RunError).Stderr, []byte("did not match any files")) {
return nil, "", os.ErrNotExist