@@ -16,14 +16,18 @@ import (
1616 "io/fs"
1717 "log"
1818 "os"
19+ "os/exec"
1920 "path"
2021 "path/filepath"
2122 "reflect"
23+ "regexp"
2224 "runtime"
2325 "strings"
2426 "sync"
2527 "testing"
2628 "time"
29+
30+ "golang.org/x/mod/semver"
2731)
2832
2933func TestMain (m * testing.M ) {
@@ -192,9 +196,29 @@ func testRepo(ctx context.Context, t *testing.T, remote string) (Repo, error) {
192196 return NewRepo (ctx , vcsName , remote , false )
193197}
194198
199+ var gitVersLineExtract = regexp .MustCompile (`git version\s+([\d.]+)` )
200+
201+ func gitVersion (t testing.TB ) string {
202+ gitOut , runErr := exec .Command ("git" , "version" ).CombinedOutput ()
203+ if runErr != nil {
204+ t .Logf ("failed to execute git version: %s" , runErr )
205+ return "v0"
206+ }
207+ matches := gitVersLineExtract .FindSubmatch (gitOut )
208+ if len (matches ) < 2 {
209+ t .Logf ("git version extraction regexp did not match version line: %q" , gitOut )
210+ return "v0"
211+ }
212+ return "v" + string (matches [1 ])
213+ }
214+
215+ const minGitSHA256Vers = "v2.29"
216+
195217func TestTags (t * testing.T ) {
196218 t .Parallel ()
197219
220+ gitVers := gitVersion (t )
221+
198222 type tagsTest struct {
199223 repo string
200224 prefix string
@@ -204,6 +228,9 @@ func TestTags(t *testing.T) {
204228 runTest := func (tt tagsTest ) func (* testing.T ) {
205229 return func (t * testing.T ) {
206230 t .Parallel ()
231+ if tt .repo == gitsha256repo && semver .Compare (gitVers , minGitSHA256Vers ) < 0 {
232+ t .Skipf ("git version is too old (%+v); skipping git sha256 test" , gitVers )
233+ }
207234 ctx := testContext (t )
208235
209236 r , err := testRepo (ctx , t , tt .repo )
@@ -288,6 +315,8 @@ func TestTags(t *testing.T) {
288315func TestLatest (t * testing.T ) {
289316 t .Parallel ()
290317
318+ gitVers := gitVersion (t )
319+
291320 type latestTest struct {
292321 repo string
293322 info * RevInfo
@@ -297,6 +326,10 @@ func TestLatest(t *testing.T) {
297326 t .Parallel ()
298327 ctx := testContext (t )
299328
329+ if tt .repo == gitsha256repo && semver .Compare (gitVers , minGitSHA256Vers ) < 0 {
330+ t .Skipf ("git version is too old (%+v); skipping git sha256 test" , gitVers )
331+ }
332+
300333 r , err := testRepo (ctx , t , tt .repo )
301334 if err != nil {
302335 t .Fatal (err )
@@ -375,6 +408,8 @@ func TestLatest(t *testing.T) {
375408func TestReadFile (t * testing.T ) {
376409 t .Parallel ()
377410
411+ gitVers := gitVersion (t )
412+
378413 type readFileTest struct {
379414 repo string
380415 rev string
@@ -387,6 +422,10 @@ func TestReadFile(t *testing.T) {
387422 t .Parallel ()
388423 ctx := testContext (t )
389424
425+ if tt .repo == gitsha256repo && semver .Compare (gitVers , minGitSHA256Vers ) < 0 {
426+ t .Skipf ("git version is too old (%+v); skipping git sha256 test" , gitVers )
427+ }
428+
390429 r , err := testRepo (ctx , t , tt .repo )
391430 if err != nil {
392431 t .Fatal (err )
@@ -468,6 +507,8 @@ type zipFile struct {
468507func TestReadZip (t * testing.T ) {
469508 t .Parallel ()
470509
510+ gitVers := gitVersion (t )
511+
471512 type readZipTest struct {
472513 repo string
473514 rev string
@@ -480,6 +521,10 @@ func TestReadZip(t *testing.T) {
480521 t .Parallel ()
481522 ctx := testContext (t )
482523
524+ if tt .repo == gitsha256repo && semver .Compare (gitVers , minGitSHA256Vers ) < 0 {
525+ t .Skipf ("git version is too old (%+v); skipping git sha256 test" , gitVers )
526+ }
527+
483528 r , err := testRepo (ctx , t , tt .repo )
484529 if err != nil {
485530 t .Fatal (err )
@@ -753,6 +798,8 @@ var hgmap = map[string]string{
753798func TestStat (t * testing.T ) {
754799 t .Parallel ()
755800
801+ gitVers := gitVersion (t )
802+
756803 type statTest struct {
757804 repo string
758805 rev string
@@ -764,6 +811,10 @@ func TestStat(t *testing.T) {
764811 t .Parallel ()
765812 ctx := testContext (t )
766813
814+ if tt .repo == gitsha256repo && semver .Compare (gitVers , minGitSHA256Vers ) < 0 {
815+ t .Skipf ("git version is too old (%+v); skipping git sha256 test" , gitVers )
816+ }
817+
767818 r , err := testRepo (ctx , t , tt .repo )
768819 if err != nil {
769820 t .Fatal (err )
0 commit comments