Skip to content

Commit 7ff8da4

Browse files
authored
Merge pull request #459 from fluxcd/libgit2-semver-flake
2 parents b35d7d8 + 9ff5334 commit 7ff8da4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

pkg/git/gogit/checkout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g
212212
}
213213

214214
var matchedVersions semver.Collection
215-
for tag, _ := range tags {
215+
for tag := range tags {
216216
v, err := version.ParseVersion(tag)
217217
if err != nil {
218218
continue
@@ -239,7 +239,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g
239239
// versions into a chronological order. This is especially important for
240240
// versions that differ only by build metadata, because it is not considered
241241
// a part of the comparable version in Semver
242-
return tagTimestamps[left.String()].Before(tagTimestamps[right.String()])
242+
return tagTimestamps[left.Original()].Before(tagTimestamps[right.Original()])
243243
})
244244
v := matchedVersions[len(matchedVersions)-1]
245245
t := v.Original()

pkg/git/libgit2/checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g
225225
// versions into a chronological order. This is especially important for
226226
// versions that differ only by build metadata, because it is not considered
227227
// a part of the comparable version in Semver
228-
return tagTimestamps[left.String()].Before(tagTimestamps[right.String()])
228+
return tagTimestamps[left.Original()].Before(tagTimestamps[right.Original()])
229229
})
230230
v := matchedVersions[len(matchedVersions)-1]
231231
t := v.Original()

pkg/git/libgit2/checkout_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,19 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) {
229229
{
230230
tag: "v0.1.0+build-1",
231231
annotated: true,
232-
commitTime: now.Add(1 * time.Minute),
233-
tagTime: now.Add(1 * time.Hour), // This should be ignored during TS comparisons
232+
commitTime: now.Add(10 * time.Minute),
233+
tagTime: now.Add(2 * time.Hour), // This should be ignored during TS comparisons
234234
},
235235
{
236236
tag: "v0.1.0+build-2",
237237
annotated: false,
238-
commitTime: now.Add(2 * time.Minute),
238+
commitTime: now.Add(30 * time.Minute),
239+
},
240+
{
241+
tag: "v0.1.0+build-3",
242+
annotated: true,
243+
commitTime: now.Add(1 * time.Hour),
244+
tagTime: now.Add(1 * time.Hour), // This should be ignored during TS comparisons
239245
},
240246
{
241247
tag: "0.2.0",
@@ -258,7 +264,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) {
258264
{
259265
name: "Orders by SemVer and timestamp",
260266
constraint: "<0.2.0",
261-
expectTag: "v0.1.0+build-2",
267+
expectTag: "v0.1.0+build-3",
262268
},
263269
{
264270
name: "Errors without match",

0 commit comments

Comments
 (0)