2023-12-15 22:33:10 +08:00
|
|
|
package gitutil
|
|
|
|
|
|
|
|
import (
|
2024-01-25 21:46:14 +08:00
|
|
|
"os"
|
2023-12-15 22:33:10 +08:00
|
|
|
"testing"
|
|
|
|
|
2024-02-01 02:59:26 +08:00
|
|
|
"github.com/docker/buildx/util/osutil"
|
2023-12-15 22:33:10 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSanitizePathWindows(t *testing.T) {
|
2024-01-25 21:46:14 +08:00
|
|
|
expected := "C:\\Users\\foobar"
|
|
|
|
if isGitBash() {
|
|
|
|
expected = "C:/Users/foobar"
|
|
|
|
}
|
2024-02-01 02:59:26 +08:00
|
|
|
assert.Equal(t, expected, osutil.SanitizePath("C:/Users/foobar"))
|
2024-01-25 21:46:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func isGitBash() bool {
|
|
|
|
// The MSYSTEM environment variable is used in MSYS2 environments,
|
|
|
|
// including Git Bash, to select the active environment. This variable
|
|
|
|
// dictates the environment in which the shell operates, influencing
|
|
|
|
// factors like the path prefixes, default compilers, and system libraries
|
|
|
|
// used: https://www.msys2.org/docs/environments/
|
|
|
|
if _, ok := os.LookupEnv("MSYSTEM"); ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2023-12-15 22:33:10 +08:00
|
|
|
}
|