Feature Discussion: `wt diff`
Curious if there is interest in a wt diff command that shows the changes that would be included in a wt merge from the current branch to a target branch.
Proposed: wt diff [target] [-p]
- Diffs from merge-base to working tree (includes uncommitted changes and untracked files, matching what
wt mergestages) - Default: stat summary.
-p: full patch.
◎ Comparing feature/my-branch → main
2 commits ahead, uncommitted changes
* a1b2c3d Add user authentication
* d4e5f6g Refactor login handler
src/auth/login.rs | 45 ++++++++++------
src/auth/session.rs | 12 +++
3 files changed, 98 insertions(+), 29 deletions(-)
untracked files
new-config.toml | 8 ++++++++
1 file added, 8 insertions(+)
I am happy to submit a draft pr if there is interest in this feature.
Motivation: One of the pain points for me is keeping track of all of the different agents and worktrees, so anything that makes it faster to get back into the context of a branch I find useful.
I empathize but I'm also wary of trying to replace the git CLI with wt, and git diff main... is very close to this...
wdyt?
That's a fair point about not duplicating the git cli. In this case however I don't think there is a clean cli equivalent because if I understand wt merge correctly, it will merge committed, staged, unstaged, and untracked changes.
Since this behavior is a deviation from the git cli patterns (stage then commit then merge), to get a view of consequences of the merge using the git cli you have to combine multiple commands. This also gives you disjointed and inconsistent formatting.
For example:
git diff main... only shows committed changes (misses staged, unstaged, and untracked).
git diff $(git merge-base HEAD main) picks up committed + staged + unstaged, but still no untracked (no form of git diff will include untracked files).
git status lists untracked file names but doesn't provide stat bars (in this case just line counts really but it's valuable information to know if a new file is adding 10 vs 1,000 lines).
git status also doesn't include committed changes, so you have to run it in combination with git diff main to get a full picture of all changes.
The closest I got to replicating what wt diff would try to provide (and it's possible I'm missing some git commands that could do this better) is to combine two separate and complicated git
commands:
Stat mode
git diff $(git merge-base HEAD main) --stat
git ls-files --others --exclude-standard
Patch mode
git diff $(git merge-base HEAD main)
for f in $(git ls-files --others --exclude-standard); do echo "--- $f ---"; cat "$f"; done
Although it's not the only value add (hooks as an obvious counter example), a huge part of the value of wt in my mind is taking stuff that is technically possible with the git cli but is a pain and making it easy.
I also respect the position if you decide that you want to keep wt tightly scoped and surgical and not expand too much.
I very much agree with the broader point!
I also tried to do a very similar workflow. I also struggled with the untracked flies, to the extent that I have an alias to add untracked files and then run the diff.
let me take another look at the commands above tomorrow; I agree if it were feasible to do this well (and not easy in git), something like wt step diff may well make sense
Sounds good. LMK.