aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes6
-rw-r--r--src/all.bat1
-rw-r--r--src/clean.bat1
-rw-r--r--src/make.bat1
-rw-r--r--src/race.bat1
-rw-r--r--src/run.bat1
-rw-r--r--test/winbatch.go30
7 files changed, 40 insertions, 1 deletions
diff --git a/.gitattributes b/.gitattributes
index 07953cae39..bcea0290f4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -8,3 +8,9 @@
# See golang.org/issue/9281
* -text
+
+# The only exception is Windows files that must absolutely be CRLF or
+# might not work. Batch files are known to have multiple bugs when run
+# with LF endings. See golang.org/issue/37791 for more information.
+
+*.bat text eol=crlf
diff --git a/src/all.bat b/src/all.bat
index 0647a715ba..8bbd6b1b5d 100644
--- a/src/all.bat
+++ b/src/all.bat
@@ -1,6 +1,7 @@
:: Copyright 2012 The Go Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style
:: license that can be found in the LICENSE file.
+
@echo off
setlocal
diff --git a/src/clean.bat b/src/clean.bat
index 3cc6a689bc..0954dcd67f 100644
--- a/src/clean.bat
+++ b/src/clean.bat
@@ -1,6 +1,7 @@
:: Copyright 2012 The Go Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style
:: license that can be found in the LICENSE file.
+
@echo off
setlocal
diff --git a/src/make.bat b/src/make.bat
index d18cd87d48..5dbde85564 100644
--- a/src/make.bat
+++ b/src/make.bat
@@ -132,3 +132,4 @@ set GOBUILDFAIL=1
if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
:end
+
diff --git a/src/race.bat b/src/race.bat
index e1c3fbf5d9..d26f3180a3 100644
--- a/src/race.bat
+++ b/src/race.bat
@@ -49,4 +49,3 @@ echo All tests passed.
:end
if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
-
diff --git a/src/run.bat b/src/run.bat
index 123edcc35d..25ee58001e 100644
--- a/src/run.bat
+++ b/src/run.bat
@@ -1,6 +1,7 @@
:: Copyright 2012 The Go Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style
:: license that can be found in the LICENSE file.
+
@echo off
:: Keep environment variables within this script
diff --git a/test/winbatch.go b/test/winbatch.go
new file mode 100644
index 0000000000..30e0e3c982
--- /dev/null
+++ b/test/winbatch.go
@@ -0,0 +1,30 @@
+// run
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Check that batch files are maintained as CRLF files (consistent behaviour
+// on all operating systems). See https://github.com/golang/go/issues/37791
+
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "runtime"
+)
+
+func main() {
+ batches, _ := filepath.Glob(runtime.GOROOT() + "/src/*.bat")
+ for _, bat := range batches {
+ body, _ := ioutil.ReadFile(bat)
+ if !bytes.Contains(body, []byte("\r\n")) {
+ fmt.Printf("Windows batch file %s does not contain CRLF line termination.\nTry running git checkout src/*.bat to fix this.\n", bat)
+ os.Exit(1)
+ }
+ }
+}