Skip to content

Commit

Permalink
Loosen up version check for git
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-decker committed Jun 1, 2023
1 parent 183037a commit 572cb0e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/sources/git/cmd_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"github.com/go-errors/errors"
)

// GitCmdCheck checks if git is installed and meets 2.36.6<=x<3.0.0 version requirements.
// GitCmdCheck checks if git is installed and meets 2.20.0<=x<3.0.0 version requirements.
func GitCmdCheck() error {
if errors.Is(exec.Command("git").Run(), exec.ErrNotFound) {
return fmt.Errorf("'git' command not found in $PATH. Make sure git is installed and included in $PATH")
}

// Check the version is greater than or equal to 2.36.6
// Check the version is greater than or equal to 2.20.0
out, err := exec.Command("git", "--version").Output()
if err != nil {
return fmt.Errorf("failed to check git version: %w", err)
Expand All @@ -30,12 +30,11 @@ func GitCmdCheck() error {
// Parse version numbers
major, _ := strconv.Atoi(versionParts[0])
minor, _ := strconv.Atoi(versionParts[1])
patch, _ := strconv.Atoi(versionParts[2])

// Compare with version 2.36.6<=x<3.0.0
if (major == 2 && minor > 36) || (major == 2 && minor == 36 && patch >= 6) {
// Compare with version 2.20.0<=x<3.0.0
if major == 2 && minor >= 20 {
return nil
} else {
return fmt.Errorf("git version is %s, but must be greater than or equal to 2.36.6, and less than 3.0.0", versionStr)
return fmt.Errorf("git version is %s, but must be greater than or equal to 2.20.0, and less than 3.0.0", versionStr)
}
}

0 comments on commit 572cb0e

Please sign in to comment.