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
path: root/cmd
diff options
context:
space:
mode:
authorPiotr Stankowski <git@trakos.pl>2022-01-10 17:30:03 +0300
committerPiotr Stankowski <git@trakos.pl>2022-03-07 22:25:08 +0300
commit1d72d52eb7743c84b268e0fe9aceaed5c4f56b88 (patch)
tree70647b8f678f28899b1c0afeea397438358af7e8 /cmd
parentf6c210fc5a0642d02aff0ed2dda543749778aa9c (diff)
git2go: Add optional Committer to MergeCommand
Squash commits in GitLab use different committer and author. Committer is the user that merges, and author is the user that created the MR. As we want to add squashing to this command, we have to make sure that we support Committer* arguments as well. Committer variables are optional, author data is used when they are empty. That way this change is backward compatible. However, if at least one of Committer* variables are set, all of them have to be.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gitaly-git2go/merge.go9
-rw-r--r--cmd/gitaly-git2go/merge_test.go47
2 files changed, 52 insertions, 4 deletions
diff --git a/cmd/gitaly-git2go/merge.go b/cmd/gitaly-git2go/merge.go
index 541cecf84..f97125061 100644
--- a/cmd/gitaly-git2go/merge.go
+++ b/cmd/gitaly-git2go/merge.go
@@ -92,8 +92,13 @@ func merge(request git2go.MergeCommand) (string, error) {
return "", fmt.Errorf("could not write tree: %w", err)
}
- committer := git.Signature(git2go.NewSignature(request.AuthorName, request.AuthorMail, request.AuthorDate))
- commit, err := repo.CreateCommitFromIds("", &committer, &committer, request.Message, tree, ours.Id(), theirs.Id())
+ author := git.Signature(git2go.NewSignature(request.AuthorName, request.AuthorMail, request.AuthorDate))
+ committer := author
+ if request.CommitterMail != "" {
+ committer = git.Signature(git2go.NewSignature(request.CommitterName, request.CommitterMail, request.CommitterDate))
+ }
+
+ commit, err := repo.CreateCommitFromIds("", &author, &committer, request.Message, tree, ours.Id(), theirs.Id())
if err != nil {
return "", fmt.Errorf("could not create merge commit: %w", err)
}
diff --git a/cmd/gitaly-git2go/merge_test.go b/cmd/gitaly-git2go/merge_test.go
index c63650fc6..b9fff3f6e 100644
--- a/cmd/gitaly-git2go/merge_test.go
+++ b/cmd/gitaly-git2go/merge_test.go
@@ -65,6 +65,22 @@ func TestMerge_missingArguments(t *testing.T) {
request: git2go.MergeCommand{Repository: repoPath, AuthorName: "Foo", AuthorMail: "foo@example.com", Message: "Foo", Ours: "HEAD"},
expectedErr: "merge: invalid parameters: missing theirs",
},
+ // Committer* arguments are required only when at least one of them is non-empty
+ {
+ desc: "missing committer mail",
+ request: git2go.MergeCommand{Repository: repoPath, AuthorName: "Foo", AuthorMail: "foo@example.com", CommitterName: "Bar", Message: "Foo", Theirs: "HEAD", Ours: "HEAD"},
+ expectedErr: "merge: invalid parameters: missing committer mail",
+ },
+ {
+ desc: "missing committer name",
+ request: git2go.MergeCommand{Repository: repoPath, AuthorName: "Foo", AuthorMail: "foo@example.com", CommitterMail: "bar@example.com", Message: "Foo", Theirs: "HEAD", Ours: "HEAD"},
+ expectedErr: "merge: invalid parameters: missing committer name",
+ },
+ {
+ desc: "missing committer date",
+ request: git2go.MergeCommand{Repository: repoPath, AuthorName: "Foo", AuthorMail: "foo@example.com", CommitterName: "Bar", CommitterMail: "bar@example.com", Message: "Foo", Theirs: "HEAD", Ours: "HEAD"},
+ expectedErr: "merge: invalid parameters: missing committer date",
+ },
}
for _, tc := range testcases {
@@ -101,6 +117,7 @@ func TestMerge_trees(t *testing.T) {
ours map[string]string
theirs map[string]string
expected map[string]string
+ withCommitter bool
expectedResponse git2go.MergeResult
expectedErr error
}{
@@ -123,6 +140,25 @@ func TestMerge_trees(t *testing.T) {
},
},
{
+ desc: "trivial merge with different committer succeeds",
+ base: map[string]string{
+ "file": "a",
+ },
+ ours: map[string]string{
+ "file": "a",
+ },
+ theirs: map[string]string{
+ "file": "a",
+ },
+ expected: map[string]string{
+ "file": "a",
+ },
+ withCommitter: true,
+ expectedResponse: git2go.MergeResult{
+ CommitID: "cba8c5ddf5a5a24f2f606e4b62d348feb1214b70",
+ },
+ },
+ {
desc: "non-trivial merge succeeds",
base: map[string]string{
"file": "a\nb\nc\nd\ne\nf\n",
@@ -193,9 +229,10 @@ func TestMerge_trees(t *testing.T) {
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))
+ committerDate := time.Date(2021, 7, 30, 7, 45, 50, 0, time.FixedZone("UTC+2", +2*60*60))
t.Run(tc.desc, func(t *testing.T) {
- response, err := executor.Merge(ctx, repoProto, git2go.MergeCommand{
+ mergeCommand := git2go.MergeCommand{
Repository: repoPath,
AuthorName: "John Doe",
AuthorMail: "john.doe@example.com",
@@ -203,7 +240,13 @@ func TestMerge_trees(t *testing.T) {
Message: "Merge message",
Ours: ours.String(),
Theirs: theirs.String(),
- })
+ }
+ if tc.withCommitter {
+ mergeCommand.CommitterName = "Jane Doe"
+ mergeCommand.CommitterMail = "jane.doe@example.com"
+ mergeCommand.CommitterDate = committerDate
+ }
+ response, err := executor.Merge(ctx, repoProto, mergeCommand)
if tc.expectedErr != nil {
require.Equal(t, tc.expectedErr, err)