Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: use `builtin cd` in fish shell integration (#3160)
Worktrunk Bot03dbf5f70e3a
diff --git a/src/shell/mod.rs b/src/shell/mod.rsindex 9318937a6..5b077ff26 100644--- a/src/shell/mod.rs+++ b/src/shell/mod.rs@@ -387,6 +387,27 @@ mod tests {}}+ #[test]+ fn test_fish_init_uses_builtin_cd() {+ // Regression test for #3159: the fish integration must change directory+ // with `builtin cd`, not a bare `cd`. A bare `cd` is interceptable by+ // shell `cd` overrides (e.g. the zoxide.fish plugin replaces `cd` with+ // a zoxide query function). When wt called `cd -- "$target"`, zoxide+ // saw `--` as a query argument and failed with "no match found". Using+ // `builtin cd` bypasses any user `cd` function, matching bash and zsh.+ let output = ShellInit::with_prefix(Shell::Fish, "wt".to_string())+ .generate()+ .expect("Failed to generate fish init");+ assert!(+ output.contains("builtin cd"),+ "fish init must use `builtin cd` to bypass shell `cd` overrides; got:\n{output}"+ );+ assert!(+ !output.contains("\n cd -- "),+ "fish init must not use a bare `cd` that shell overrides can intercept; got:\n{output}"+ );+ }+#[test]fn test_shell_config_paths_returns_paths() {// All shells should return at least one config pathdiff --git a/src/shell/snapshots/worktrunk__shell__tests__init_fish.snap b/src/shell/snapshots/worktrunk__shell__tests__init_fish.snapindex 7cde05fd2..e9f0d871c 100644--- a/src/shell/snapshots/worktrunk__shell__tests__init_fish.snap+++ b/src/shell/snapshots/worktrunk__shell__tests__init_fish.snap@@ -44,7 +44,10 @@ function wt# safe even if CWD was removed by worktree removal).if test -s "$cd_file"set -l target (string trim < "$cd_file")- cd -- "$target"+ # `builtin cd` bypasses any user `cd` override (e.g. the zoxide.fish+ # plugin replaces `cd` with a query function that mishandles the `--`+ # separator). Matches the bash/zsh wrappers. (#3159)+ builtin cd -- "$target"set -l cd_exit $statusif test $exit_code -eq 0set exit_code $cd_exitdiff --git a/templates/fish.fish b/templates/fish.fishindex a4824ef95..13ee6abf0 100644--- a/templates/fish.fish+++ b/templates/fish.fish@@ -40,7 +40,10 @@ function {{ cmd }}# safe even if CWD was removed by worktree removal).if test -s "$cd_file"set -l target (string trim < "$cd_file")- cd -- "$target"+ # `builtin cd` bypasses any user `cd` override (e.g. the zoxide.fish+ # plugin replaces `cd` with a query function that mishandles the `--`+ # separator). Matches the bash/zsh wrappers. (#3159)+ builtin cd -- "$target"set -l cd_exit $statusif test $exit_code -eq 0set exit_code $cd_exitdiff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex 9b802aeb9..090e82928 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -88,7 +88,10 @@ function wt# safe even if CWD was removed by worktree removal).if test -s "$cd_file"set -l target (string trim < "$cd_file")- cd -- "$target"+ # `builtin cd` bypasses any user `cd` override (e.g. the zoxide.fish+ # plugin replaces `cd` with a query function that mishandles the `--`+ # separator). Matches the bash/zsh wrappers. (#3159)+ builtin cd -- "$target"set -l cd_exit $statusif test $exit_code -eq 0set exit_code $cd_exit