go-version constraints ignore pre-releases (#13234)

Go-version constraints ignore pre-releases.

Rather than change the library further this PR simply changes
the git version comparison to use simple version compare ignoring the
issue of pre-releases.

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath 2020-10-21 16:42:08 +01:00 committed by GitHub
parent 53359b1861
commit de6e427a01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 25 additions and 25 deletions

View file

@ -477,7 +477,7 @@ func (c *Commit) GetBranchName() (string, error) {
args := []string{
"name-rev",
}
if CheckGitVersionConstraint(">= 2.13.0") == nil {
if CheckGitVersionAtLeast("2.13.0") == nil {
args = append(args, "--exclude", "refs/tags/*")
}
args = append(args, "--name-only", "--no-undefined", c.ID.String())

View file

@ -150,13 +150,13 @@ func Init(ctx context.Context) error {
return err
}
if CheckGitVersionConstraint(">= 2.10") == nil {
if CheckGitVersionAtLeast("2.10") == nil {
if err := checkAndSetConfig("receive.advertisePushOptions", "true", true); err != nil {
return err
}
}
if CheckGitVersionConstraint(">= 2.18") == nil {
if CheckGitVersionAtLeast("2.18") == nil {
if err := checkAndSetConfig("core.commitGraph", "true", true); err != nil {
return err
}
@ -173,17 +173,17 @@ func Init(ctx context.Context) error {
return nil
}
// CheckGitVersionConstraint check version constrain against local installed git version
func CheckGitVersionConstraint(constraint string) error {
// CheckGitVersionAtLeast check git version is at least the constraint version
func CheckGitVersionAtLeast(atLeast string) error {
if err := LoadGitVersion(); err != nil {
return err
}
check, err := version.NewConstraint(constraint)
atLeastVersion, err := version.NewVersion(atLeast)
if err != nil {
return err
}
if !check.Check(gitVersion) {
return fmt.Errorf("installed git binary %s does not satisfy version constraint %s", gitVersion.Original(), constraint)
if gitVersion.Compare(atLeastVersion) < 0 {
return fmt.Errorf("installed git binary version %s is not at least %s", gitVersion.Original(), atLeast)
}
return nil
}

View file

@ -40,7 +40,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[
}
// git check-attr --cached first appears in git 1.7.8
if opts.CachedOnly && CheckGitVersionConstraint(">= 1.7.8") == nil {
if opts.CachedOnly && CheckGitVersionAtLeast("1.7.8") == nil {
cmdArgs = append(cmdArgs, "--cached")
}

View file

@ -469,7 +469,7 @@ func (repo *Repository) getCommitsBeforeLimit(id SHA1, num int) (*list.List, err
}
func (repo *Repository) getBranches(commit *Commit, limit int) ([]string, error) {
if CheckGitVersionConstraint(">= 2.7.0") == nil {
if CheckGitVersionAtLeast("2.7.0") == nil {
stdout, err := NewCommand("for-each-ref", "--count="+strconv.Itoa(limit), "--format=%(refname:strip=2)", "--contains", commit.ID.String(), BranchPrefix).RunInDir(repo.Path)
if err != nil {
return nil, err

View file

@ -89,11 +89,11 @@ func (repo *Repository) CommitTree(author *Signature, committer *Signature, tree
_, _ = messageBytes.WriteString(opts.Message)
_, _ = messageBytes.WriteString("\n")
if CheckGitVersionConstraint(">= 1.7.9") == nil && (opts.KeyID != "" || opts.AlwaysSign) {
if CheckGitVersionAtLeast("1.7.9") == nil && (opts.KeyID != "" || opts.AlwaysSign) {
cmd.AddArguments(fmt.Sprintf("-S%s", opts.KeyID))
}
if CheckGitVersionConstraint(">= 2.0.0") == nil && opts.NoGPGSign {
if CheckGitVersionAtLeast("2.0.0") == nil && opts.NoGPGSign {
cmd.AddArguments("--no-gpg-sign")
}