Skip to content

Commit

Permalink
gitutil: check git bash env when testing
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jan 25, 2024
1 parent fb2c62a commit 703c765
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion util/gitutil/path_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
package gitutil

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSanitizePathWindows(t *testing.T) {
assert.Equal(t, "C:\\Users\\foobar", SanitizePath("C:/Users/foobar"))
expected := "C:\\Users\\foobar"
if isGitBash() {
expected = "C:/Users/foobar"
}
assert.Equal(t, expected, SanitizePath("C:/Users/foobar"))
}

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
}

0 comments on commit 703c765

Please sign in to comment.