MCPcopy Create free account
hub / github.com/cli/cli / TestClientCommitsExcludesBaseSideCommits

Function TestClientCommitsExcludesBaseSideCommits

git/client_test.go:428–454  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

426}
427
428func 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
456func TestClientCommitsReturnsOnlyOrdinaryFeatureSideCommits(t *testing.T) {
457 // Given a feature branch that merges a side branch

Callers

nothing calls this directly

Calls 6

newTestRepoFunction · 0.85
WriteFileMethod · 0.80
JoinMethod · 0.80
EqualMethod · 0.80
CommitsMethod · 0.65
runMethod · 0.45

Tested by

no test coverage detected