Skip to content

feat(error): list dirty files in UncommittedChanges - #2653

Merged
max-sixty merged 2 commits into
mainfrom
flaky-tests
May 9, 2026
Merged

max-sixty merged 2 commits into
mainfrom
flaky-tests

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

The "X has uncommitted changes" error now lists the offending files via
git status --porcelain between the title and the hint, instead of leaving
the user to re-run git status to find out what's dirty.

Before:

✗ Cannot remove worktree after merge: feature-auth has uncommitted changes
↳ Commit or stash changes first

After:

✗ Cannot remove worktree after merge: feature-auth has uncommitted changes
   M auth.rs
  ?? .DS_Store
↳ Commit or stash changes first

What changed

  • GitError::UncommittedChanges carries a new dirty_files: Vec<String> field (raw porcelain lines).
  • WorkingTree::ensure_clean runs through a new dirty_files() helper that returns the porcelain lines instead of discarding them; the four call sites (wt merge cleanup, wt remove, wt step promote × 2) now thread the file list into the error.
  • wt merge --no-commit validator in commands/merge.rs:155 does the same.
  • No new git subprocesses: is_dirty() was already running git status --porcelain and dropping the output. We just stop dropping it on the failure path.
  • 5 existing snapshots updated; 1 new test case added.

Why

A user hitting "feature has uncommitted changes" today has to re-run git status to see what's blocking. The list is information we already have.

There's a side benefit: this surfaces dirty state in test snapshots when something unexpected dirties a worktree mid-merge — useful for diagnosing the local-only flake on test_readme_example_complex etc., where the failing snapshot will now carry the exact file list (likely an OS metadata file like .DS_Store or an fsmonitor artifact) rather than a worktrunk bug.

Test plan

  • cargo test --lib (1098 passed)
  • cargo test --test integration (1633 passed; 1 new test case)
  • cargo run -- hook pre-merge --yes — full lint + test suite (3531 passed, lints clean)
  • Snapshots reviewed; new format renders correctly across merge / remove / promote / git-error-display tests.

🤖 Generated with Claude Code

`UncommittedChanges` now carries the `git status --porcelain` lines and
renders them as a dim, indented block between the title and the hint, so
"feature has uncommitted changes" tells the user *which* files. Plumbed
through `WorkingTree::ensure_clean` (a new `dirty_files()` helper runs
porcelain once and returns the lines) and the `--no-commit` validator in
`wt merge`. Empty vec is allowed; the field is additive.

Affects every ensure_clean caller — merge cleanup, remove, promote main +
target — plus `wt merge --no-commit` validation. No new git subprocesses:
`is_dirty()` already ran porcelain; we just stop discarding its output on
the failure path.

Side benefit: surfaces what dirty state caused a flaky-test report. When
`test_readme_example_complex` flakes locally with "feature-auth has
uncommitted changes" mid-merge, the failing snapshot will now contain the
exact file list — likely an OS metadata file (`.DS_Store`, fsmonitor
artifact) rather than a worktrunk bug. See INVESTIGATION.md (untracked,
local).

Co-Authored-By: Claude <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit on the new test case — see inline.

Comment thread src/git/error.rs Resolved
Per review on #2653: the four other cases in this test use inline `@"..."`
snapshots; the new fifth case was left as `assert_snapshot!(err.render())`
which made cargo-insta materialize an external `.snap` under
`src/git/snapshots/`. Per `tests/CLAUDE.md` ("Inline snapshots over
multi-assert"), inline is the convention. Drops the external file too.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 4dd84ca into main May 9, 2026
33 checks passed
@max-sixty
max-sixty deleted the flaky-tests branch May 9, 2026 19:59
@max-sixty max-sixty mentioned this pull request May 10, 2026
3 tasks done
max-sixty added a commit that referenced this pull request May 10, 2026
Bump worktrunk to **0.49.0** — minor bump (semver-checks reports a
breaking change in `GitError::UncommittedChanges`, which gained a
`dirty_files: Vec<String>` field).

## Highlights

**Improved**
- New `codename(n)` template filter — deterministic friendly worktree
names from a ~1.26M-combo pool (`{{ branch | codename(2) }}` →
`malleable-opah`).
[#2641](#2641), thanks
@endigma
- Picker preview disk cache for Log / BranchDiff / UpstreamDiff, with
background refresh for stale Log decorations.
[#2628](#2628),
[#2646](#2646)
- Picker shares one `default_branch_sha` lookup across BranchDiff items
instead of forking N rev-parse subprocesses.
[#2658](#2658)
- "X has uncommitted changes" errors now list the dirty files inline.
[#2653](#2653)

**Fixed**
- `wt switch` integrates with `cd` aliases like zoxide (uses `builtin
cd`). [#2644](#2644), thanks
@xkumiyu for reporting
- Empty hook tables no longer panic during `wt switch --create`.
[#2635](#2635), thanks @topit
for reporting
- `Repository::current_worktree()` and five sibling helpers no longer
silently leak the process CWD when called via `Repository::at(p)`.
[#2652](#2652)
- `WorkingTree::is_linked` tolerates non-git CWDs (e.g. Nix sandbox).
[#2625](#2625), thanks
@DArtagan for reporting
- Picker no longer overlays `collect` warnings on the active TUI; clears
its frame on exit in inline mode.
[#2627](#2627),
[#2626](#2626)
- Failed `git log` no longer poisons the picker's preview disk cache.
[#2651](#2651)
- `wt step prune` says "removing branch" for branch-only candidates.
[#2619](#2619)
- Claude Code Windows integration uses a `wt.sh` wrapper to avoid
colliding with Windows Terminal's `wt.exe`.
[#1754](#1754), thanks
@lucaspimentel

**Documentation**
- cmux workspace integration recipe.
[#1907](#1907), thanks
@alvistar

See
[CHANGELOG.md](https://github.com/max-sixty/worktrunk/blob/release/CHANGELOG.md)
for the full list including internal CI / test-isolation changes.

## Test plan

- [x] `cargo run -- hook pre-merge --yes` (tests + lints clean)
- [x] `cargo semver-checks check-release -p worktrunk` (one breaking
change confirmed → minor bump)
- [x] CHANGELOG entries verified by subagent against actual diffs

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants