Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(completion): Handle empty completion input
Maximilian Roosfe6756daebdc
diff --git a/src/commands/completion.rs b/src/commands/completion.rsindex d5494f55f..8dd783dbe 100644--- a/src/commands/completion.rs+++ b/src/commands/completion.rs@@ -376,14 +376,21 @@ pub fn handle_complete(args: Vec<String>) -> Result<(), GitError> {}}- let last = args.last().map(String::as_str).unwrap_or("");+ // Determine the prefix to filter by:+ // - If we've consumed all args as subcommands (i >= args.len()), use empty prefix+ // - Otherwise, use the last arg as prefix for filtering+ let prefix = if i >= args.len() {+ ""+ } else {+ args.last().map(String::as_str).unwrap_or("")+ };// Check if there's a positional with possible_valuesif let Some(arg) = cur.get_positionals().find(|a| !a.get_possible_values().is_empty()){- let items = items_from_arg(arg, last);+ let items = items_from_arg(arg, prefix);if !items.is_empty() {print_items(items);}diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rsindex f4466b02f..b93900bcf 100644--- a/tests/integration_tests/completion.rs+++ b/tests/integration_tests/completion.rs@@ -866,6 +866,35 @@ fn test_complete_dev_run_hook_with_partial_input() {assert!(!hooks.contains(&"pre-merge"));}+#[test]+fn test_complete_dev_run_hook_without_trailing_empty() {+ let temp = TestRepo::new();+ temp.commit("initial");++ // Test completion WITHOUT trailing empty string (what fish actually sends)+ // Regression test for bug where "wt beta run-hook<tab>" showed nothing+ // but "wt beta run-hook ""<tab>" showed all hooks+ let mut cmd = wt_command();+ temp.clean_cli_env(&mut cmd);+ let output = cmd+ .current_dir(temp.root_path())+ .args(["complete", "wt", "beta", "run-hook"]) // No trailing ""+ .output()+ .unwrap();++ assert!(output.status.success());+ let stdout = String::from_utf8_lossy(&output.stdout);+ let hooks: Vec<&str> = stdout.lines().collect();++ // Should include all hook types even without trailing empty string+ assert!(hooks.contains(&"post-create"), "Missing post-create");+ assert!(hooks.contains(&"post-start"), "Missing post-start");+ assert!(hooks.contains(&"pre-commit"), "Missing pre-commit");+ assert!(hooks.contains(&"pre-merge"), "Missing pre-merge");+ assert!(hooks.contains(&"post-merge"), "Missing post-merge");+ assert_eq!(hooks.len(), 5, "Should have exactly 5 hook types");+}+#[test]fn test_complete_init_shows_shells() {let temp = TestRepo::new();@@ -895,6 +924,30 @@ fn test_complete_init_shows_shells() {assert!(shells.contains(&"xonsh"));}+#[test]+fn test_complete_init_without_trailing_empty() {+ let temp = TestRepo::new();+ temp.commit("initial");++ // Test completion WITHOUT trailing empty string (what fish actually sends)+ let mut cmd = wt_command();+ temp.clean_cli_env(&mut cmd);+ let output = cmd+ .current_dir(temp.root_path())+ .args(["complete", "wt", "init"]) // No trailing ""+ .output()+ .unwrap();++ assert!(output.status.success());+ let stdout = String::from_utf8_lossy(&output.stdout);+ let shells: Vec<&str> = stdout.lines().collect();++ // Should show all shell types even without trailing empty string+ assert!(shells.contains(&"bash"));+ assert!(shells.contains(&"fish"));+ assert!(shells.contains(&"zsh"));+}+#[test]fn test_complete_init_partial() {let temp = TestRepo::new();