-
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.
Merge pull request #1477 from crazy-max/git-wsl
build: lookup the right git binary on WSL
- Loading branch information
Showing
23 changed files
with
1,058 additions
and
111 deletions.
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
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
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,42 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package gitutil | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/moby/sys/mountinfo" | ||
) | ||
|
||
func gitPath(wd string) (string, error) { | ||
// On WSL2 we need to check if the current working directory is mounted on | ||
// a Windows drive and if so, we need to use the Windows git executable. | ||
if os.Getenv("WSL_DISTRO_NAME") != "" && wd != "" { | ||
// ensure any symlinks are resolved | ||
wdPath, err := filepath.EvalSymlinks(wd) | ||
if err != nil { | ||
return "", err | ||
} | ||
mi, err := mountinfo.GetMounts(mountinfo.ParentsFilter(wdPath)) | ||
if err != nil { | ||
return "", err | ||
} | ||
// find the longest mount point | ||
var idx, maxlen int | ||
for i := range mi { | ||
if len(mi[i].Mountpoint) > maxlen { | ||
maxlen = len(mi[i].Mountpoint) | ||
idx = i | ||
} | ||
} | ||
if mi[idx].FSType == "9p" { | ||
if p, err := exec.LookPath("git.exe"); err == nil { | ||
return p, nil | ||
} | ||
} | ||
} | ||
return exec.LookPath("git") | ||
} |
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,9 @@ | ||
package gitutil | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
func gitPath(wd string) (string, error) { | ||
return exec.LookPath("git.exe") | ||
} |
Oops, something went wrong.