worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Add list ignore support for worktree paths and branch names

Open willpote opened this issue 8 months ago • 23 comments

Adds [list].ignore config. These are glob patterns that hide worktrees and branches from wt list output. Motivation is when using tools like Cursor, which generate worktrees for each agent running in parallel, wt list becomes cluttered with these temporary worktrees and un-usable.

  [list]
  ignore = ["tmp-*", "*/scratch/*"]

Per-project overrides work via the [projects."..."] table (inherits through OverridableConfig).

Each pattern is matched two ways:

  • As a path glob against the worktree's canonical filesystem path (e.g. /scratch/ matches worktrees inside a scratch/ directory)
  • As a string match against the branch name (e.g. tmp-* matches any branch starting with tmp-)

A worktree or branch is hidden if either matches. Filtering applies uniformly to worktrees, local branches (--branches), and remote branches (--remotes).

wt list --ignored bypasses all ignore filtering and shows everything.

When items are filtered, the summary line includes the count: Showing 3 worktrees, 1 ignored.

Changes

  • ignore: Option<Vec> field on ListConfig
  • --ignored CLI flag on wt list
  • Filtering in collect() after worktree/branch collection, before sorting — matches worktrees by path and branch name, local/remote branches by name
  • SummaryMetrics.ignored count shown in the summary line when > 0
  • glob crate added as a dependency
  • 6 integration tests: single glob, array globs, --ignored flag, parent path matching, branch name matching, --branches filtering

willpote avatar Mar 26 '26 01:03 willpote

I think I get the motivation, and I've had a similar experience at times

but I worry this might not quite pull its weight...

hardly my style to suggest multiple checkouts, but one approach is to give cursor another base checkout

OTOH I can't think of an easy way to do this without the feature. and we could make the downside less confusing with "X hidden" in the footer

max-sixty avatar Mar 26 '26 03:03 max-sixty

I think I get the motivation, and I've had a similar experience at times

but I worry this might not quite pull its weight...

hardly my style to suggest multiple checkouts, but one approach is to give cursor another base checkout

OTOH I can't think of an easy way to do this without the feature. and we could make the downside less confusing with "X hidden" in the footer

In the Cursor case, if you use the "Use multiple agents" feature when implementing something, it automatically spins up worktrees for you in ~/.cursor/worktrees, its not something another base checkout helps with unfortunately

Re: X hidden, i did add that to the summary message- not sure if this is what you meant but it says ○ Showing 1 worktree, 4 ignored, 1 with changes

willpote avatar Mar 26 '26 04:03 willpote

ok. let me think / let's see whether anyone else has thoughts

feel free to use @worktrunk-bot to fix tests etc

max-sixty avatar Mar 26 '26 04:03 max-sixty

Re: X hidden, i did add that to the summary message- not sure if this is what you meant but it says ○ Showing 1 worktree, 4 ignored, 1 with changes

I was thinking "8 hidden" could be here

max-sixty avatar Mar 26 '26 04:03 max-sixty

CI is failing because TestRepo::git_command() on main now returns worktrunk::shell_exec::Cmd (not std::process::Command), and Cmd has .run() but not .output().

The fix is in tests/integration_tests/list_config.rs lines 598 and 600 — change .output() to .run():

-                .output();
+                .run();
         }
-        let _ = repo.git_command().args(["branch", "-D", branch]).output();
+        let _ = repo.git_command().args(["branch", "-D", branch]).run();

The check-unused-dependencies failure (tree-sitter) is a pre-existing issue on main — not related to this PR.

worktrunk-bot avatar Mar 26 '26 04:03 worktrunk-bot

Re: X hidden, i did add that to the summary message- not sure if this is what you meant but it says ○ Showing 1 worktree, 4 ignored, 1 with changes

I was thinking "8 hidden" could be here

Right i added 'X ignored'. I can rename to 'X hidden' if you like

willpote avatar Mar 26 '26 05:03 willpote

Right i added 'X ignored'.

sorry, not sure how I missed that!

max-sixty avatar Mar 26 '26 05:03 max-sixty

@worktrunk-bot can we fix the tests, so we have a working PR to review?

max-sixty avatar Mar 28 '26 01:03 max-sixty

Fixed — merged main and changed .output() → .run() on the two Cmd calls in list_config.rs (lines 598, 600). All 1266 integration tests pass and lints are clean.

worktrunk-bot avatar Mar 28 '26 02:03 worktrunk-bot

@worktrunk-bot update dev/config.example.toml as suggested

willpote avatar Apr 06 '26 00:04 willpote

@max-sixty any thoughts on this change?

willpote avatar Apr 06 '26 00:04 willpote

Done — added ignore = ["tmp-*"] to the [list] section in the config docs source (src/cli/mod.rs), and regenerated all downstream files:

  • dev/config.example.toml (line 88)
  • docs/content/config.md
  • skills/worktrunk/reference/config.md
  • Help text snapshots for wt config and wt config create

worktrunk-bot avatar Apr 06 '26 00:04 worktrunk-bot

@worktrunk-bot do we label as experimental? can we do that if not?

thanks @willpote

max-sixty avatar Apr 06 '26 01:04 max-sixty

@worktrunk-bot can we review whether this should be ignore vs hidden? if we can switch to them etc, it should be "hidden"; it should only be "ignored" if we totally ignore it

max-sixty avatar Apr 06 '26 01:04 max-sixty

Done — labeled [list].ignore as experimental. Added [experimental] tags to:

  • The ## Filtering with ignore patterns docs section heading
  • The --ignored CLI flag description
  • The ignore line in the config example TOML

All downstream files regenerated (docs, skills, help snapshots).

worktrunk-bot avatar Apr 06 '26 01:04 worktrunk-bot

Reviewed the diff — the filtering only applies to wt list output. Worktrees matched by these patterns are still fully accessible for switch, merge, remove, and every other command. So this is display-level hiding, not functional ignoring.

Agree hidden is the right name. The rename would touch:

  • Config field: [list].ignore → [list].hidden
  • CLI flag: --ignored → --hidden (or --show-hidden)
  • Docs/messages: "ignored" → "hidden" throughout (summary line, section headings, help text)
  • Struct fields: ignore/ignored → hidden in ListConfig, ShowConfig, SummaryMetrics, collect()

The glob::Pattern matching logic stays the same — just a naming change.

@willpote would you like to make this rename, or should I put up a commit on the branch?

worktrunk-bot avatar Apr 06 '26 01:04 worktrunk-bot

@worktrunk-bot let's make the naming change and then if @willpote disagrees we can revert

max-sixty avatar Apr 06 '26 01:04 max-sixty

Done — renamed [list].ignore → [list].hidden and --ignored → --hidden throughout:

  • Config field, CLI flag, struct fields, variables, comments
  • All 6 integration tests (renamed functions + snapshot files)
  • Help text snapshots, docs, skill references, example configs

All 1339 integration tests + 492 unit tests pass, lints clean.

worktrunk-bot avatar Apr 06 '26 02:04 worktrunk-bot

@worktrunk-bot merge and resolve conflicts

max-sixty avatar Apr 08 '26 03:04 max-sixty

Merged main and resolved conflicts — main refactored List to use a ListArgs struct (along with Switch, Remove, Merge). Added the hidden field to ListArgs and updated the dispatch to pass it through. All 1393 integration tests pass, lints clean. Waiting on CI.

worktrunk-bot avatar Apr 08 '26 03:04 worktrunk-bot