Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2023-07-05 14:14:59 +0300
committerToon Claes <toon@gitlab.com>2023-07-07 12:50:22 +0300
commit1a8786ef4e0f7e55ebbfe5bef7e79fa55e1a78e2 (patch)
tree2eace18cb7271be22390c471f08d0f68f1a2bec7
parent3fed9a081d09f26a2d3b197c71b818c5902059a6 (diff)
operations: Add test for cherry-picking merge commit
There wasn't any test coverage for cherry-picking a commit which has more than one parent. This change adds that. The added test has the following `git-log`: * 2905b7e (cherry-picking-dst) Cherry-picking a04f7be | create mode 100644 c | create mode 100644 d * a4da336 add zucchini | create mode 100644 z | * a04f7be merge coconut & dragon fruit into banana | |\ | | * 1a9b416 add dragon fruit | | | create mode 100644 d | | * 77b3f23 add coconut | |/ create mode 100644 c |/| | | | * ecd2b2c add banana |/ create mode 100644 b | * 80765b6 (HEAD -> main) add apple create mode 100644 a
-rw-r--r--internal/gitaly/service/operations/cherry_pick_test.go95
1 files changed, 93 insertions, 2 deletions
diff --git a/internal/gitaly/service/operations/cherry_pick_test.go b/internal/gitaly/service/operations/cherry_pick_test.go
index 8fdfaa648..6a2b35f24 100644
--- a/internal/gitaly/service/operations/cherry_pick_test.go
+++ b/internal/gitaly/service/operations/cherry_pick_test.go
@@ -415,6 +415,97 @@ func testServerUserCherryPickSuccessfulGitHooks(t *testing.T, ctx context.Contex
}
}
+func TestServer_UserCherryPick_mergeCommit(t *testing.T) {
+ t.Parallel()
+
+ testhelper.NewFeatureSets(
+ featureflag.CherryPickPureGit,
+ featureflag.GPGSigning,
+ ).Run(t, testServerUserCherryPickMergeCommit)
+}
+
+func testServerUserCherryPickMergeCommit(t *testing.T, ctx context.Context) {
+ t.Parallel()
+
+ skipSHA256WithGit2goCherryPick(t, ctx)
+
+ ctx, cfg, client := setupOperationsServiceWithoutRepo(t, ctx)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
+
+ baseCommitID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithBranch(git.DefaultBranch),
+ gittest.WithMessage("add apple"),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "apple"},
+ ),
+ )
+
+ leftCommitID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(baseCommitID),
+ gittest.WithMessage("add banana"),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "apple"},
+ gittest.TreeEntry{Mode: "100644", Path: "b", Content: "banana"},
+ ))
+ rightCommitID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(baseCommitID),
+ gittest.WithMessage("add coconut"),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "apple"},
+ gittest.TreeEntry{Mode: "100644", Path: "c", Content: "coconut"},
+ ))
+ rightCommitID = gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(rightCommitID),
+ gittest.WithMessage("add dragon fruit"),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "apple"},
+ gittest.TreeEntry{Mode: "100644", Path: "c", Content: "coconut"},
+ gittest.TreeEntry{Mode: "100644", Path: "d", Content: "dragon fruit"},
+ ))
+ cherryPickCommitID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(leftCommitID, rightCommitID),
+ gittest.WithMessage("merge coconut & dragon fruit into banana"),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "apple"},
+ gittest.TreeEntry{Mode: "100644", Path: "b", Content: "banana"},
+ gittest.TreeEntry{Mode: "100644", Path: "c", Content: "coconut"},
+ gittest.TreeEntry{Mode: "100644", Path: "d", Content: "dragon fruit"},
+ ))
+ cherryPickedCommit, err := repo.ReadCommit(ctx, cherryPickCommitID.Revision())
+ require.NoError(t, err)
+
+ destinationBranch := "cherry-picking-dst"
+ gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithParents(baseCommitID),
+ gittest.WithBranch(destinationBranch),
+ gittest.WithMessage("add zucchini"),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "apple"},
+ gittest.TreeEntry{Mode: "100644", Path: "z", Content: "zucchini"},
+ ),
+ )
+
+ request := &gitalypb.UserCherryPickRequest{
+ Repository: repoProto,
+ User: gittest.TestUser,
+ Commit: cherryPickedCommit,
+ BranchName: []byte(destinationBranch),
+ Message: []byte("Cherry-picking " + cherryPickedCommit.Id),
+ }
+
+ response, err := client.UserCherryPick(ctx, request)
+ require.NoError(t, err)
+
+ gittest.RequireTree(t, cfg, repoPath, response.BranchUpdate.CommitId,
+ []gittest.TreeEntry{
+ {Mode: "100644", Path: "a", Content: "apple"},
+ {Mode: "100644", Path: "c", Content: "coconut"},
+ {Mode: "100644", Path: "d", Content: "dragon fruit"},
+ {Mode: "100644", Path: "z", Content: "zucchini"},
+ })
+}
+
func TestServer_UserCherryPick_stableID(t *testing.T) {
t.Parallel()
@@ -1038,8 +1129,8 @@ func testServerUserCherryPickReverse(t *testing.T, ctx context.Context) {
{Mode: "100644", Path: "a", Content: "apple"},
{Mode: "100644", Path: "b", Content: "banana"},
// The above are in the destination, the below are committed one by one in the source
- {Mode: "100644", Path: "c", Content: "cherry"},
- {Mode: "100644", Path: "d", Content: "date"},
+ {Mode: "100644", Path: "c", Content: "coconut"},
+ {Mode: "100644", Path: "d", Content: "dragon fruit"},
{Mode: "100644", Path: "e", Content: "eggplant"},
{Mode: "100644", Path: "f", Content: "fig"},
}