From 87efbd7e6a782f64c01d57dcb2acf06bb943502e Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 9 Nov 2020 12:29:20 +0100 Subject: git2go: Allow building commits with multiple parents Our git2go testhelper which creates commits for us currently only accepts a single parent for the created commit. As we're about to use this function for generating criss-cross merges, let's expand it to accept multiple parents as a preparatory step. --- cmd/gitaly-git2go/conflicts/conflicts_test.go | 5 +++-- cmd/gitaly-git2go/merge_test.go | 6 +++--- cmd/gitaly-git2go/revert_test.go | 8 ++++---- cmd/gitaly-git2go/testhelper/testhelper.go | 8 ++------ 4 files changed, 12 insertions(+), 15 deletions(-) (limited to 'cmd/gitaly-git2go') diff --git a/cmd/gitaly-git2go/conflicts/conflicts_test.go b/cmd/gitaly-git2go/conflicts/conflicts_test.go index a91a73027..31db7c6c2 100644 --- a/cmd/gitaly-git2go/conflicts/conflicts_test.go +++ b/cmd/gitaly-git2go/conflicts/conflicts_test.go @@ -6,6 +6,7 @@ import ( "os" "testing" + git "github.com/libgit2/git2go/v30" "github.com/stretchr/testify/require" cmdtesthelper "gitlab.com/gitlab-org/gitaly/cmd/gitaly-git2go/testhelper" "gitlab.com/gitlab-org/gitaly/internal/git2go" @@ -180,8 +181,8 @@ func TestConflicts(t *testing.T) { defer cleanup() base := cmdtesthelper.BuildCommit(t, repoPath, nil, tc.base) - ours := cmdtesthelper.BuildCommit(t, repoPath, base, tc.ours) - theirs := cmdtesthelper.BuildCommit(t, repoPath, base, tc.theirs) + ours := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{base}, tc.ours) + theirs := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{base}, tc.theirs) t.Run(tc.desc, func(t *testing.T) { ctx, cancel := testhelper.Context() diff --git a/cmd/gitaly-git2go/merge_test.go b/cmd/gitaly-git2go/merge_test.go index 0a2b6bbab..53f3ef3aa 100644 --- a/cmd/gitaly-git2go/merge_test.go +++ b/cmd/gitaly-git2go/merge_test.go @@ -174,9 +174,9 @@ func TestMergeTrees(t *testing.T) { _, repoPath, cleanup := testhelper.NewTestRepo(t) defer cleanup() - base := cmdtesthelper.BuildCommit(t, repoPath, nil, tc.base) - ours := cmdtesthelper.BuildCommit(t, repoPath, base, tc.ours) - theirs := cmdtesthelper.BuildCommit(t, repoPath, base, tc.theirs) + base := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{nil}, tc.base) + ours := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{base}, tc.ours) + theirs := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{base}, tc.theirs) authorDate := time.Date(2020, 7, 30, 7, 45, 50, 0, time.FixedZone("UTC+2", +2*60*60)) diff --git a/cmd/gitaly-git2go/revert_test.go b/cmd/gitaly-git2go/revert_test.go index 790ad585d..0010aab0b 100644 --- a/cmd/gitaly-git2go/revert_test.go +++ b/cmd/gitaly-git2go/revert_test.go @@ -88,11 +88,11 @@ func TestRevert_trees(t *testing.T) { "a": "apple", "b": "banana", }) - revertOid := cmdtesthelper.BuildCommit(t, repoPath, baseOid, map[string]string{ + revertOid := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{baseOid}, map[string]string{ "a": "apple", "b": "pineapple", }) - oursOid := cmdtesthelper.BuildCommit(t, repoPath, revertOid, map[string]string{ + oursOid := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{revertOid}, map[string]string{ "a": "apple", "b": "pineapple", "c": "carrot", @@ -113,10 +113,10 @@ func TestRevert_trees(t *testing.T) { baseOid := cmdtesthelper.BuildCommit(t, repoPath, nil, map[string]string{ "a": "apple", }) - revertOid := cmdtesthelper.BuildCommit(t, repoPath, baseOid, map[string]string{ + revertOid := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{baseOid}, map[string]string{ "a": "pineapple", }) - oursOid := cmdtesthelper.BuildCommit(t, repoPath, revertOid, map[string]string{ + oursOid := cmdtesthelper.BuildCommit(t, repoPath, []*git.Oid{revertOid}, map[string]string{ "a": "carrot", }) diff --git a/cmd/gitaly-git2go/testhelper/testhelper.go b/cmd/gitaly-git2go/testhelper/testhelper.go index 3a7a24b0d..44741c195 100644 --- a/cmd/gitaly-git2go/testhelper/testhelper.go +++ b/cmd/gitaly-git2go/testhelper/testhelper.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" ) -func BuildCommit(t testing.TB, repoPath string, parent *git.Oid, fileContents map[string]string) *git.Oid { +func BuildCommit(t testing.TB, repoPath string, parents []*git.Oid, fileContents map[string]string) *git.Oid { repo, err := git.OpenRepository(repoPath) require.NoError(t, err) defer repo.Free() @@ -37,11 +37,7 @@ func BuildCommit(t testing.TB, repoPath string, parent *git.Oid, fileContents ma } var commit *git.Oid - if parent != nil { - commit, err = repo.CreateCommitFromIds("", &committer, &committer, "Message", tree, parent) - } else { - commit, err = repo.CreateCommitFromIds("", &committer, &committer, "Message", tree) - } + commit, err = repo.CreateCommitFromIds("", &committer, &committer, "Message", tree, parents...) require.NoError(t, err) return commit -- cgit v1.2.3