opencode_sdk/http/
worktree.rs1use crate::error::Result;
6use crate::http::HttpClient;
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10#[derive(Clone)]
12pub struct WorktreeApi {
13 http: HttpClient,
14}
15
16impl WorktreeApi {
17 pub fn new(http: HttpClient) -> Self {
19 Self { http }
20 }
21
22 pub async fn create(&self, req: &CreateWorktreeRequest) -> Result<Worktree> {
28 let body = serde_json::to_value(req)?;
29 self.http
30 .request_json(Method::POST, "/experimental/worktree", Some(body))
31 .await
32 }
33
34 pub async fn list(&self) -> Result<Vec<Worktree>> {
40 self.http
41 .request_json(Method::GET, "/experimental/worktree", None)
42 .await
43 }
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct CreateWorktreeRequest {
50 pub branch: String,
52 #[serde(default, skip_serializing_if = "Option::is_none")]
54 pub path: Option<String>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct Worktree {
61 pub path: String,
63 #[serde(default, skip_serializing_if = "Option::is_none")]
65 pub branch: Option<String>,
66 #[serde(default)]
68 pub is_main: bool,
69}