-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package gitutil | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var windowsPathRegex = regexp.MustCompile(`^[A-Za-z]:[\\/].*$`) | ||
|
||
func sanitizePath(path string) string { | ||
// If we're running in WSL, we need to convert Windows paths to Unix paths. | ||
// This is because the git binary can be invoked through `git.exe` and | ||
// therefore returns Windows paths. | ||
if os.Getenv("WSL_DISTRO_NAME") != "" && windowsPathRegex.MatchString(path) { | ||
unixPath := strings.ReplaceAll(path, "\\", "/") | ||
drive := strings.ToLower(string(unixPath[0])) | ||
rest := filepath.Clean(unixPath[3:]) | ||
return filepath.Join("/mnt", drive, rest) | ||
} | ||
return path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gitutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSanitizePathUnix(t *testing.T) { | ||
assert.Equal(t, "/home/foobar", sanitizePath("/home/foobar")) | ||
} | ||
|
||
func TestSanitizePathWSL(t *testing.T) { | ||
t.Setenv("WSL_DISTRO_NAME", "Ubuntu") | ||
assert.Equal(t, "/mnt/c/Users/foobar", sanitizePath("C:\\Users\\foobar")) | ||
} | ||
|
||
func TestSanitizePathWindows(t *testing.T) { | ||
assert.Equal(t, "C:\\Users\\foobar", sanitizePath("C:\\Users\\foobar")) | ||
} |
File renamed without changes.
File renamed without changes.