@@ -19,6 +19,8 @@ import (
1919 "os"
2020 "os/exec"
2121 "path"
22+ "strconv"
23+ "strings"
2224 "testing"
2325
2426 "github.com/googleapis/librarian/internal/sidekick/config"
@@ -229,6 +231,37 @@ func requireCommand(t *testing.T, command string) {
229231 if _ , err := exec .LookPath (command ); err != nil {
230232 t .Skipf ("skipping test because %s is not installed" , command )
231233 }
234+ if command == "git" {
235+ requireGitVersion (t )
236+ }
237+ }
238+
239+ func requireGitVersion (t * testing.T ) {
240+ t .Helper ()
241+ out , err := exec .Command ("git" , "--version" ).Output ()
242+ if err != nil {
243+ t .Skipf ("cannot determine git version: %v" , err )
244+ }
245+ v := strings .TrimSpace (string (out ))
246+ f := strings .Fields (v )
247+ if len (f ) < 3 {
248+ t .Skipf ("unexpected git version format: %s" , v )
249+ }
250+ parts := strings .Split (f [2 ], "." )
251+ if len (parts ) < 2 {
252+ t .Skipf ("unexpected git version format: %s" , f [2 ])
253+ }
254+ major , err := strconv .Atoi (parts [0 ])
255+ if err != nil {
256+ t .Skipf ("cannot parse git major version: %s" , parts [0 ])
257+ }
258+ minor , err := strconv .Atoi (parts [1 ])
259+ if err != nil {
260+ t .Skipf ("cannot parse git minor version: %s" , parts [1 ])
261+ }
262+ if major < 2 || major == 2 && minor < 28 {
263+ t .Skipf ("git 2.28 or later required; have %s" , f [2 ])
264+ }
232265}
233266
234267func configNewGitRepository (t * testing.T ) {
0 commit comments