From 3b183da509b9416d434d2736b01ded450fae51ff Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 1 Jun 2016 02:36:25 +0000 Subject: [PATCH] Fix gitconfig dependency in pkg/gitutils.TestCheckoutGit Fix #23152 Signed-off-by: Akihiro Suda --- gitutils/gitutils_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gitutils/gitutils_test.go b/gitutils/gitutils_test.go index ec288f0..d197058 100644 --- a/gitutils/gitutils_test.go +++ b/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" }