T13: a label built from a path shows control characters as their pictures, so a name with a newline no longer aborts gpui's line shaping in Files or the session row; on macOS a name meets Git's mark in composed form, as git writes it; the rev-parse prefix keeps its own newlines
CI / platforms (windows-latest) (push) Failing after 8s
CI / macos (push) Failing after 9m56s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-14 19:25:58 -04:00
1 parent 8369d96b36
commit 937dab8552
7 files changed
+167 -22

No files matched your search

+24 -5
View File
@@ -36,11 +36,15 @@ pub fn changes(folder: &Path) -> anyhow::Result<Option<Vec<(PathBuf, GitStatus)>
);
}
let place = String::from_utf8_lossy(&place.stdout);
let mut lines = place.lines();
if lines.next() != Some("true") {
return Ok(None);
}
let prefix = lines.next().context("git: rev-parse printed no prefix")?;
// The prefix may hold newlines of its own.
let answer = place
.strip_suffix('\n')
.and_then(|place| place.split_once('\n'));
let prefix = match answer {
Some(("true", prefix)) => prefix,
Some(("false", _)) => return Ok(None),
_ => bail!("git: rev-parse in {} printed {place:?}", folder.display()),
};
let status = git(folder, &["status", "--porcelain=v1", "-z", "--", "."])?;
if !status.status.success() {
let error = String::from_utf8_lossy(&status.stderr);
@@ -215,4 +219,19 @@ mod tests {
assert_eq!(changes(&root.join(".git")).expect("rev-parse"), None);
assert_eq!(changes(&folder("git-outside")).expect("rev-parse"), None);
}
#[cfg(unix)]
#[test]
fn a_folder_named_with_a_newline_keeps_its_whole_prefix() {
let root = folder("git-newline");
run(&root, &["init", "-q"]);
let inner = root.join("line\nbreak");
fs::create_dir_all(&inner).expect("a folder");
fs::write(inner.join("tracked.txt"), "first").expect("a file");
run(&root, &["add", "."]);
run(&root, &["commit", "-qm", "first"]);
fs::write(inner.join("tracked.txt"), "second").expect("an edit");
let edit = (inner.join("tracked.txt"), GitStatus::Modified);
assert_eq!(changes(&inner).expect("status"), Some(vec![edit]));
}
}