Browse Source

Merge pull request #23153 from AkihiroSuda/fix23152PkgGitutils

Fix gitconfig dependency in pkg/gitutils.TestCheckoutGit
Vincent Demeester 9 years ago
parent
commit
f69353a364
1 changed files with 17 additions and 1 deletions
  1. 17 1
      pkg/gitutils/gitutils_test.go

+ 17 - 1
pkg/gitutils/gitutils_test.go

@@ -10,6 +10,7 @@ import (
 	"path/filepath"
 	"reflect"
 	"runtime"
+	"strings"
 	"testing"
 )
 
@@ -70,6 +71,16 @@ func TestCloneArgsStripFragment(t *testing.T) {
 	}
 }
 
+func gitGetConfig(name string) string {
+	b, err := git([]string{"config", "--get", name}...)
+	if err != nil {
+		// since we are interested in empty or non empty string,
+		// we can safely ignore the err here.
+		return ""
+	}
+	return strings.TrimSpace(string(b))
+}
+
 func TestCheckoutGit(t *testing.T) {
 	root, err := ioutil.TempDir("", "docker-build-git-checkout")
 	if err != nil {
@@ -77,8 +88,13 @@ func TestCheckoutGit(t *testing.T) {
 	}
 	defer os.RemoveAll(root)
 
+	autocrlf := gitGetConfig("core.autocrlf")
+	if !(autocrlf == "true" || autocrlf == "false" ||
+		autocrlf == "input" || autocrlf == "") {
+		t.Logf("unknown core.autocrlf value: \"%s\"", autocrlf)
+	}
 	eol := "\n"
-	if runtime.GOOS == "windows" {
+	if autocrlf == "true" {
 		eol = "\r\n"
 	}