fix: diff view lists files in new folders and shows untracked content
build / version (push) Successful in 9s
build / build (aarch64-apple-darwin) (push) Successful in 4m27s
build / build (x86_64-unknown-linux-musl) (push) Successful in 3m47s
build / release (push) Successful in 19s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-15 23:13:12 +01:00
1 parent 8c4361acee
commit f652e607f6
1 file changed
+23 -1
+23 -1
View File
@@ -757,7 +757,7 @@ fn test_output(app: &App, id: &str) -> Pager {
fn diff_of(worktree: &str) -> Pager {
let git = |a: &[&str]| crate::run::git(Path::new(worktree), a);
let mut text = String::new();
match git(&["status", "--short"]) {
match git(&["status", "--short", "--untracked-files=all"]) {
Ok(s) if !s.trim().is_empty() => text.push_str(&format!("{s}\n")),
Ok(_) => {}
Err(e) => text.push_str(&format!("{e:#}\n")),
@@ -767,6 +767,20 @@ fn diff_of(worktree: &str) -> Pager {
Ok(s) => text.push_str(&s),
Err(e) => text.push_str(&format!("{e:#}")),
}
// `git diff HEAD` skips untracked files: show them as additions too.
// `--no-index` exits 1 when the files differ, so read stdout and ignore the status.
for f in git(&["ls-files", "--others", "--exclude-standard"])
.unwrap_or_default()
.lines()
{
if let Ok(o) = std::process::Command::new("git")
.args(["diff", "--no-index", "--", "/dev/null", f])
.current_dir(worktree)
.output()
{
text.push_str(&String::from_utf8_lossy(&o.stdout));
}
}
Pager {
title: "diff".into(),
lines: lines_of(&text),
@@ -1435,6 +1449,14 @@ end = "escalated"
assert!(tr.lines.last().unwrap().contains("ended: escalated"));
// the agent's (here: the shell's) untracked file shows up in the diff view
assert!(diff_of(&d.worktree).lines.iter().any(|l| l == "?? n"));
// files inside a new folder are listed one by one, not collapsed to "sub/"
std::fs::create_dir_all(Path::new(&d.worktree).join("sub")).unwrap();
std::fs::write(Path::new(&d.worktree).join("sub/f"), "x").unwrap();
let lines = diff_of(&d.worktree).lines;
assert!(lines.iter().any(|l| l == "?? sub/f"));
// and its content appears as an added file
assert!(lines.iter().any(|l| l == "+++ b/sub/f"), "{lines:?}");
assert!(lines.iter().any(|l| l == "+x"), "{lines:?}");
let _ = std::fs::remove_dir_all(&dir);
}