Skip to content

Commit

Permalink
tests: for ".jj" path, try both DOS and hashed NT short file names
Browse files Browse the repository at this point in the history
For some unknown reasons, hashed 8.3 file name is used on Github CI.
  • Loading branch information
yuja committed Nov 7, 2024
1 parent fdfe808 commit e0212cc
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions lib/tests/test_local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,26 +1617,38 @@ fn test_check_out_reserved_file_path_hfs_plus(file_path_str: &str) {
}
}

#[test_case("GIT~1/pwned"; "root .git dir short name")]
#[test_case("JJ~1/pwned"; "root .jj dir short name")]
#[test_case(".GIT./pwned"; "root .git dir trailing dots")]
#[test_case(".JJ../pwned"; "root .jj dir trailing dots")]
#[test_case("sub/.GIT.."; "sub .git file trailing dots")]
#[test_case("sub/.JJ."; "sub .jj file trailing dots")]
#[test_case(&["GIT~1/pwned"]; "root .git dir short name")]
#[test_case(&["JJ~1/pwned", "JJ2E09~1/pwned"]; "root .jj dir short name")]
#[test_case(&[".GIT./pwned"]; "root .git dir trailing dots")]
#[test_case(&[".JJ../pwned"]; "root .jj dir trailing dots")]
#[test_case(&["sub/.GIT.."]; "sub .git file trailing dots")]
#[test_case(&["sub/.JJ."]; "sub .jj file trailing dots")]
// TODO: Add more weird patterns?
// - https://en.wikipedia.org/wiki/8.3_filename ".GIxxxx~2"
// - See is_ntfs_dotgit() of Git and pathauditor of Mercurial
fn test_check_out_reserved_file_path_vfat(file_path_str: &str) {
fn test_check_out_reserved_file_path_vfat(file_path_strs: &[&str]) {
let settings = testutils::user_settings();
let mut test_workspace = TestWorkspace::init(&settings);
let repo = &test_workspace.repo;
let workspace_root = test_workspace.workspace.workspace_root().to_owned();
std::fs::create_dir(workspace_root.join(".git")).unwrap();
let is_vfat = check_vfat(&workspace_root);

let file_path = RepoPath::from_internal_string(file_path_str);
let disk_path = file_path.to_fs_path_unchecked(&workspace_root);
let tree1 = create_tree(repo, &[(file_path, "contents")]);
let file_paths = file_path_strs
.iter()
.map(|&s| RepoPath::from_internal_string(s))
.collect_vec();
let disk_paths = file_paths
.iter()
.map(|path| path.to_fs_path_unchecked(&workspace_root))
.collect_vec();
let tree1 = create_tree(
repo,
&file_paths
.iter()
.map(|&path| (path, "contents"))
.collect_vec(),
);
let tree2 = create_tree(repo, &[]);
let commit1 = commit_with_tree(repo.store(), tree1.id());
let commit2 = commit_with_tree(repo.store(), tree2.id());
Expand All @@ -1652,7 +1664,7 @@ fn test_check_out_reserved_file_path_vfat(file_path_str: &str) {

// Therefore, "pwned" file shouldn't be created.
if is_vfat {
assert!(!disk_path.exists());
assert!(!disk_paths.iter().all(|path| path.exists()));
}
assert!(!workspace_root.join(".git").join("pwned").exists());
assert!(!workspace_root.join(".jj").join("pwned").exists());
Expand All @@ -1663,8 +1675,10 @@ fn test_check_out_reserved_file_path_vfat(file_path_str: &str) {
let mut locked_ws = ws.start_working_copy_mutation().unwrap();
locked_ws.locked_wc().reset(&commit1).unwrap();
locked_ws.finish(repo.op_id().clone()).unwrap();
std::fs::create_dir_all(disk_path.parent().unwrap()).unwrap();
std::fs::write(&disk_path, "").unwrap();
for path in &disk_paths {
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(path, "").unwrap();
}

// Check out empty tree, which tries to remove the file.
let result = ws.check_out(repo.op_id().clone(), None, &commit2);
Expand All @@ -1676,7 +1690,7 @@ fn test_check_out_reserved_file_path_vfat(file_path_str: &str) {

// The existing file shouldn't be removed on VFAT-like fs.
if is_vfat {
assert!(disk_path.exists());
assert!(disk_paths.iter().all(|path| path.exists()));
}
}

Expand Down

0 comments on commit e0212cc

Please sign in to comment.