| 426 | } |
| 427 | |
| 428 | func TestClientCommitsExcludesBaseSideCommits(t *testing.T) { |
| 429 | // Given divergent branches with patch-equivalent commits and one unique feature commit |
| 430 | repo := newTestRepo(t) |
| 431 | repo.run(t, "commit", "--quiet", "--allow-empty", "-m", "initial commit") |
| 432 | repo.run(t, "checkout", "--quiet", "-b", "feature") |
| 433 | require.NoError(t, os.WriteFile(filepath.Join(repo.dir, "shared.txt"), []byte("shared\n"), 0600)) |
| 434 | repo.run(t, "add", "shared.txt") |
| 435 | t.Setenv("GIT_COMMITTER_DATE", "2000-01-01T00:00:00Z") |
| 436 | repo.run(t, "commit", "--quiet", "-m", "feature shared change") |
| 437 | sharedCommit := repo.run(t, "rev-parse", "HEAD") |
| 438 | repo.run(t, "commit", "--quiet", "--allow-empty", "-m", "feature-only commit") |
| 439 | uniqueCommit := repo.run(t, "rev-parse", "HEAD") |
| 440 | repo.run(t, "checkout", "--quiet", "trunk") |
| 441 | // A different committer date gives the cherry-picked commit a distinct hash. |
| 442 | t.Setenv("GIT_COMMITTER_DATE", "2001-01-01T00:00:00Z") |
| 443 | repo.run(t, "cherry-pick", sharedCommit) |
| 444 | |
| 445 | // When commits unique to the feature branch are requested |
| 446 | commits, err := repo.client.Commits(t.Context(), "trunk", "feature") |
| 447 | |
| 448 | // Then only the feature side of the symmetric difference is returned |
| 449 | require.NoError(t, err) |
| 450 | assert.Equal(t, []*Commit{ |
| 451 | {Sha: uniqueCommit, Title: "feature-only commit"}, |
| 452 | {Sha: sharedCommit, Title: "feature shared change"}, |
| 453 | }, commits) |
| 454 | } |
| 455 | |
| 456 | func TestClientCommitsReturnsOnlyOrdinaryFeatureSideCommits(t *testing.T) { |
| 457 | // Given a feature branch that merges a side branch |