Skip to content

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

feat(completion): Suggest hooks for 'dev run-hook'

Maximilian Roos99dbb4887732
diff --git a/src/commands/completion.rs b/src/commands/completion.rs
index cb68847e2..bee95728f 100644
--- a/src/commands/completion.rs
+++ b/src/commands/completion.rs
@@ -36,6 +36,7 @@ enum CompletionContext {
MergeTarget,
RemoveBranch,
BaseFlag,
+ DevRunHook,
Unknown,
}
@@ -71,6 +72,7 @@ fn should_complete_positional_arg(args: &[String], start_index: usize) -> bool {
fn parse_completion_context(args: &[String]) -> CompletionContext {
// args format: ["wt", "switch", "partial"]
// or: ["wt", "switch", "--create", "new", "--base", "partial"]
+ // or: ["wt", "dev", "run-hook", "partial"]
if args.len() < 2 {
return CompletionContext::Unknown;
@@ -87,6 +89,15 @@ fn parse_completion_context(args: &[String]) -> CompletionContext {
}
}
+ // Handle dev subcommand
+ if subcommand == "dev" && args.len() >= 3 {
+ let dev_subcommand = &args[2];
+ if dev_subcommand == "run-hook" {
+ // Complete hook types for the positional argument
+ return CompletionContext::DevRunHook;
+ }
+ }
+
// Special handling for switch --create: don't complete new branch names
if subcommand == "switch" {
let has_create = args.iter().any(|arg| arg == "--create" || arg == "-c");
@@ -144,6 +155,15 @@ pub fn handle_complete(args: Vec<String>) -> Result<(), GitError> {
println!("{}", branch);
}
}
+ CompletionContext::DevRunHook => {
+ // Complete with hook types
+ println!("post-create");
+ println!("post-start");
+ println!("pre-commit");
+ println!("pre-squash");
+ println!("pre-merge");
+ println!("post-merge");
+ }
CompletionContext::Unknown => {
// No completions
}
@@ -270,4 +290,36 @@ mod tests {
CompletionContext::SwitchBranch
);
}
+
+ #[test]
+ fn test_parse_completion_context_dev_run_hook() {
+ // "wt dev run-hook <cursor>"
+ let args = vec!["wt".to_string(), "dev".to_string(), "run-hook".to_string()];
+ assert_eq!(
+ parse_completion_context(&args),
+ CompletionContext::DevRunHook
+ );
+ }
+
+ #[test]
+ fn test_parse_completion_context_dev_run_hook_partial() {
+ // "wt dev run-hook po<cursor>"
+ let args = vec![
+ "wt".to_string(),
+ "dev".to_string(),
+ "run-hook".to_string(),
+ "po".to_string(),
+ ];
+ assert_eq!(
+ parse_completion_context(&args),
+ CompletionContext::DevRunHook
+ );
+ }
+
+ #[test]
+ fn test_parse_completion_context_dev_only() {
+ // "wt dev <cursor>" - should not complete
+ let args = vec!["wt".to_string(), "dev".to_string()];
+ assert_eq!(parse_completion_context(&args), CompletionContext::Unknown);
+ }
}
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 9cd3bc48b..46e4ea18a 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -682,3 +682,53 @@ fn test_complete_remove_shows_branches() {
assert!(branches.iter().any(|b| b.contains("feature/new")));
assert!(branches.iter().any(|b| b.contains("hotfix/bug")));
}
+
+#[test]
+fn test_complete_dev_run_hook_shows_hook_types() {
+ let temp = TestRepo::new();
+ temp.commit("initial");
+
+ // Test completion for dev run-hook
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd
+ .current_dir(temp.root_path())
+ .args(["complete", "wt", "dev", "run-hook", ""])
+ .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
+ 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-squash"), "Missing pre-squash");
+ assert!(hooks.contains(&"pre-merge"), "Missing pre-merge");
+ assert!(hooks.contains(&"post-merge"), "Missing post-merge");
+ assert_eq!(hooks.len(), 6, "Should have exactly 6 hook types");
+}
+
+#[test]
+fn test_complete_dev_run_hook_with_partial_input() {
+ let temp = TestRepo::new();
+ temp.commit("initial");
+
+ // Test completion with partial input
+ let mut cmd = Command::cargo_bin("wt").unwrap();
+ let output = cmd
+ .current_dir(temp.root_path())
+ .args(["complete", "wt", "dev", "run-hook", "po"])
+ .output()
+ .unwrap();
+
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let hooks: Vec<&str> = stdout.lines().collect();
+
+ // Should still show all hook types (filtering happens in the shell)
+ assert!(hooks.contains(&"post-create"));
+ assert!(hooks.contains(&"post-start"));
+ assert!(hooks.contains(&"post-merge"));
+}