Skip to content

Commit 7cbfce5

Browse files
go-version constraints ignore pre-releases
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. PR for this go-gitea#13234 Signed-off-by: Andrew Thornton <[email protected]> Signed-off-by: wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf <[email protected]>
1 parent 53359b1 commit 7cbfce5

File tree

12 files changed

+25
-25
lines changed

12 files changed

+25
-25
lines changed

modules/git/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ func (c *Commit) GetBranchName() (string, error) {
477477
args := []string{
478478
"name-rev",
479479
}
480-
if CheckGitVersionConstraint(">= 2.13.0") == nil {
480+
if CheckGitVersionAtLeast("2.13.0") == nil {
481481
args = append(args, "--exclude", "refs/tags/*")
482482
}
483483
args = append(args, "--name-only", "--no-undefined", c.ID.String())

modules/git/git.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ func Init(ctx context.Context) error {
150150
return err
151151
}
152152

153-
if CheckGitVersionConstraint(">= 2.10") == nil {
153+
if CheckGitVersionAtLeast("2.10") == nil {
154154
if err := checkAndSetConfig("receive.advertisePushOptions", "true", true); err != nil {
155155
return err
156156
}
157157
}
158158

159-
if CheckGitVersionConstraint(">= 2.18") == nil {
159+
if CheckGitVersionAtLeast("2.18") == nil {
160160
if err := checkAndSetConfig("core.commitGraph", "true", true); err != nil {
161161
return err
162162
}
@@ -173,17 +173,17 @@ func Init(ctx context.Context) error {
173173
return nil
174174
}
175175

176-
// CheckGitVersionConstraint check version constrain against local installed git version
177-
func CheckGitVersionConstraint(constraint string) error {
176+
// CheckGitVersionAtLeast check git version is at least the constraint version
177+
func CheckGitVersionAtLeast(atLeast string) error {
178178
if err := LoadGitVersion(); err != nil {
179179
return err
180180
}
181-
check, err := version.NewConstraint(constraint)
181+
atLeastVersion, err := version.NewVersion(atLeast)
182182
if err != nil {
183183
return err
184184
}
185-
if !check.Check(gitVersion) {
186-
return fmt.Errorf("installed git binary %s does not satisfy version constraint %s", gitVersion.Original(), constraint)
185+
if gitVersion.Compare(atLeastVersion) < 0 {
186+
return fmt.Errorf("installed git binary version %s is not at least %s", gitVersion.Original(), atLeast)
187187
}
188188
return nil
189189
}

modules/git/repo_attribute.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[
4040
}
4141

4242
// git check-attr --cached first appears in git 1.7.8
43-
if opts.CachedOnly && CheckGitVersionConstraint(">= 1.7.8") == nil {
43+
if opts.CachedOnly && CheckGitVersionAtLeast("1.7.8") == nil {
4444
cmdArgs = append(cmdArgs, "--cached")
4545
}
4646

modules/git/repo_commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func (repo *Repository) getCommitsBeforeLimit(id SHA1, num int) (*list.List, err
469469
}
470470

471471
func (repo *Repository) getBranches(commit *Commit, limit int) ([]string, error) {
472-
if CheckGitVersionConstraint(">= 2.7.0") == nil {
472+
if CheckGitVersionAtLeast("2.7.0") == nil {
473473
stdout, err := NewCommand("for-each-ref", "--count="+strconv.Itoa(limit), "--format=%(refname:strip=2)", "--contains", commit.ID.String(), BranchPrefix).RunInDir(repo.Path)
474474
if err != nil {
475475
return nil, err

modules/git/repo_tree.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ func (repo *Repository) CommitTree(author *Signature, committer *Signature, tree
8989
_, _ = messageBytes.WriteString(opts.Message)
9090
_, _ = messageBytes.WriteString("\n")
9191

92-
if CheckGitVersionConstraint(">= 1.7.9") == nil && (opts.KeyID != "" || opts.AlwaysSign) {
92+
if CheckGitVersionAtLeast("1.7.9") == nil && (opts.KeyID != "" || opts.AlwaysSign) {
9393
cmd.AddArguments(fmt.Sprintf("-S%s", opts.KeyID))
9494
}
9595

96-
if CheckGitVersionConstraint(">= 2.0.0") == nil && opts.NoGPGSign {
96+
if CheckGitVersionAtLeast("2.0.0") == nil && opts.NoGPGSign {
9797
cmd.AddArguments("--no-gpg-sign")
9898
}
9999

modules/repofiles/temp_repo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
214214
args := []string{"commit-tree", treeHash, "-p", "HEAD"}
215215

216216
// Determine if we should sign
217-
if git.CheckGitVersionConstraint(">= 1.7.9") == nil {
217+
if git.CheckGitVersionAtLeast("1.7.9") == nil {
218218
sign, keyID, signer, _ := t.repo.SignCRUDAction(author, t.basePath, "HEAD")
219219
if sign {
220220
args = append(args, "-S"+keyID)
@@ -231,7 +231,7 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
231231
}
232232
committerSig = signer
233233
}
234-
} else if git.CheckGitVersionConstraint(">= 2.0.0") == nil {
234+
} else if git.CheckGitVersionAtLeast("2.0.0") == nil {
235235
args = append(args, "--no-gpg-sign")
236236
}
237237
}
@@ -335,7 +335,7 @@ func (t *TemporaryUploadRepository) CheckAttribute(attribute string, args ...str
335335
cmdArgs := []string{"check-attr", "-z", attribute}
336336

337337
// git check-attr --cached first appears in git 1.7.8
338-
if git.CheckGitVersionConstraint(">= 1.7.8") == nil {
338+
if git.CheckGitVersionAtLeast("1.7.8") == nil {
339339
cmdArgs = append(cmdArgs, "--cached")
340340
}
341341
cmdArgs = append(cmdArgs, "--")

modules/repository/init.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *models.User, def
131131
"-m", "Initial commit",
132132
}
133133

134-
if git.CheckGitVersionConstraint(">= 1.7.9") == nil {
134+
if git.CheckGitVersionAtLeast("1.7.9") == nil {
135135
sign, keyID, signer, _ := models.SignInitialCommit(tmpPath, u)
136136
if sign {
137137
args = append(args, "-S"+keyID)
@@ -141,7 +141,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *models.User, def
141141
committerName = signer.Name
142142
committerEmail = signer.Email
143143
}
144-
} else if git.CheckGitVersionConstraint(">= 2.0.0") == nil {
144+
} else if git.CheckGitVersionAtLeast("2.0.0") == nil {
145145
args = append(args, "--no-gpg-sign")
146146
}
147147
}

modules/setting/git.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ func newGit() {
7474
log.Fatal("Error retrieving git version: %v", err)
7575
}
7676

77-
if git.CheckGitVersionConstraint(">= 2.9") == nil {
77+
if git.CheckGitVersionAtLeast("2.9") == nil {
7878
// Explicitly disable credential helper, otherwise Git credentials might leak
7979
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
8080
}
8181

8282
var format = "Git Version: %s"
8383
var args = []interface{}{version.Original()}
8484
// Since git wire protocol has been released from git v2.18
85-
if Git.EnableAutoGitWireProtocol && git.CheckGitVersionConstraint(">= 2.18") == nil {
85+
if Git.EnableAutoGitWireProtocol && git.CheckGitVersionAtLeast("2.18") == nil {
8686
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "protocol.version=2")
8787
format += ", Wire Protocol %s Enabled"
8888
args = append(args, "Version 2") // for focus color

modules/setting/lfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func CheckLFSVersion() {
9696
log.Fatal("Error retrieving git version: %v", err)
9797
}
9898

99-
if git.CheckGitVersionConstraint(">= 2.1.2") != nil {
99+
if git.CheckGitVersionAtLeast("2.1.2") != nil {
100100
LFS.StartServer = false
101101
log.Error("LFS server support needs at least Git v2.1.2")
102102
} else {

routers/repo/lfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func LFSPointerFiles(ctx *context.Context) {
584584
go createPointerResultsFromCatFileBatch(catFileBatchReader, &wg, pointerChan, ctx.Repo.Repository, ctx.User)
585585
go pipeline.CatFileBatch(shasToBatchReader, catFileBatchWriter, &wg, basePath)
586586
go pipeline.BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader, shasToBatchWriter, &wg)
587-
if git.CheckGitVersionConstraint(">= 2.6.0") != nil {
587+
if git.CheckGitVersionAtLeast("2.6.0") != nil {
588588
revListReader, revListWriter := io.Pipe()
589589
shasToCheckReader, shasToCheckWriter := io.Pipe()
590590
wg.Add(2)

services/mirror/mirror.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func remoteAddress(repoPath string) (string, error) {
4646
if err != nil {
4747
return "", err
4848
}
49-
if git.CheckGitVersionConstraint(">= 2.7") == nil {
49+
if git.CheckGitVersionAtLeast("2.7") == nil {
5050
cmd = git.NewCommand("remote", "get-url", "origin")
5151
} else {
5252
cmd = git.NewCommand("config", "--get", "remote.origin.url")

services/pull/merge.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge
155155
}
156156

157157
var gitConfigCommand func() *git.Command
158-
if git.CheckGitVersionConstraint(">= 1.8.0") == nil {
158+
if git.CheckGitVersionAtLeast("1.8.0") == nil {
159159
gitConfigCommand = func() *git.Command {
160160
return git.NewCommand("config", "--local")
161161
}
@@ -214,14 +214,14 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge
214214

215215
// Determine if we should sign
216216
signArg := ""
217-
if git.CheckGitVersionConstraint(">= 1.7.9") == nil {
217+
if git.CheckGitVersionAtLeast("1.7.9") == nil {
218218
sign, keyID, signer, _ := pr.SignMerge(doer, tmpBasePath, "HEAD", trackingBranch)
219219
if sign {
220220
signArg = "-S" + keyID
221221
if pr.BaseRepo.GetTrustModel() == models.CommitterTrustModel || pr.BaseRepo.GetTrustModel() == models.CollaboratorCommitterTrustModel {
222222
committer = signer
223223
}
224-
} else if git.CheckGitVersionConstraint(">= 2.0.0") == nil {
224+
} else if git.CheckGitVersionAtLeast("2.0.0") == nil {
225225
signArg = "--no-gpg-sign"
226226
}
227227
}

0 commit comments

Comments
 (0)