MCPcopy Create free account
hub / github.com/AI45Lab/Code / create_worktree

Method create_worktree

core/src/tools/builtin/git.rs:456–501  ·  view source on GitHub ↗

Create a new worktree.

(
        &self,
        args: &serde_json::Value,
        worktree: &dyn WorkspaceGitWorktreeProvider,
    )

Source from the content-addressed store, hash-verified

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(

Callers 1

worktreeMethod · 0.45

Calls 3

getMethod · 0.45
as_strMethod · 0.45
with_metadataMethod · 0.45

Tested by

no test coverage detected