aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs/git_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-10-14 18:09:10 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-10-15 09:08:36 +0000
commit42d3a37026616a8cb3a9da11ab8e5565ca6b6074 (patch)
tree6be4d678b1a05ef78450a4e9133eba3590509589 /pkg/vcs/git_test.go
parent7eb57b4aa460c38365f8c5aa77d06c3b750daa4b (diff)
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.
Diffstat (limited to 'pkg/vcs/git_test.go')
-rw-r--r--pkg/vcs/git_test.go20
1 files changed, 10 insertions, 10 deletions
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()