Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(completion): skip prefix filtering to enable shell substring matching (#1471)
worktrunk-botb527e42a3183
diff --git a/src/completion.rs b/src/completion.rsindex 646a41d86..8031af037 100644--- a/src/completion.rs+++ b/src/completion.rs@@ -279,21 +279,16 @@ impl ValueCompleter for BranchCompleter {return Vec::new();}- // Filter branches by prefix - clap doesn't filter ArgValueCompleter results- let prefix = current.to_string_lossy();+ // Return all candidates without prefix filtering — let the shell apply its+ // own matching (substring in fish, fuzzy in zsh, prefix in bash). Pre-filtering+ // here prevents shells from using their native matching strategies. The >100+ // remote exclusion in complete_branches() still applies to avoid overwhelming+ // the shell with thousands of remote-only branches.complete_branches(self.suppress_with_create,self.exclude_remote_only,self.worktree_only,)- .into_iter()- .filter(|candidate| {- candidate- .get_value()- .to_string_lossy()- .starts_with(&*prefix)- })- .collect()}}diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rsindex 2a3a59667..92423ab12 100644--- a/tests/integration_tests/completion.rs+++ b/tests/integration_tests/completion.rs@@ -289,7 +289,7 @@ fn test_init_fish_no_inline_completions() {}#[rstest]-fn test_complete_with_partial_prefix(repo: TestRepo) {+fn test_complete_with_partial_prefix_returns_all_branches(repo: TestRepo) {repo.commit("initial");// Create branches with common prefix@@ -297,19 +297,60 @@ fn test_complete_with_partial_prefix(repo: TestRepo) {repo.run_git(&["branch", "feature/two"]);repo.run_git(&["branch", "hotfix/bug"]);- // Complete with partial prefix - shell does prefix filtering, we return all branches- let mut settings = Settings::clone_current();- settings.set_snapshot_path("../snapshots");- settings.bind(|| {- let output = repo- .completion_cmd(&["wt", "switch", "feat"])- .output()- .unwrap();- assert!(output.status.success());- let stdout = String::from_utf8_lossy(&output.stdout);- assert!(stdout.contains("feature/one"));- assert!(stdout.contains("feature/two"));- });+ // Complete with partial prefix — binary returns ALL branches, shell does its own+ // matching (substring in fish, fuzzy in zsh, prefix in bash). This enables+ // fish/zsh substring matching for e.g. `wt switch auth<TAB>` → feature/user-auth.+ let output = repo+ .completion_cmd(&["wt", "switch", "feat"])+ .output()+ .unwrap();+ assert!(output.status.success());+ let stdout = String::from_utf8_lossy(&output.stdout);+ let values = value_suggestions(&stdout);++ // All branches returned, not just prefix matches+ assert!(values.iter().any(|v| v.contains("feature/one")));+ assert!(values.iter().any(|v| v.contains("feature/two")));+ assert!(values.iter().any(|v| v.contains("hotfix/bug")));+ assert!(values.iter().any(|v| v.contains("main")));+}++/// Typing a substring that appears mid-branch (e.g. "auth") should still return+/// branches containing that substring, because the binary no longer prefix-filters.+/// This is the core use case from #1468: `wt switch auth<TAB>` should let fish/zsh+/// match `feature/user-auth`.+#[rstest]+fn test_complete_switch_returns_candidates_for_substring_matching(repo: TestRepo) {+ repo.commit("initial");++ repo.run_git(&["branch", "feature/user-auth"]);+ repo.run_git(&["branch", "bugfix/user-auth-timeout"]);+ repo.run_git(&["branch", "release/2024-q1"]);++ // Type "auth" — not a prefix of any branch, but the binary returns all candidates+ // so the shell can apply substring matching+ let output = repo+ .completion_cmd(&["wt", "switch", "auth"])+ .output()+ .unwrap();+ assert!(output.status.success());+ let stdout = String::from_utf8_lossy(&output.stdout);+ let values = value_suggestions(&stdout);++ assert!(+ values.iter().any(|v| v.contains("feature/user-auth")),+ "should return feature/user-auth for shell substring matching\n{stdout}"+ );+ assert!(+ values+ .iter()+ .any(|v| v.contains("bugfix/user-auth-timeout")),+ "should return bugfix/user-auth-timeout for shell substring matching\n{stdout}"+ );+ assert!(+ values.iter().any(|v| v.contains("release/2024-q1")),+ "should return all branches regardless of typed prefix\n{stdout}"+ );}#[rstest]