Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Feat: Add branch completion for `remove` command

Maximilian Roos85800e86f464
diff --git a/src/commands/completion.rs b/src/commands/completion.rs
index 7e36cd5bd..b5cf8dce4 100644
--- a/src/commands/completion.rs
+++ b/src/commands/completion.rs
@@ -34,6 +34,7 @@ enum CompletionContext {
SwitchBranch,
PushTarget,
MergeTarget,
+ RemoveBranch,
BaseFlag,
Unknown,
}
@@ -99,6 +100,7 @@ fn parse_completion_context(args: &[String]) -> CompletionContext {
"switch" => CompletionContext::SwitchBranch,
"push" => CompletionContext::PushTarget,
"merge" => CompletionContext::MergeTarget,
+ "remove" => CompletionContext::RemoveBranch,
_ => return CompletionContext::Unknown,
};
@@ -134,6 +136,7 @@ pub fn handle_complete(args: Vec<String>) -> Result<(), GitError> {
}
CompletionContext::PushTarget
| CompletionContext::MergeTarget
+ | CompletionContext::RemoveBranch
| CompletionContext::BaseFlag => {
// Complete with all branches
let branches = get_branches_for_completion(|| Repository::current().all_branches());
@@ -180,6 +183,15 @@ mod tests {
);
}
+ #[test]
+ fn test_parse_completion_context_remove() {
+ let args = vec!["wt".to_string(), "remove".to_string(), "feat".to_string()];
+ assert_eq!(
+ parse_completion_context(&args),
+ CompletionContext::RemoveBranch
+ );
+ }
+
#[test]
fn test_parse_completion_context_base_flag() {
let args = vec![
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index ab54ddb37..cbbb17d54 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -204,7 +204,7 @@ fn test_complete_edge_cases_return_empty() {
assert!(output.status.success());
assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
- // Test 4: Commands that don't take branch arguments (list, remove)
+ // Test 4: Commands that don't take branch arguments (list)
let mut cmd = Command::cargo_bin("wt").unwrap();
let output = cmd
.current_dir(repo.root_path())
@@ -213,15 +213,6 @@ fn test_complete_edge_cases_return_empty() {
.unwrap();
assert!(output.status.success());
assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
-
- let mut cmd = Command::cargo_bin("wt").unwrap();
- let output = cmd
- .current_dir(repo.root_path())
- .args(["complete", "wt", "remove", ""])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
}
#[test]
@@ -577,3 +568,35 @@ fn test_complete_switch_base_flag_after_branch() {
// Should complete base flag value with branches
assert!(stdout.contains("develop"));
}
+
+#[test]
+fn test_complete_remove_shows_branches() {
+ let mut temp = TestRepo::new();
+ temp.commit("initial");
+
+ // Create worktree (creates "feature/new" branch)
+ temp.add_worktree("feature-worktree", "feature/new");
+
+ // Create another branch without worktree
+ StdCommand::new("git")
+ .args(["branch", "hotfix/bug"])
+ .current_dir(temp.root_path())
+ .output()
+ .unwrap();
+
+ // Test completion for remove (should show ALL branches)
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd
+ .current_dir(temp.root_path())
+ .args(["complete", "wt", "remove", ""])
+ .output()
+ .unwrap();
+
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let branches: Vec<&str> = stdout.lines().collect();
+
+ // Should include both branches
+ assert!(branches.iter().any(|b| b.contains("feature/new")));
+ assert!(branches.iter().any(|b| b.contains("hotfix/bug")));
+}