diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-26 10:09:33 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-26 10:31:08 +0300 |
commit | 96ac33ef6eb440d4a1c1b49776c11253dba69764 (patch) | |
tree | 3e0ce1582480efb14cc16f2e7528b282287702f9 | |
parent | 16af76ac3004eee3ed9a92e19b3769e73f610088 (diff) |
operations: Wire up AllowConflicts handling for Go
Originally, handling of the "AllowConflicts" parameter for the
UserMergeToRef RPC was only implemented in Ruby and not in Go because
efforts to port to Go and to implement this new flag crossed. This has
changed with the previous commit so that we can now switch over to fully
use the Go port instead of the Ruby code in all cases.
Note that this directly removes the Ruby codepath without any kind of
feature flag. This is done because first, the UserMergeToRef RPC has
been tested already and rolled out by default. And second, all callers
in GitLab Rails which make use of "AllowConflicts" are already hidden
behind the "display_merge_conflicts_in_diff" feature flag which is
currently disabled by default. Introducing another feature flag for this
parameter thus doesn't seem necessary.
-rw-r--r-- | changelogs/unreleased/pks-go-user-merge-to-ref-allow-conflicts.yml | 5 | ||||
-rw-r--r-- | internal/gitaly/service/operations/merge.go | 47 |
2 files changed, 19 insertions, 33 deletions
diff --git a/changelogs/unreleased/pks-go-user-merge-to-ref-allow-conflicts.yml b/changelogs/unreleased/pks-go-user-merge-to-ref-allow-conflicts.yml new file mode 100644 index 000000000..08033751f --- /dev/null +++ b/changelogs/unreleased/pks-go-user-merge-to-ref-allow-conflicts.yml @@ -0,0 +1,5 @@ +--- +title: 'operations: Wire up AllowConflicts handling for Go' +merge_request: 2997 +author: +type: added diff --git a/internal/gitaly/service/operations/merge.go b/internal/gitaly/service/operations/merge.go index 21fefd5a7..4ceb8be2b 100644 --- a/internal/gitaly/service/operations/merge.go +++ b/internal/gitaly/service/operations/merge.go @@ -235,10 +235,14 @@ func validateUserMergeToRefRequest(in *gitalypb.UserMergeToRefRequest) error { return nil } -// userMergeToRef overwrites the given TargetRef to point to either Branch or +// UserMergeToRef overwrites the given TargetRef to point to either Branch or // FirstParentRef. Afterwards, it performs a merge of SourceSHA with either // Branch or FirstParentRef and updates TargetRef to the merge commit. -func (s *Server) userMergeToRef(ctx context.Context, request *gitalypb.UserMergeToRefRequest) (*gitalypb.UserMergeToRefResponse, error) { +func (s *Server) UserMergeToRef(ctx context.Context, request *gitalypb.UserMergeToRefRequest) (*gitalypb.UserMergeToRefResponse, error) { + if err := validateUserMergeToRefRequest(request); err != nil { + return nil, helper.ErrInvalidArgument(err) + } + repoPath, err := s.locator.GetPath(request.Repository) if err != nil { return nil, err @@ -278,13 +282,14 @@ func (s *Server) userMergeToRef(ctx context.Context, request *gitalypb.UserMerge // Now, we create the merge commit... merge, err := git2go.MergeCommand{ - Repository: repoPath, - AuthorName: string(request.User.Name), - AuthorMail: string(request.User.Email), - AuthorDate: authorDate, - Message: string(request.Message), - Ours: oid.String(), - Theirs: sourceRef.String(), + Repository: repoPath, + AuthorName: string(request.User.Name), + AuthorMail: string(request.User.Email), + AuthorDate: authorDate, + Message: string(request.Message), + Ours: oid.String(), + Theirs: sourceRef.String(), + AllowConflicts: request.AllowConflicts, }.Run(ctx, s.cfg) if err != nil { if errors.Is(err, git2go.ErrInvalidArgument) { @@ -310,30 +315,6 @@ func (s *Server) userMergeToRef(ctx context.Context, request *gitalypb.UserMerge }, nil } -func (s *Server) UserMergeToRef(ctx context.Context, in *gitalypb.UserMergeToRefRequest) (*gitalypb.UserMergeToRefResponse, error) { - if err := validateUserMergeToRefRequest(in); err != nil { - return nil, helper.ErrInvalidArgument(err) - } - - // Ruby has grown a new feature since being ported to Go, and we don't - // handle that yet. - if !in.AllowConflicts { - return s.userMergeToRef(ctx, in) - } - - client, err := s.ruby.OperationServiceClient(ctx) - if err != nil { - return nil, helper.ErrInternal(err) - } - - clientCtx, err := rubyserver.SetHeaders(ctx, s.locator, in.GetRepository()) - if err != nil { - return nil, err - } - - return client.UserMergeToRef(clientCtx, in) -} - func isAncestor(ctx context.Context, repo repository.GitRepo, ancestor, descendant string) (bool, error) { cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "merge-base", |