List all worktrees.
(repo_path: &Path)
| 535 | |
| 536 | /// List all worktrees. |
| 537 | pub 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. |
| 582 | pub fn create_worktree( |
no test coverage detected