Create a new worktree.
(
&self,
args: &serde_json::Value,
worktree: &dyn WorkspaceGitWorktreeProvider,
)
| 454 | |
| 455 | /// Create a new worktree. |
| 456 | async fn create_worktree( |
| 457 | &self, |
| 458 | args: &serde_json::Value, |
| 459 | worktree: &dyn WorkspaceGitWorktreeProvider, |
| 460 | ) -> Result<ToolOutput> { |
| 461 | let branch = match args |
| 462 | .get("name") |
| 463 | .or_else(|| args.get("branch")) |
| 464 | .and_then(|v| v.as_str()) |
| 465 | { |
| 466 | Some(b) => b, |
| 467 | None => { |
| 468 | return Ok(ToolOutput::error( |
| 469 | "branch name is required for worktree create", |
| 470 | )) |
| 471 | } |
| 472 | }; |
| 473 | |
| 474 | let new_branch = args |
| 475 | .get("new_branch") |
| 476 | .and_then(|v| v.as_bool()) |
| 477 | .unwrap_or(true); |
| 478 | let path = args |
| 479 | .get("path") |
| 480 | .and_then(|v| v.as_str()) |
| 481 | .map(ToString::to_string); |
| 482 | |
| 483 | match worktree |
| 484 | .create_worktree(WorkspaceGitCreateWorktreeRequest { |
| 485 | branch: branch.to_string(), |
| 486 | path, |
| 487 | new_branch, |
| 488 | }) |
| 489 | .await |
| 490 | { |
| 491 | Ok(result) => Ok(ToolOutput::success(format!( |
| 492 | "Created worktree at: {}\nBranch: {branch}", |
| 493 | result.path |
| 494 | )) |
| 495 | .with_metadata(serde_json::json!({ |
| 496 | "path": result.path, |
| 497 | "branch": branch, |
| 498 | }))), |
| 499 | Err(e) => Ok(ToolOutput::error(format!("Failed to create worktree: {e}"))), |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /// Remove a worktree. |
| 504 | async fn remove_worktree( |
no test coverage detected