From 50b2762dca9fcfc52a961fd3b0a1c7d800e9f548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sat, 14 Jun 2025 13:03:04 +0200 Subject: [PATCH] fix: missing push when files were changed (#193) The whole check to avoid pushes when they were only rebases was broken and compared the wrong things. Unfortunately this worked for nearly all unit tests, except for one were I used the wrong assertion. This fixed the check by comparing the right things and inverting the assertion in the unit test to make sure things do not break again in the future. Bug was introduced in #114. --- internal/git/git.go | 4 ++-- internal/git/git_test.go | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/git/git.go b/internal/git/git.go index 136a828..d1db11b 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -233,7 +233,7 @@ func (r *Repository) hasChangesWithRemote(ctx context.Context, mainBranchRef, lo return false, nil } - remoteDiff, err := commitOnRemotePRBranch.PatchContext(ctx, currentRemotePRMergeBase) + remoteDiff, err := currentRemotePRMergeBase.PatchContext(ctx, commitOnRemotePRBranch) if err != nil { return false, err } @@ -248,7 +248,7 @@ func (r *Repository) hasChangesWithRemote(ctx context.Context, mainBranchRef, lo return false, err } - return remoteDiff.String() == localDiff.String(), nil + return remoteDiff.String() != localDiff.String(), nil } func (r *Repository) commitFromRef(refName plumbing.ReferenceName) (*object.Commit, error) { diff --git a/internal/git/git_test.go b/internal/git/git_test.go index 3d05538..bf300df 100644 --- a/internal/git/git_test.go +++ b/internal/git/git_test.go @@ -147,15 +147,17 @@ func TestRepository_HasChangesWithRemote(t *testing.T) { OnBranch(mainBranchRef), AsNewBranch(remotePRBranchRef), WithFile("VERSION", "v1.1.0"), + WithFile("CHANGELOG.md", "Foo"), ), WithCommit( - "chore: release v1.2.0", + "chore: release v1.1.0", OnBranch(mainBranchRef), AsNewBranch(localPRBranchRef), - WithFile("VERSION", "v1.2.0"), + WithFile("VERSION", "v1.1.0"), + WithFile("CHANGELOG.md", "FooBar"), ), ), - want: false, + want: true, wantErr: assert.NoError, }, }