From 42d3a37026616a8cb3a9da11ab8e5565ca6b6074 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 14 Oct 2024 18:09:10 +0200 Subject: pkg/vcs: change HeadCommit to Commit Currently we have HeadCommit function that returns info about the HEAD commit. Change it to a more flexible Commit function that can return info about any commit. This will be used in future changes. --- pkg/vcs/git_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'pkg/vcs/git_test.go') diff --git a/pkg/vcs/git_test.go b/pkg/vcs/git_test.go index 73670dd4a..8ff4dbb6e 100644 --- a/pkg/vcs/git_test.go +++ b/pkg/vcs/git_test.go @@ -186,7 +186,7 @@ func TestGetCommitsByTitles(t *testing.T) { repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "abc") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - commitA, _ := repo.repo.HeadCommit() + commitA, _ := repo.repo.Commit(HEAD) results, missing, err := repo.repo.GetCommitsByTitles([]string{"target"}) validateSuccess(commitA, results, missing, err) @@ -222,7 +222,7 @@ func TestContains(t *testing.T) { // We expect Contains to return true, if commit is in current checkout. repo.Git("checkout", "-b", "branch-a") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - commitA, _ := repo.repo.HeadCommit() + commitA, _ := repo.repo.Commit(HEAD) if contained, _ := repo.repo.Contains(commitA.Hash); !contained { t.Fatalf("contains claims commit that should be present is not") } @@ -233,7 +233,7 @@ func TestContains(t *testing.T) { // Commits must only be searched for from the checkedout HEAD. repo.Git("checkout", "-b", "branch-b") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - commitB, _ := repo.repo.HeadCommit() + commitB, _ := repo.repo.Commit(HEAD) repo.Git("checkout", "branch-a") if contained, _ := repo.repo.Contains(commitB.Hash); contained { t.Fatalf("contains found commit that is not in current branch") @@ -325,12 +325,12 @@ func TestMergeBase(t *testing.T) { // Create base branch. repo.Git("checkout", "-b", "base") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - baseCommit, _ := repo.repo.HeadCommit() + baseCommit, _ := repo.repo.Commit(HEAD) // Fork off another branch. repo.Git("checkout", "-b", "fork") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - forkCommit, _ := repo.repo.HeadCommit() + forkCommit, _ := repo.repo.Commit(HEAD) // Ensure that merge base points to the base commit. mergeCommits, err := repo.repo.MergeBases(baseCommit.Hash, forkCommit.Hash) @@ -343,11 +343,11 @@ func TestMergeBase(t *testing.T) { // Let branches diverge. repo.Git("checkout", "base") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "newBase") - newBaseCommit, _ := repo.repo.HeadCommit() + newBaseCommit, _ := repo.repo.Commit(HEAD) repo.Git("checkout", "fork") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "newFork") - newForkCommit, _ := repo.repo.HeadCommit() + newForkCommit, _ := repo.repo.Commit(HEAD) // The merge base should remain the same. mergeCommits, err = repo.repo.MergeBases(newBaseCommit.Hash, newForkCommit.Hash) @@ -363,7 +363,7 @@ func TestMergeBase(t *testing.T) { // And advance the fork branch. repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - newNewForkCommit, _ := repo.repo.HeadCommit() + newNewForkCommit, _ := repo.repo.Commit(HEAD) // The merge base should point to the last commit in `base`. mergeCommits, err = repo.repo.MergeBases(newBaseCommit.Hash, newNewForkCommit.Hash) @@ -387,7 +387,7 @@ func TestGitCustomRefs(t *testing.T) { remote.Git("commit", "--no-edit", "--allow-empty", "-m", "detached commit") // Add a ref to prevent the commit from getting garbage collected. remote.Git("update-ref", "refs/custom/test", "temp_branch") - refCommit, _ := remote.repo.HeadCommit() + refCommit, _ := remote.repo.Commit(HEAD) // Remove the branch, let the commit stay only in refs. remote.Git("checkout", "base_branch") @@ -435,7 +435,7 @@ func TestGitFetchShortHash(t *testing.T) { remote.Git("tag", "base_tag") remote.Git("checkout", "-b", "temp_branch") remote.Git("commit", "--no-edit", "--allow-empty", "-m", "detached commit") - refCommit, _ := remote.repo.HeadCommit() + refCommit, _ := remote.repo.Commit(HEAD) // Create a local repo. localRepoDir := t.TempDir() -- cgit mrf-deployment