Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(select): add --branches and --remotes flags (#538)
Maximilian Rooscdbc10224519
diff --git a/.claude-plugin/skills/worktrunk/reference/select.md b/.claude-plugin/skills/worktrunk/reference/select.mdindex f73c044ef..525140c99 100644--- a/.claude-plugin/skills/worktrunk/reference/select.md+++ b/.claude-plugin/skills/worktrunk/reference/select.md@@ -31,7 +31,7 @@ Toggle between views with number keys:| `Alt-p` | Toggle preview panel || `Ctrl-u`/`Ctrl-d` | Scroll preview up/down |-Branches without worktrees are included — selecting one creates a worktree. (`wt list` requires `--branches` to show them.)+With `--branches`, branches without worktrees are included — selecting one creates a worktree. This matches `wt list --branches`.## Configuration@@ -55,6 +55,12 @@ Browse and switch worktrees with live preview.Usage: <b><span class=c>wt select</span></b> <span class=c>[OPTIONS]</span><b><span class=g>Options:</span></b>+ <b><span class=c>--branches</span></b>+ Include branches without worktrees++ <b><span class=c>--remotes</span></b>+ Include remote branches+<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>Print help (see a summary with '-h')diff --git a/docs/content/select.md b/docs/content/select.mdindex c3a7b8f9f..c9126821a 100644--- a/docs/content/select.md+++ b/docs/content/select.md@@ -46,7 +46,7 @@ Toggle between views with number keys:| `Alt-p` | Toggle preview panel || `Ctrl-u`/`Ctrl-d` | Scroll preview up/down |-Branches without worktrees are included — selecting one creates a worktree. (`wt list` requires `--branches` to show them.)+With `--branches`, branches without worktrees are included — selecting one creates a worktree. This matches `wt list --branches`.## Configuration@@ -76,6 +76,12 @@ Browse and switch worktrees with live preview.Usage: <b><span class=c>wt select</span></b> <span class=c>[OPTIONS]</span><b><span class=g>Options:</span></b>+ <b><span class=c>--branches</span></b>+ Include branches without worktrees++ <b><span class=c>--remotes</span></b>+ Include remote branches+<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>Print help (see a summary with '-h')diff --git a/src/cli/mod.rs b/src/cli/mod.rsindex 3c2c3b2cb..1f607a8cd 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -883,7 +883,7 @@ Toggle between views with number keys:| `Alt-p` | Toggle preview panel || `Ctrl-u`/`Ctrl-d` | Scroll preview up/down |-Branches without worktrees are included — selecting one creates a worktree. (`wt list` requires `--branches` to show them.)+With `--branches`, branches without worktrees are included — selecting one creates a worktree. This matches `wt list --branches`.## Configuration@@ -904,7 +904,15 @@ This is useful when the default pager doesn't render correctly in the embedded p- [`wt switch`](@/switch.md) — Direct switching to a known target branch"#)]- Select,+ Select {+ /// Include branches without worktrees+ #[arg(long)]+ branches: bool,++ /// Include remote branches+ #[arg(long)]+ remotes: bool,+ },/// Run individual operations#[command(diff --git a/src/commands/select.rs b/src/commands/select.rsindex dc761b8c2..8444c9533 100644--- a/src/commands/select.rs+++ b/src/commands/select.rs@@ -852,7 +852,11 @@ where}}-pub fn handle_select() -> anyhow::Result<()> {+pub fn handle_select(+ show_branches: bool,+ show_remotes: bool,+ config: &WorktrunkConfig,+) -> anyhow::Result<()> {use std::io::IsTerminal;// Select requires an interactive terminal for the TUI@@ -865,11 +869,6 @@ pub fn handle_select() -> anyhow::Result<()> {// Initialize preview mode state file (auto-cleanup on drop)let state = PreviewState::new();- // Load config (or use default) for path mismatch detection- let config = WorktrunkConfig::load()- .inspect_err(|e| log::warn!("Config load failed, using defaults: {}", e))- .unwrap_or_default();-// Gather list data using simplified collection (buffered mode)// Skip expensive operations not needed for select UIlet skip_tasks = [@@ -888,12 +887,12 @@ pub fn handle_select() -> anyhow::Result<()> {let Some(list_data) = collect::collect(&repo,- true, // show_branches (include branches without worktrees)- false, // show_remotes (local branches only, not remote branches)+ show_branches,+ show_remotes,&skip_tasks,false, // show_progress (no progress bars)false, // render_table (select renders its own UI)- &config,+ config,command_timeout,true, // skip_expensive_for_stale (faster for repos with many stale branches))?diff --git a/src/main.rs b/src/main.rsindex 26429616d..44b65a5a1 100644--- a/src/main.rs+++ b/src/main.rs@@ -1203,9 +1203,26 @@ fn main() {},},#[cfg(unix)]- Commands::Select => handle_select(),+ Commands::Select { branches, remotes } => {+ WorktrunkConfig::load()+ .context("Failed to load config")+ .and_then(|config| {+ // Get config values from [list] config (shared with wt list)+ let (show_branches_config, show_remotes_config) = config+ .list+ .as_ref()+ .map(|l| (l.branches.unwrap_or(false), l.remotes.unwrap_or(false)))+ .unwrap_or((false, false));++ // CLI flags override config+ let show_branches = branches || show_branches_config;+ let show_remotes = remotes || show_remotes_config;++ handle_select(show_branches, show_remotes, &config)+ })+ }#[cfg(not(unix))]- Commands::Select => {+ Commands::Select { .. } => {let _ = output::print(error_message("wt select is not available on Windows"));let _ = output::print(hint_message(cformat!("To see all worktrees, run <bright-black>wt list</>; to switch directly, run <bright-black>wt switch BRANCH</>"diff --git a/tests/integration_tests/select.rs b/tests/integration_tests/select.rsindex fa203d44e..ddf73e13b 100644--- a/tests/integration_tests/select.rs+++ b/tests/integration_tests/select.rs@@ -378,7 +378,7 @@ fn test_select_with_branches(mut repo: TestRepo) {let env_vars = repo.test_env_vars();let (raw_output, exit_code) = exec_in_pty_with_input(get_cargo_bin("wt").to_str().unwrap(),- &["select"],+ &["select", "--branches"],repo.root_path(),&env_vars,"\x1b", // Escape to abort@@ -583,3 +583,43 @@ fn test_new_feature() {let normalized = normalize_output(&screen);assert_snapshot!("select_preview_main_diff", normalized);}++#[rstest]+fn test_select_respects_list_config(mut repo: TestRepo) {+ repo.add_worktree("active-worktree");+ // Create a branch without a worktree+ let output = repo+ .git_command()+ .args(["branch", "orphan-branch"])+ .output()+ .unwrap();+ assert!(output.status.success(), "Failed to create branch");++ // Write user config with [list] branches = true+ // This should enable branches in wt select without the --branches flag+ repo.write_test_config(+ r#"+[list]+branches = true+"#,+ );++ let env_vars = repo.test_env_vars();+ let (raw_output, exit_code) = exec_in_pty_with_input(+ get_cargo_bin("wt").to_str().unwrap(),+ &["select"], // No --branches flag - config should enable it+ repo.root_path(),+ &env_vars,+ "\x1b", // Escape to abort+ );++ assert_valid_abort_exit_code(exit_code);++ let screen = render_terminal_screen(&raw_output);+ // Verify that orphan-branch appears (enabled by config, not CLI flag)+ assert!(+ screen.contains("orphan-branch"),+ "orphan-branch should appear when [list] branches = true in config.\nScreen:\n{}",+ screen+ );+}