syntax = "proto3";

package mesh.v1;

option go_package = "atlassian.com/bitbucket/mesh/rpc/v1";
option java_multiple_files = true;
option java_outer_classname = "GitErrorProtos";
option java_package = "com.atlassian.bitbucket.mesh.rpc.v1";

/* A top-level message for encoding an (optional) CommandSummary as well as
   an (optional) specific error payload. The error will have a summary or a
   specific error, at a minimum, and may have both. */
message RpcGitError {
  RpcFailedCommand failed_command = 1;

  oneof error_oneof {
    //ABORTED
    RpcNonFastForwardMerge non_fast_forward_merge = 28;
    RpcNonFastForwardUpdate non_fast_forward_update = 29;
    //AUTHENTICATION
    RpcRemoteAuthenticationFailed remote_authentication_failed = 39;
    //DEADLINE_EXCEEDED
    RpcCommandTimeout command_timeout = 55;
    //FAILED_PRECONDITION
    RpcDetachedHead detached_head = 13;
    RpcEmptyRebase empty_rebase = 34;
    RpcEmptyRebaseMerge empty_rebase_merge = 31;
    RpcEmptySquashMerge empty_squash_merge = 25;
    RpcIllegalTransactionState illegal_transaction_state = 56;
    RpcMergeFailed merge_failed = 27;
    RpcRebaseConflicted rebase_conflicted = 30;
    RpcRebaseFailed rebase_failed = 35;
    RpcUnsupportedOperation unsupported_operation = 53;
    RpcInvalidWorkTree invalid_work_tree = 62;
    RpcRevertFailed revert_failed = 66;
    RpcRevertConflicted revert_conflicted = 67;
    RpcRevertInvalidParentNumber revert_invalid_parent_number = 68;
    //INTERNAL
    RpcCreateRefFailed create_ref_failed = 5;
    RpcDeletePullRequestFailed delete_pull_request_failed = 59;
    RpcDeleteRefFailed delete_ref_failed = 61;
    RpcDisableTranscodeFailed disable_transcode_failed = 47;
    RpcEditFileFailed edit_file_failed = 38;
    RpcEnableRefLogFailed enable_ref_log_failed = 6;
    RpcEnableTranscodeFailed enable_transcode_failed = 46;
    RpcHookScriptWriteFailed hook_script_write_failed = 43;
    RpcLfsStorageFailed lfs_storage_failed = 51;
    RpcSetDefaultBranchFailed set_default_branch_failed = 7;
    RpcSetMetadataFailed set_metadata_failed = 60;
    RpcTransactionCommitFailed transaction_commit_failed = 57;
    RpcTransactionRollbackFailed transaction_rollback_failed = 58;
    RpcTranscodingFailed transcoding_failed = 36;
    RpcWorkTreeWriteFailed work_tree_write_failed = 63;
    //INVALID_ARGUMENT
    RpcBranchNotMerged branch_not_merged = 17;
    RpcInvalidBranchName invalid_branch_name = 15;
    RpcInvalidCommitish invalid_commitish = 10;
    RpcInvalidEditFile invalid_edit_file = 37;
    RpcInvalidFollowPathspec invalid_follow_pathspec = 42;
    RpcInvalidHookScriptId invalid_hook_script_id = 45;
    RpcInvalidMerge invalid_merge = 32;
    RpcInvalidPack invalid_pack = 54;
    RpcInvalidRebase invalid_rebase = 33;
    RpcInvalidRefName invalid_ref_name = 14;
    RpcInvalidTagName invalid_tag_name = 18;
    RpcInvalidTreeish invalid_treeish = 11;
    RpcInvalidWorkTreePath invalid_work_tree_path = 64;
    RpcLfsByteRangeNotSatisfiable lfs_byte_range_not_satisfiable = 50;
    RpcLfsChecksumValidationFailed lfs_checksum_validation_failed = 52;
    RpcRefNameConflict ref_name_conflict = 16;
    RpcUnsupportedArgument unsupported_argument = 19;
    RpcUnsupportedCommand unsupported_command = 49;
    RpcUnsupportedMergeStrategy unsupported_merge_strategy = 24;
    RpcUsage usage = 12;
    //NOT_FOUND
    RpcNoDefaultBranch no_default_branch = 23;
    RpcNoMergeBase no_merge_base = 41;
    RpcNoSuchCommit no_such_commit = 20;
    RpcNoSuchHookScript no_such_hook_script = 44;
    RpcNoSuchObject no_such_object = 21;
    RpcNoSuchPath no_such_path = 22;
    RpcNoSuchRef no_such_ref = 48;
    RpcNoSuchWorkTree no_such_work_tree= 65;
    //PERMISSION_DENIED
    RpcRemoteAuthorizationFailed remote_authorization_failed = 40;
  }
}

/* Indicates that the branch can't be deleted yet because it is not merged */
message RpcBranchNotMerged {
  bytes branch_name = 1;
}

message RpcCommandTimeout {
  bytes command_line = 1;
  sint32 exit_code = 2;
}

/* Indicates that Mesh failed to create specified ref */
message RpcCreateRefFailed {
  bytes ref_name = 1;
}

message RpcDeletePullRequestFailed {
}

/* Indicates that Mesh failed to delete specified ref */
message RpcDeleteRefFailed {
  bytes ref_name = 1;
}

/* The specified repository has a detached head which is not supported */
message RpcDetachedHead {
}

message RpcDisableTranscodeFailed {
}

message RpcEditFileFailed {
}

message RpcEmptyRebase {
}

message RpcEmptyRebaseMerge {
}

/* The target branch includes identical changes; the squashed commit would be empty */
message RpcEmptySquashMerge {
}

/* Indicates that attempt to enable ref log failed */
message RpcEnableRefLogFailed {
  bytes ref_id = 1;
}

message RpcEnableTranscodeFailed {
}

/* Summary for a command that failed. */
message RpcFailedCommand {
  bytes command_line = 1;
  sint32 exit_code = 2;
  string stderr = 3;
}

message RpcHookScriptWriteFailed {
  string hook_script_id = 1;
}

message RpcIllegalTransactionState {
  string transaction_id = 1;

  string state = 2;
  string target_state = 3;
}

/* Summary of an issue with branch name reported by Git */
message RpcInvalidBranchName {
  enum Reason {
    DUPLICATE = 0;
    NAME_INVALID = 1;
    START_POINT_INVALID = 3;
    START_POINT_NOT_FOUND = 4;
  }

  Reason reason = 1;
  bytes branch_name = 2;
}

/* The specified commitish (a value that can be coerced to a commit) is invalid */
message RpcInvalidCommitish {
  bytes commitish = 1;
}

message RpcInvalidEditFile {
  enum Reason {
    EDIT_FILE_DELETED = 0;
    EDIT_FILE_EXISTS = 1;
    EDIT_FILE_NO_BRANCH = 2;
    EDIT_FILE_NONEXISTENT = 3;
    EDIT_FILE_PATH = 4;
    EDIT_FILE_SAME = 5;
    EDIT_FILE_STALE = 6;
  }

  Reason reason = 1;
}

message RpcInvalidFollowPathspec {
}

message RpcInvalidHookScriptId {
  string hook_script_id = 1;
}

message RpcInvalidMerge {
  enum Reason {
    AUTHOR_EMAIL_BLANK = 0;
    AUTHOR_NAME_BLANK = 1;
    COMMIT_MESSAGE_BLANK = 2;
    UNRELATED = 3;
  };

  Reason reason = 1;
}

message RpcInvalidPack {
  enum Reason {
    INVALID_OBJECT = 0;
    EARLY_EOF = 1;
    MISSING_OBJECT = 2;
    TOO_LARGE = 3;
    UNKNOWN = 4;
    UNRESOLVED_DELTA = 5;
  }

  Reason reason = 1;
  optional string details = 2;
}

message RpcInvalidRebase {
  enum Reason {
    COMMITTER_EMAIL_BLANK = 0;
    COMMITTER_NAME_BLANK = 1;
  };

  Reason reason = 1;
}

message RpcInvalidRefName {
  enum Reason {
    BLANK = 0;
    INVALID = 1;
    TOO_LONG = 2;
    WHITESPACE = 3;
  };

  Reason reason = 1;
  bytes ref_name = 2;
  int32 max_length = 3;
}

message RpcInvalidTagName {
  enum Reason {
    DUPLICATE = 0;
    NAME_INVALID = 1;
    START_POINT_NOT_FOUND = 2;
  }

  Reason reason = 1;
  bytes tag_name = 2;
}

/* The specified treeish (a value that can be coerced to a tree) is invalid */
message RpcInvalidTreeish {
  bytes treeish = 1;
}

/* The specified path inside the work tree is invalid */
message RpcInvalidWorkTreePath {
  enum Reason {
    FILE_ALREADY_EXISTS = 0;
    INVALID_LOCATION = 1;
    INVALID_NAME = 2;
  }

  Reason reason = 1;
  bytes path = 2;
}

/* An LFS range request cannot be satisfied */
message RpcLfsByteRangeNotSatisfiable {
  uint64 start = 1;
  uint64 end = 2;
}

/* An LFS object's checksum did not match its object ID */
message RpcLfsChecksumValidationFailed {
  string oid = 1;
  string checksum = 2;
}

/* An internal error occurred during an LFS RPC */
message RpcLfsStorageFailed {
}

message RpcMergeFailed {
  string from_commit_id = 1;
}

/* Repository doesn't have a default branch */
message RpcNoDefaultBranch {
  //The branch HEAD is set to, which does not exist.
  bytes branch_id = 1;
}

/* The specified commits have no merge base. */
message RpcNoMergeBase {
}

/* A requested commit doesn't exist. */
message RpcNoSuchCommit {
  bytes commitish = 1;
}

/* A requested hook script doesn't exist */
message RpcNoSuchHookScript {
  string hook_script_id = 1;
}

/* A requested object (specific type unknown) doesn't exist. */
message RpcNoSuchObject {
  bytes object_id = 1;
}

/* A specified path doesn't exist at a given comment. */
message RpcNoSuchPath {
  bytes commitish = 1;
  bytes path = 2;
}

/* A requested ref doesn't exist. */
message RpcNoSuchRef {
  bytes ref_name = 1;
}

/* A requested work tree doesn't exist */
message RpcNoSuchWorkTree {
  string id = 1;
}

/* The branch or revision being merged is not fast-forward.  */
message RpcNonFastForwardMerge {
  string from_commit_id = 1;
}

/* A non-forced push to a ref failed because it was not fast-forward. */
message RpcNonFastForwardUpdate {
  bytes rejected_ref = 1;
}

/* Rebase failed due to conflicts. */
message RpcRebaseConflicted {
  string from_commit_id = 1;
}

message RpcRebaseFailed {
}

message RpcRefNameConflict {
  bytes ref_name = 1;
  bytes conflict_name = 2;
}

/* Indicates that authentication failed when accessing a remote server */
message RpcRemoteAuthenticationFailed {
  string url = 1;
}

/* Indicates that authorisation failed when accessing a remote server */
message RpcRemoteAuthorizationFailed {
  string url = 1;
}

/* Revert failed due to conflicts. */
//@since 1.5
message RpcRevertConflicted {
  string commit_id = 1;
  string source_branch_commit_id = 2;
}

/* Revert failed due to unknown reason */
//@since 1.5
message RpcRevertFailed {
  string commit_id = 1;
}

/* Revert failed due to invalid merged commit parent number. */
//@since 1.5
message RpcRevertInvalidParentNumber {
  string commit_id = 1;
  int32 merged_commit_parent_number = 2;
}

message RpcSetDefaultBranchFailed {
  bytes branch_id = 1;
}

message RpcSetMetadataFailed {
}

message RpcTransactionCommitFailed {
  enum Reason {
    UNKNOWN = 0;
    TIMEOUT = 1;
    INTERRUPTED = 2;
    PUBLISH_FAILED = 3;
  }

  Reason reason = 2;
}

message RpcTransactionRollbackFailed {
  enum Reason {
    UNKNOWN = 0;
    TIMEOUT = 1;
    INTERRUPTED = 2;
    CLEANUP_FAILED = 3;
  }

  Reason reason = 2;
}
message RpcTranscodingFailed {
  string source = 1;
  string target = 2;
}

message RpcUnsupportedArgument {
  enum Reason {
    UNSUPPORTED_OBJECT_TYPE = 0;
    UNSUPPORTED_NODE_TYPE = 1;
    UNSUPPORTED_COMBINATION = 2; // when an unsupported combination of git arguments are provided
    UNSUPPORTED_UPLOAD_TYPE = 3;
  }

  Reason reason = 1;
  bytes value = 2;
}

message RpcUnsupportedCommand {
  bytes command_line = 1;
}

message RpcUnsupportedMergeStrategy {
  string strategy_id = 1;
  repeated string supported_strategies = 2;
}

message RpcUnsupportedOperation {
  string operation = 1;
}

/* The assembled command is invalid, or unsupported by the installed Git. The
   details for the invalid command will be in the CommandSummary. */
message RpcUsage {
  //Intentionally empty for now
}

message RpcInvalidWorkTree {
  enum Reason {
    EXPIRED = 0;
    NO_COMMIT = 1;
  }

  Reason reason = 1;
}

message RpcWorkTreeWriteFailed {
}
