From 4c94f88ebb6d42a8e23542b9d231e7c16a13c5a6 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Fri, 22 Oct 2021 13:19:34 +0200 Subject: [PATCH 1/2] libgit2: ensure original tag is used for TS lookup This adds an additional selection candidate, to ensure test flakiness happens more often. Signed-off-by: Hidde Beydals --- pkg/git/libgit2/checkout.go | 2 +- pkg/git/libgit2/checkout_test.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/git/libgit2/checkout.go b/pkg/git/libgit2/checkout.go index 7fcfe4512..5fe28e92d 100644 --- a/pkg/git/libgit2/checkout.go +++ b/pkg/git/libgit2/checkout.go @@ -225,7 +225,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g // versions into a chronological order. This is especially important for // versions that differ only by build metadata, because it is not considered // a part of the comparable version in Semver - return tagTimestamps[left.String()].Before(tagTimestamps[right.String()]) + return tagTimestamps[left.Original()].Before(tagTimestamps[right.Original()]) }) v := matchedVersions[len(matchedVersions)-1] t := v.Original() diff --git a/pkg/git/libgit2/checkout_test.go b/pkg/git/libgit2/checkout_test.go index 5ad2b2523..b7bf92935 100644 --- a/pkg/git/libgit2/checkout_test.go +++ b/pkg/git/libgit2/checkout_test.go @@ -229,13 +229,19 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) { { tag: "v0.1.0+build-1", annotated: true, - commitTime: now.Add(1 * time.Minute), - tagTime: now.Add(1 * time.Hour), // This should be ignored during TS comparisons + commitTime: now.Add(10 * time.Minute), + tagTime: now.Add(2 * time.Hour), // This should be ignored during TS comparisons }, { tag: "v0.1.0+build-2", annotated: false, - commitTime: now.Add(2 * time.Minute), + commitTime: now.Add(30 * time.Minute), + }, + { + tag: "v0.1.0+build-3", + annotated: true, + commitTime: now.Add(1 * time.Hour), + tagTime: now.Add(1 * time.Hour), // This should be ignored during TS comparisons }, { tag: "0.2.0", @@ -258,7 +264,7 @@ func TestCheckoutTagSemVer_Checkout(t *testing.T) { { name: "Orders by SemVer and timestamp", constraint: "<0.2.0", - expectTag: "v0.1.0+build-2", + expectTag: "v0.1.0+build-3", }, { name: "Errors without match", From 9ff533468893f3fd3513cf824f02e81e377777e2 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Fri, 22 Oct 2021 13:25:24 +0200 Subject: [PATCH 2/2] go-git: ensure original tag is used for TS lookup Signed-off-by: Hidde Beydals --- pkg/git/gogit/checkout.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/git/gogit/checkout.go b/pkg/git/gogit/checkout.go index fdf910271..e767b37a2 100644 --- a/pkg/git/gogit/checkout.go +++ b/pkg/git/gogit/checkout.go @@ -212,7 +212,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g } var matchedVersions semver.Collection - for tag, _ := range tags { + for tag := range tags { v, err := version.ParseVersion(tag) if err != nil { continue @@ -239,7 +239,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g // versions into a chronological order. This is especially important for // versions that differ only by build metadata, because it is not considered // a part of the comparable version in Semver - return tagTimestamps[left.String()].Before(tagTimestamps[right.String()]) + return tagTimestamps[left.Original()].Before(tagTimestamps[right.Original()]) }) v := matchedVersions[len(matchedVersions)-1] t := v.Original()