8
8
"archive/zip"
9
9
"bytes"
10
10
"flag"
11
- "fmt"
12
11
"internal/testenv"
13
12
"io"
14
13
"io/fs"
@@ -47,36 +46,32 @@ var altRepos = []string{
47
46
var localGitRepo string
48
47
49
48
func testMain (m * testing.M ) int {
50
- if _ , err := exec .LookPath ("git" ); err != nil {
51
- fmt .Fprintln (os .Stderr , "skipping because git binary not found" )
52
- fmt .Println ("PASS" )
53
- return 0
54
- }
55
-
56
49
dir , err := os .MkdirTemp ("" , "gitrepo-test-" )
57
50
if err != nil {
58
51
log .Fatal (err )
59
52
}
60
53
defer os .RemoveAll (dir )
61
54
62
55
if testenv .HasExternalNetwork () && testenv .HasExec () {
63
- // Clone gitrepo1 into a local directory.
64
- // If we use a file:// URL to access the local directory,
65
- // then git starts up all the usual protocol machinery,
66
- // which will let us test remote git archive invocations.
67
- localGitRepo = filepath .Join (dir , "gitrepo2" )
68
- if _ , err := Run ("" , "git" , "clone" , "--mirror" , gitrepo1 , localGitRepo ); err != nil {
69
- log .Fatal (err )
70
- }
71
- if _ , err := Run (localGitRepo , "git" , "config" , "daemon.uploadarch" , "true" ); err != nil {
72
- log .Fatal (err )
56
+ if _ , err := exec .LookPath ("git" ); err == nil {
57
+ // Clone gitrepo1 into a local directory.
58
+ // If we use a file:// URL to access the local directory,
59
+ // then git starts up all the usual protocol machinery,
60
+ // which will let us test remote git archive invocations.
61
+ localGitRepo = filepath .Join (dir , "gitrepo2" )
62
+ if _ , err := Run ("" , "git" , "clone" , "--mirror" , gitrepo1 , localGitRepo ); err != nil {
63
+ log .Fatal (err )
64
+ }
65
+ if _ , err := Run (localGitRepo , "git" , "config" , "daemon.uploadarch" , "true" ); err != nil {
66
+ log .Fatal (err )
67
+ }
73
68
}
74
69
}
75
70
76
71
return m .Run ()
77
72
}
78
73
79
- func testRepo (remote string ) (Repo , error ) {
74
+ func testRepo (t * testing. T , remote string ) (Repo , error ) {
80
75
if remote == "localGitRepo" {
81
76
// Convert absolute path to file URL. LocalGitRepo will not accept
82
77
// Windows absolute paths because they look like a host:path remote.
@@ -87,15 +82,17 @@ func testRepo(remote string) (Repo, error) {
87
82
} else {
88
83
url = "file:///" + filepath .ToSlash (localGitRepo )
89
84
}
85
+ testenv .MustHaveExecPath (t , "git" )
90
86
return LocalGitRepo (url )
91
87
}
92
- kind := "git"
88
+ vcs := "git"
93
89
for _ , k := range []string {"hg" } {
94
90
if strings .Contains (remote , "/" + k + "/" ) {
95
- kind = k
91
+ vcs = k
96
92
}
97
93
}
98
- return NewRepo (kind , remote )
94
+ testenv .MustHaveExecPath (t , vcs )
95
+ return NewRepo (vcs , remote )
99
96
}
100
97
101
98
var tagsTests = []struct {
@@ -116,7 +113,7 @@ func TestTags(t *testing.T) {
116
113
117
114
for _ , tt := range tagsTests {
118
115
f := func (t * testing.T ) {
119
- r , err := testRepo (tt .repo )
116
+ r , err := testRepo (t , tt .repo )
120
117
if err != nil {
121
118
t .Fatal (err )
122
119
}
@@ -168,7 +165,7 @@ func TestLatest(t *testing.T) {
168
165
169
166
for _ , tt := range latestTests {
170
167
f := func (t * testing.T ) {
171
- r , err := testRepo (tt .repo )
168
+ r , err := testRepo (t , tt .repo )
172
169
if err != nil {
173
170
t .Fatal (err )
174
171
}
@@ -221,7 +218,7 @@ func TestReadFile(t *testing.T) {
221
218
222
219
for _ , tt := range readFileTests {
223
220
f := func (t * testing.T ) {
224
- r , err := testRepo (tt .repo )
221
+ r , err := testRepo (t , tt .repo )
225
222
if err != nil {
226
223
t .Fatal (err )
227
224
}
@@ -412,7 +409,7 @@ func TestReadZip(t *testing.T) {
412
409
413
410
for _ , tt := range readZipTests {
414
411
f := func (t * testing.T ) {
415
- r , err := testRepo (tt .repo )
412
+ r , err := testRepo (t , tt .repo )
416
413
if err != nil {
417
414
t .Fatal (err )
418
415
}
@@ -581,7 +578,7 @@ func TestStat(t *testing.T) {
581
578
582
579
for _ , tt := range statTests {
583
580
f := func (t * testing.T ) {
584
- r , err := testRepo (tt .repo )
581
+ r , err := testRepo (t , tt .repo )
585
582
if err != nil {
586
583
t .Fatal (err )
587
584
}
0 commit comments