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:
authorPaul Okstad <pokstad@gitlab.com>2020-11-04 07:11:23 +0300
committerPaul Okstad <pokstad@gitlab.com>2020-11-04 07:11:23 +0300
commit95fab045b6c1b6fa8100a67dc5cee7e02fa8384e (patch)
treef315ce22ca9b1ef908ffbc62c820589c96a857d8 /internal/git2go
parent7785c65515161d76f6c5448ae663d3472c879b1d (diff)
Resolve conflicts git2go subcommand
The new "resolve" subcommand duplicates most of the Ruby functionality using the git2go library. This includes: - Attempts a merge commit - Iterates over the conflicts remaining in the index - For each conflict, applies the provided resolutions - Fails if any conflicts are unresolved - Creates a commit in the source repository - Returns this commit to the caller
Diffstat (limited to 'internal/git2go')
-rw-r--r--internal/git2go/resolve_conflicts.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/internal/git2go/resolve_conflicts.go b/internal/git2go/resolve_conflicts.go
new file mode 100644
index 000000000..42d9bf642
--- /dev/null
+++ b/internal/git2go/resolve_conflicts.go
@@ -0,0 +1,66 @@
+package git2go
+
+import (
+ "context"
+ "fmt"
+ "io"
+
+ "gitlab.com/gitlab-org/gitaly/internal/git/conflict"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+)
+
+// ResolveCommand contains arguments to perform a merge commit and resolve any
+// conflicts produced from that merge commit
+type ResolveCommand struct {
+ MergeCommand `json:"merge_command"`
+ Resolutions []conflict.Resolution `json:"conflict_files"`
+}
+
+// ResolveResult returns information about the successful merge and resolution
+type ResolveResult struct {
+ MergeResult `json:"merge_result"`
+}
+
+// ResolveResolveCommandFromSerialized deserializes a ResolveCommand and
+// verifies the arguments are valid
+func ResolveCommandFromSerialized(serialized string) (ResolveCommand, error) {
+ var request ResolveCommand
+ if err := deserialize(serialized, &request); err != nil {
+ return ResolveCommand{}, err
+ }
+
+ if err := request.verify(); err != nil {
+ return ResolveCommand{}, fmt.Errorf("resolve: %w: %s", ErrInvalidArgument, err.Error())
+ }
+
+ return request, nil
+}
+
+// Run will attempt merging and resolving conflicts for the provided request
+func (r ResolveCommand) Run(ctx context.Context, cfg config.Cfg) (ResolveResult, error) {
+ if err := r.verify(); err != nil {
+ return ResolveResult{}, fmt.Errorf("resolve: %w: %s", ErrInvalidArgument, err.Error())
+ }
+
+ serialized, err := serialize(r)
+ if err != nil {
+ return ResolveResult{}, err
+ }
+
+ stdout, err := run(ctx, binaryPathFromCfg(cfg), nil, "resolve", "-request", serialized)
+ if err != nil {
+ return ResolveResult{}, err
+ }
+
+ var response ResolveResult
+ if err := deserialize(stdout.String(), &response); err != nil {
+ return ResolveResult{}, err
+ }
+
+ return response, nil
+}
+
+// SerializeTo serializes the resolve conflict and writes it to the writer
+func (r ResolveResult) SerializeTo(w io.Writer) error {
+ return serializeTo(w, r)
+}