-
Notifications
You must be signed in to change notification settings - Fork 60
/
git_windows.go
47 lines (41 loc) · 1.39 KB
/
git_windows.go
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
43
44
45
46
47
//go:build windows
// +build windows
package vcs
import (
"os"
"path/filepath"
"strings"
)
func handleSubmodules(g *GitRepo, dir string) ([]byte, error) {
// Get the submodule directories
out, err := g.RunFromDir("git", "submodule", "foreach", "--quiet", "--recursive", "echo $sm_path")
if err != nil {
return out, err
}
cleanOut := strings.TrimSpace(string(out))
pths := strings.Split(strings.ReplaceAll(cleanOut, "\r\n", "\n"), "\n")
// Create the new directories. Directories are sometimes not created under
// Windows
for _, pth := range pths {
fpth := filepath.Join(dir + pth)
os.MkdirAll(fpth, 0755)
}
// checkout-index for each submodule. Using $path or $sm_path while iterating
// over the submodules does not work in Windows when called from Go.
var cOut []byte
for _, pth := range pths {
// Get the path to the submodule in the exported location
fpth := EscapePathSeparator(filepath.Join(dir, pth) + string(os.PathSeparator))
// Call checkout-index directly in the submodule rather than in the
// parent project. This stils git submodule foreach that has trouble
// on Windows within Go where $sm_path isn't being handled properly
c := g.CmdFromDir("git", "checkout-index", "-f", "-a", "--prefix="+fpth)
c.Dir = filepath.Join(c.Dir, pth)
out, err := c.CombinedOutput()
cOut = append(cOut, out...)
if err != nil {
return cOut, err
}
}
return cOut, nil
}