Skip to content

Commit a70af2f

Browse files
committed
Fixing CI
- Added comment on why bzr tests are being skipped - Fixed the git submodule handling on Windows Signed-off-by: Matt Farina <matt@mattfarina.com>
1 parent 1db9d87 commit a70af2f

File tree

6 files changed

+84
-2
lines changed

6 files changed

+84
-2
lines changed

.github/workflows/windows-tests.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ jobs:
2525
- name: Test
2626
run: go test -v
2727
env:
28+
# Skipping bzr tests on Windows as bzr does not install properly there.
29+
# bzr development stopped in 2017 (when last change landed). The official
30+
# windows installer is still bzr 2.5. The installer does not setup working
31+
# cacerts. This needs to be manually modified to get working. Skipping
32+
# tests in this environment as there are environment problems.
2833
SKIP_BZR: "true"

git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ func (s *GitRepo) ExportDir(dir string) error {
412412
}
413413

414414
// and now, the horror of submodules
415-
path = EscapePathSeparator(dir + "$path" + string(os.PathSeparator))
416-
out, err = s.RunFromDir("git", "submodule", "foreach", "--recursive", "git checkout-index -f -a --prefix="+path)
415+
handleSubmodules(s, dir)
416+
417417
s.log(out)
418418
if err != nil {
419419
return NewLocalError("Error while exporting submodule sources", err, string(out))

git_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ func TestGitSubmoduleHandling2(t *testing.T) {
573573

574574
exportDir := filepath.Join(tempDir2, "src")
575575

576+
tl := testLogger(t)
577+
repo.Logger = tl
578+
576579
err = repo.ExportDir(exportDir)
577580
if err != nil {
578581
t.Errorf("Unable to export Git repo. Err was %s", err)

git_unix.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package vcs
5+
6+
import "os"
7+
8+
func handleSubmodules(g *GitRepo, dir string) ([]byte, error) {
9+
// Generate path
10+
path := EscapePathSeparator(dir + "$path" + string(os.PathSeparator))
11+
12+
return g.RunFromDir("git", "submodule", "foreach", "--recursive", "git checkout-index -f -a --prefix="+path)
13+
}

git_windows.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package vcs
5+
6+
import (
7+
"os"
8+
"path/filepath"
9+
"strings"
10+
)
11+
12+
func handleSubmodules(g *GitRepo, dir string) ([]byte, error) {
13+
// Get the submodule directories
14+
out, err := g.RunFromDir("git", "submodule", "foreach", "--quiet", "--recursive", "echo $sm_path")
15+
if err != nil {
16+
return out, err
17+
}
18+
cleanOut := strings.TrimSpace(string(out))
19+
pths := strings.Split(strings.ReplaceAll(cleanOut, "\r\n", "\n"), "\n")
20+
21+
// Create the new directories. Directories are sometimes not created under
22+
// Windows
23+
for _, pth := range pths {
24+
fpth := filepath.Join(dir + pth)
25+
os.MkdirAll(fpth, 0755)
26+
}
27+
28+
// checkout-index for each submodule. Using $path or $sm_path while iterating
29+
// over the submodules does not work in Windows when called from Go.
30+
var cOut []byte
31+
for _, pth := range pths {
32+
// Get the path to the submodule in the exported location
33+
fpth := EscapePathSeparator(filepath.Join(dir, pth) + string(os.PathSeparator))
34+
35+
// Call checkout-index directly in the submodule rather than in the
36+
// parent project. This stils git submodule foreach that has trouble
37+
// on Windows within Go where $sm_path isn't being handled properly
38+
c := g.CmdFromDir("git", "checkout-index", "-f", "-a", "--prefix="+fpth)
39+
c.Dir = filepath.Join(c.Dir, pth)
40+
out, err := c.CombinedOutput()
41+
cOut = append(cOut, out...)
42+
if err != nil {
43+
return cOut, err
44+
}
45+
}
46+
return cOut, nil
47+
}

repo_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package vcs
33
import (
44
"fmt"
55
"io/ioutil"
6+
"log"
67
"os"
78
"testing"
89
)
@@ -72,3 +73,16 @@ func TestDepInstalled(t *testing.T) {
7273
t.Error("depInstalled finding not installed dep.")
7374
}
7475
}
76+
77+
func testLogger(t *testing.T) *log.Logger {
78+
return log.New(testWriter{t}, "test", log.LstdFlags)
79+
}
80+
81+
type testWriter struct {
82+
t *testing.T
83+
}
84+
85+
func (tw testWriter) Write(p []byte) (n int, err error) {
86+
tw.t.Log(string(p))
87+
return len(p), nil
88+
}

0 commit comments

Comments
 (0)