From 4418f49c352a01041333d614835fc20d6098c8f1 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sat, 31 Oct 2026 13:23:20 +0800 Subject: [PATCH] test(vcs): keep the shelf path fixture legal on Windows (#541) Co-authored-by: a-rookie-of-C-language <186315048+a-rookie-of-C-language@users.noreply.github.com> --- crates/ide-vcs/tests/history_ops.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/ide-vcs/tests/history_ops.rs b/crates/ide-vcs/tests/history_ops.rs index 39b035572..dd854c949 100644 --- a/crates/ide-vcs/tests/history_ops.rs +++ b/crates/ide-vcs/tests/history_ops.rs @@ -568,14 +568,17 @@ fn update_branch_fast_forwards_a_branch_not_checked_out() { assert!(repo.update_branch("work", &cancel, &out).is_err()); } +/// `"` and tabs are illegal in Windows file names, and only they make Git quote a path. +const QUOTED: &str = if cfg!(windows) { "quote '.txt" } else { "quote\"\t.txt" }; + #[test] fn shelf_diff_and_scoped_operations_preserve_siblings() { let fx = Fixture::new(); - for path in ["a.txt", "b.txt", "quote\"\t.txt", "gone.txt"] { + for path in ["a.txt", "b.txt", QUOTED, "gone.txt"] { fx.write(path, "base\n"); } fx.commit_all("base"); - for path in ["a.txt", "b.txt", "quote\"\t.txt"] { + for path in ["a.txt", "b.txt", QUOTED] { fx.write(path, "shelved\n"); } std::fs::remove_file(fx.path("gone.txt")).unwrap(); @@ -583,7 +586,7 @@ fn shelf_diff_and_scoped_operations_preserve_siblings() { std::fs::write(fx.path("binary.dat"), [0, 1, 255]).unwrap(); let repo = fx.repo(); let shelf = fx._tmp.path().join("shelf"); - let paths = ["a.txt", "b.txt", "quote\"\t.txt", "gone.txt", "new.txt", "binary.dat"].map(|p| fx.path(p)); + let paths = ["a.txt", "b.txt", QUOTED, "gone.txt", "new.txt", "binary.dat"].map(|p| fx.path(p)); let entry = repo.shelve(&shelf, "work", &paths).unwrap(); fx.write("a.txt", "new head\n"); fx.commit_all("advance head"); @@ -591,7 +594,7 @@ fn shelf_diff_and_scoped_operations_preserve_siblings() { let status = fx.git(&["status", "--porcelain"]); let index = fx.git(&["ls-files", "--stage"]); let diffs = shelf::diff_files(&repo, &shelf, &entry.id).unwrap(); - for path in ["a.txt", "b.txt", "quote\"\t.txt"] { + for path in ["a.txt", "b.txt", QUOTED] { let f = diffs.iter().find(|f| f.path == path).unwrap(); assert_eq!(f.before.as_deref(), Some("base\n"), "{path}"); assert_eq!(f.after.as_deref(), Some("shelved\n"), "{path}"); @@ -609,7 +612,7 @@ fn shelf_diff_and_scoped_operations_preserve_siblings() { shelf::unshelve_path(&repo, &shelf, &entry.id, true, Some("b.txt")).unwrap(); assert_eq!(fx.read("b.txt"), "shelved\n"); assert!(!shelf::list(&shelf).unwrap()[0].files.iter().any(|f| f.path == "b.txt")); - shelf::delete_path(&shelf, &entry.id, Some("quote\"\t.txt")).unwrap(); + shelf::delete_path(&shelf, &entry.id, Some(QUOTED)).unwrap(); assert!(shelf::selected_patch(&shelf, &entry.id, Some("a.txt")).is_ok()); shelf::import_patch(&shelf, "imported", &patch).unwrap(); assert_eq!(shelf::list(&shelf).unwrap().len(), 2);