Fix gitconfig dependency in pkg/gitutils.TestCheckoutGit
Fix #23152 Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
parent
ed9647689d
commit
3b183da509
1 changed files with 17 additions and 1 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"testing"
|
"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) {
|
func TestCheckoutGit(t *testing.T) {
|
||||||
root, err := ioutil.TempDir("", "docker-build-git-checkout")
|
root, err := ioutil.TempDir("", "docker-build-git-checkout")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,8 +88,13 @@ func TestCheckoutGit(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(root)
|
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"
|
eol := "\n"
|
||||||
if runtime.GOOS == "windows" {
|
if autocrlf == "true" {
|
||||||
eol = "\r\n"
|
eol = "\r\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue