syntax = "proto3";
package rpc;

option go_package = "github.com/harness/gitness/gitrpc/rpc";

import "shared.proto";

// DiffService is a service which provides RPCs to inspect differences
// introduced between a set of commits.
service MergeService {
  rpc Merge(MergeRequest) returns (MergeResponse) {}
}


message MergeRequest {
  enum MergeMethod {
    merge =  0;
    squash = 1;
    rebase = 2;
  }
  WriteRequest base = 1;
  // head_branch is the source branch we want to merge
  string head_branch = 2;
  // base_branch is the branch into which the given commit shall be merged and whose
  // reference is going to be updated.
  string base_branch = 3;
  // title is the title to use for the merge commit.
  string title = 4;
  // message is the message to use for the merge commit.
  string message = 5;
  // author is the person who originally wrote the code
  Identity author = 6;
  // committer is the person who last applied the patch
  Identity committer = 7;

  // ref_type is an otional value and is used to generate the full
  // reference in which the merge result is stored.
  RefType ref_type  = 8;
  // ref_name is an otional value and is used to generate the full
  // reference in which the merge result is stored.
  string ref_name  = 9;

  // head_expected_sha is commit sha on the head branch, if head_expected_sha is older
  // than the head_branch latest sha then merge will fail.
  string head_expected_sha = 10;

  // force merge
  bool force = 11;
  // delete branch after merge
  bool delete_head_branch = 12;
  // merging method
  MergeMethod method      = 13;
}

message MergeResponse {
  // base_sha is the sha of the latest commit on the base branch that was used for merging.
  string base_sha = 1;
  // head_sha is the sha of the latest commit on the head branch that was used for merging.
  string head_sha = 2;
  // merge_base_sha is the sha of the merge base of the head_sha and base_sha
  string merge_base_sha = 3;
  // merge_sha is the sha of the commit after merging head_sha with base_sha.
  string merge_sha = 4;
}

// MergeConflictError is an error returned in the case when merging two commits
// fails due to a merge conflict.
message MergeConflictError {
  // ConflictingFiles is the set of files which have been conflicting.
  repeated string conflicting_files = 1;
}