Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: Guard compdef call in zsh static completions for --no-rcs compatibility
Maximilian Roos44f07e612513
diff --git a/src/commands/init.rs b/src/commands/init.rsindex bc6eb4601..9e8406390 100644--- a/src/commands/init.rs+++ b/src/commands/init.rs@@ -70,7 +70,22 @@ pub fn handle_init(shell_name: &str, cmd_name: &str, cli_cmd: &mut Command) -> Rline.to_string()};- println!("{}", line);+ // For zsh, wrap the final compdef call in a guard to prevent errors in --no-rcs mode+ // The clap-generated completions end with:+ // if [ "$funcstack[1]" = "_wt" ]; then+ // _wt "$@"+ // else+ // compdef _wt wt+ // fi+ // We need to check if compdef exists before calling it in the else branch+ if matches!(shell, shell::Shell::Zsh) && line.trim() == "compdef _wt wt" {+ // Wrap the compdef call in a guard (preserve 4-space indentation from else block)+ println!(" if (( $+functions[compdef] )); then");+ println!(" compdef _wt wt");+ println!(" fi");+ } else {+ println!("{}", line);+ }}Ok(())diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__command_failure_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__command_failure_zsh.snapindex ce8b21c1b..dc69189d5 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__command_failure_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__command_failure_zsh.snap@@ -2,7 +2,6 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefβ [31mBranch [1m[31mexisting[0m already exists[0mπ‘ [2mRemove --create flag to switch to it[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snapindex 29eac739a..8903390cb 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_failure_zsh.snap@@ -2,7 +2,6 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefβ Code formatting check passedβ Test suite failed: 3 tests failingβ [31mPre-merge command failed: [1m[31mtest[0m[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snapindex 3474951f1..6f85a617a 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap@@ -2,7 +2,6 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefβ Code formatting check passedβ Linting passed - no warningsβ All 47 tests passed in 2.3sdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_zsh.snapindex e96b53264..f0f2b867a 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_zsh.snap@@ -2,5 +2,4 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefβ [32mAlready on [1m[32mmain[0m, nothing to merge[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove_zsh.snapindex 53e9e9543..8b824a4bb 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove_zsh.snap@@ -2,6 +2,5 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefπ [36mRemoving worktree for [1mto-remove[0m...[0mβ [32mRemoved worktree for [1m[32mto-remove[0m[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_create_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_create_zsh.snapindex 4039cc3a7..6d6577aca 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_create_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_create_zsh.snap@@ -2,5 +2,4 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefβ [32mCreated new worktree for [1m[32mfeature[0m at [TMPDIR]/test-repo.feature[0mdiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_zsh.snapindex aabd3606d..8bef55bb1 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_zsh.snap@@ -2,7 +2,6 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefβ [32mCreated new worktree for [1m[32mtest-exec[0m at [TMPDIR]/test-repo.test-exec[0mπ [36mExecuting (--execute):[0m[40m [0m echo executeddiff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snapindex 408cbd06e..351825872 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap@@ -2,7 +2,6 @@source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized().as_ref()----zsh:365: command not found: compdefInstalling dependencies...Building project...π [36mExecuting (post-create):[0mdiff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 6fe1c7735..868cbe0ff 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpelDWZF/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpw2OXOa/test-config.toml---success: trueexit_code: 0@@ -382,7 +382,9 @@ _wt__switch_commands() {if [ "$funcstack[1]" = "_wt" ]; then_wt "$@"else- compdef _wt wt+ if (( $+functions[compdef] )); then+ compdef _wt wt+ fifi----- stderr -----