From cafb2aee6a952c52e20e7ddbbfbbf2afccfc9cb6 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Fri, 3 Mar 2023 11:50:21 -0500 Subject: [PATCH 1/4] fix: add time constraint for itterator Signed-off-by: Christopher Phillips --- internal/git/tag.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/git/tag.go b/internal/git/tag.go index 2a7048a..0996238 100644 --- a/internal/git/tag.go +++ b/internal/git/tag.go @@ -41,12 +41,24 @@ func CommitsBetween(repoPath string, cfg Range) ([]string, error) { } } + var sinceTime time.Time + if sinceHash != nil { + c, err := r.CommitObject(*sinceHash) + if err != nil { + return nil, fmt.Errorf("unable to find since git commit=%q: %w", sinceHash, err) + } + sinceTime = c.Committer.When + } + untilHash, err := r.ResolveRevision(plumbing.Revision(cfg.UntilRef)) if err != nil { return nil, fmt.Errorf("unable to find until git ref=%q: %w", cfg.UntilRef, err) } - iter, err := r.Log(&git.LogOptions{From: *untilHash}) + iter, err := r.Log(&git.LogOptions{ + From: *untilHash, + Since: &sinceTime, + }) if err != nil { return nil, fmt.Errorf("unable to find until git log for ref=%q: %w", cfg.UntilRef, err) } From d34e7df5cf247fd8e69e59ce13ecfb116de98287 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Fri, 3 Mar 2023 11:53:09 -0500 Subject: [PATCH 2/4] fix: return retErr Signed-off-by: Christopher Phillips --- internal/git/tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/git/tag.go b/internal/git/tag.go index 0996238..2fa0b42 100644 --- a/internal/git/tag.go +++ b/internal/git/tag.go @@ -83,7 +83,7 @@ func CommitsBetween(repoPath string, cfg Range) ([]string, error) { commits = append(commits, hash) } - return + return retErr }) return commits, err From dc0b45d2904965d542b524eb6933fa3b0452e142 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Fri, 3 Mar 2023 12:32:37 -0500 Subject: [PATCH 3/4] chore: add test confirming filter Signed-off-by: Christopher Phillips --- internal/git/tag.go | 2 +- internal/git/tag_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/git/tag.go b/internal/git/tag.go index 2fa0b42..0996238 100644 --- a/internal/git/tag.go +++ b/internal/git/tag.go @@ -83,7 +83,7 @@ func CommitsBetween(repoPath string, cfg Range) ([]string, error) { commits = append(commits, hash) } - return retErr + return }) return commits, err diff --git a/internal/git/tag_test.go b/internal/git/tag_test.go index cd19007..9c4296d 100644 --- a/internal/git/tag_test.go +++ b/internal/git/tag_test.go @@ -133,6 +133,17 @@ func TestCommitsBetween(t *testing.T) { }, count: 5, }, + { + name: "include start and end; filter by time", + path: "test-fixtures/repos/tag-range-repo", + config: Range{ + SinceRef: "v0.1.1", + UntilRef: "v0.2.0", + IncludeStart: true, + IncludeEnd: true, + }, + count: 4, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { From 9fa9444a168bae013e4898cf3ad8614648679fb0 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Fri, 3 Mar 2023 13:41:04 -0500 Subject: [PATCH 4/4] fix: update branch error for tag range Signed-off-by: Christopher Phillips --- internal/git/tag.go | 8 ++++++-- internal/git/tag_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/git/tag.go b/internal/git/tag.go index 0996238..8fd0dcb 100644 --- a/internal/git/tag.go +++ b/internal/git/tag.go @@ -1,6 +1,7 @@ package git import ( + "errors" "fmt" "io" "time" @@ -56,9 +57,9 @@ func CommitsBetween(repoPath string, cfg Range) ([]string, error) { } iter, err := r.Log(&git.LogOptions{ - From: *untilHash, - Since: &sinceTime, + From: *untilHash, }) + // BRANCH ------> 0 ---> Tip of Main if err != nil { return nil, fmt.Errorf("unable to find until git log for ref=%q: %w", cfg.UntilRef, err) } @@ -79,6 +80,9 @@ func CommitsBetween(repoPath string, cfg Range) ([]string, error) { if cfg.IncludeStart { commits = append(commits, hash) } + case sinceTime.Before(c.Committer.When): + log.Errorf("found commit=%q before finding commit=%q at time=%q", hash, sinceHash, sinceTime) + retErr = errors.New("the previous release is probably on a different branch") default: commits = append(commits, hash) } diff --git a/internal/git/tag_test.go b/internal/git/tag_test.go index 9c4296d..30efdc4 100644 --- a/internal/git/tag_test.go +++ b/internal/git/tag_test.go @@ -150,7 +150,7 @@ func TestCommitsBetween(t *testing.T) { actual, err := CommitsBetween(test.path, test.config) require.NoError(t, err) - // the answer is based off the the current (dynamically created) git log test fixture + // the answer is based off the current (dynamically created) git log test fixture expected := gitLogRange(t, test.path, test.config.SinceRef, test.config.UntilRef) require.NotEmpty(t, expected)