MCPcopy Index your code
hub / github.com/AI45Lab/Code / list_worktrees

Function list_worktrees

core/src/git.rs:537–579  ·  view source on GitHub ↗

List all worktrees.

(repo_path: &Path)

Source from the content-addressed store, hash-verified

535
536/// List all worktrees.
537pub fn list_worktrees(repo_path: &Path) -> Result<Vec<WorktreeInfo>> {
538 let (_, stdout, _) = run_git(repo_path, &["worktree", "list", "--porcelain"])?;
539
540 let mut worktrees = Vec::new();
541 let mut current_path = String::new();
542 let mut current_branch = String::new();
543 let mut is_bare = false;
544 let mut is_detached = false;
545
546 for line in stdout.lines() {
547 if let Some(path) = line.strip_prefix("worktree ") {
548 if !current_path.is_empty() {
549 worktrees.push(WorktreeInfo {
550 path: current_path.clone(),
551 branch: current_branch.clone(),
552 is_bare,
553 is_detached,
554 });
555 }
556 current_path = path.to_string();
557 current_branch.clear();
558 is_bare = false;
559 is_detached = false;
560 } else if let Some(branch) = line.strip_prefix("branch refs/heads/") {
561 current_branch = branch.to_string();
562 } else if line == "bare" {
563 is_bare = true;
564 } else if line == "detached" {
565 is_detached = true;
566 }
567 }
568
569 if !current_path.is_empty() {
570 worktrees.push(WorktreeInfo {
571 path: current_path,
572 branch: current_branch,
573 is_bare,
574 is_detached,
575 });
576 }
577
578 Ok(worktrees)
579}
580
581/// Create a new worktree.
582pub fn create_worktree(

Callers 1

list_worktreesMethod · 0.85

Calls 4

run_gitFunction · 0.85
is_emptyMethod · 0.45
cloneMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected