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

Method list_worktrees

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

List all worktrees.

(
        &self,
        worktree: &dyn WorkspaceGitWorktreeProvider,
    )

Source from the content-addressed store, hash-verified

418
419 /// List all worktrees.
420 async fn list_worktrees(
421 &self,
422 worktree: &dyn WorkspaceGitWorktreeProvider,
423 ) -> Result<ToolOutput> {
424 match worktree.list_worktrees().await {
425 Ok(worktrees) => {
426 if worktrees.is_empty() {
427 return Ok(ToolOutput::success("No worktrees found."));
428 }
429
430 let entries: Vec<String> = worktrees
431 .iter()
432 .map(|worktree| {
433 let suffix = if worktree.is_bare {
434 " (bare)".to_string()
435 } else if worktree.is_detached {
436 " (detached)".to_string()
437 } else {
438 format!(" [{}]", worktree.branch)
439 };
440 format!(" {}{}", worktree.path, suffix)
441 })
442 .collect();
443
444 Ok(ToolOutput::success(format!(
445 "Worktrees ({}):\n{}",
446 worktrees.len(),
447 entries.join("\n")
448 ))
449 .with_metadata(serde_json::json!({ "count": worktrees.len() })))
450 }
451 Err(e) => Ok(ToolOutput::error(format!("Failed to list worktrees: {e}"))),
452 }
453 }
454
455 /// Create a new worktree.
456 async fn create_worktree(

Callers 1

worktreeMethod · 0.45

Calls 2

is_emptyMethod · 0.45
with_metadataMethod · 0.45

Tested by

no test coverage detected