File: path.go

package info (click to toggle)
docker-buildx 0.13.1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,356 kB
  • sloc: sh: 299; makefile: 87
file content (42 lines) | stat: -rw-r--r-- 928 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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")
}