(repo_path: &Path)
| 42 | } |
| 43 | |
| 44 | pub fn list_worktrees(repo_path: &Path) -> Result<Vec<WorktreeInfo>, WorktreeError> { |
| 45 | if !is_git_repo(repo_path) { |
| 46 | return Err(WorktreeError::NotGitRepo); |
| 47 | } |
| 48 | |
| 49 | let output = run_git(&["worktree", "list", "--porcelain"], repo_path)?; |
| 50 | |
| 51 | let mut worktrees = Vec::new(); |
| 52 | let mut current_path: Option<String> = None; |
| 53 | let mut current_branch: Option<String> = None; |
| 54 | let mut current_head: Option<String> = None; |
| 55 | |
| 56 | for line in output.lines() { |
| 57 | if line.starts_with("worktree ") { |
| 58 | if let (Some(path), Some(branch), Some(head)) = |
| 59 | (¤t_path, ¤t_branch, ¤t_head) |
| 60 | { |
| 61 | worktrees.push(WorktreeInfo { |
| 62 | path: path.clone(), |
| 63 | branch: branch.clone(), |
| 64 | head: head.clone(), |
| 65 | }); |
| 66 | } |
| 67 | current_path = Some(line["worktree ".len()..].to_string()); |
| 68 | current_branch = None; |
| 69 | current_head = None; |
| 70 | } else if line.starts_with("HEAD ") { |
| 71 | current_head = Some(line["HEAD ".len()..].to_string()); |
| 72 | } else if line.starts_with("branch ") { |
| 73 | let branch_full = &line["branch ".len()..]; |
| 74 | let branch = branch_full |
| 75 | .strip_prefix("refs/heads/") |
| 76 | .unwrap_or(branch_full); |
| 77 | current_branch = Some(branch.to_string()); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if let (Some(path), Some(branch), Some(head)) = (¤t_path, ¤t_branch, ¤t_head) |
| 82 | { |
| 83 | worktrees.push(WorktreeInfo { |
| 84 | path: path.clone(), |
| 85 | branch: branch.clone(), |
| 86 | head: head.clone(), |
| 87 | }); |
| 88 | } else if let (Some(path), Some(head)) = (¤t_path, ¤t_head) { |
| 89 | worktrees.push(WorktreeInfo { |
| 90 | path: path.clone(), |
| 91 | branch: "HEAD".to_string(), |
| 92 | head: head.clone(), |
| 93 | }); |
| 94 | } |
| 95 | |
| 96 | Ok(worktrees) |
| 97 | } |
| 98 | |
| 99 | pub fn create_worktree( |
| 100 | repo_path: &Path, |
nothing calls this directly
no test coverage detected