syntax = "proto3";

package mesh.v1;

import "mesh/v1/commit.proto";
import "mesh/v1/git_model.proto";
import "mesh/v1/stream.proto";

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

message RpcCloseWorkTreeRequest {
  string work_tree = 1;
}

message RpcCloseWorkTreeResponse {
}

message RpcCreateWorkTreeRequest {
  enum CheckoutType {
    UNSPECIFIED = 0;

    NONE = 1;
    SPARSE = 2;
  }
  string repository = 1;

  repeated string alternates = 2;
  //expiry is the number of seconds from when the work tree is created until it expires.
  uint64 expiry = 3;
  bytes commitish = 4;
  CheckoutType checkout_type = 5;
}

message RpcCreateWorkTreeResponse {
  string work_tree = 1;
  uint64 expiry = 2;
}

message RpcPublishWorkTreeFragment {
  oneof request_oneof {
    RpcPublishWorkTreeRequest request = 1;
    RpcUpdateRef update_ref = 2;
  }
}

message RpcPublishWorkTreeRequest {
  string work_tree = 1;
  RpcGitTimeouts timeouts = 3;

  optional RpcPerson author = 4;
  bytes branch = 5;
  optional string expected_hash = 6;
}

message RpcPublishWorkTreeResponse {
  RpcRefUpdate ref_update = 1;
}

message RpcPublishWorkTreeResponseFragment {
  oneof request_oneof {
    RpcRunPublishWorkTreeHooks run_hooks = 1;
    RpcPublishWorkTreeResponse response = 2;
  }
}

message RpcRunPublishWorkTreeHooks {
  string repository_id = 1;

  RpcRefUpdate ref_update = 2;
}

message RpcWorkTreeMkdirRequest {
  string work_tree = 1;

  //relative path to directory to make
  bytes path = 2;
}

message RpcWorkTreeMkdirResponse {
}

message RpcWriteWorkTreeFileFragment {
  oneof request_oneof {
    RpcWriteWorkTreeFileRequest request = 1;
    RpcStreamChunk content = 2;
  }
}

message RpcWriteWorkTreeFileRequest {
  string work_tree = 1;

  //relative path to file to write to, contents will be overwritten
  bytes path = 2;
}

message RpcWriteWorkTreeFileResponse {
}
