ok/jj
1
0
Fork 0
forked from mirrors/jj

tree_builder: do not omit file entry which was previously a directory

This commit is contained in:
Yuya Nishihara 2023-05-31 22:30:20 +09:00
parent 68a30c934d
commit 3d449c55b7
2 changed files with 6 additions and 2 deletions

View file

@ -93,7 +93,11 @@ impl TreeBuilder {
if let Some((parent, basename)) = dir.split() { if let Some((parent, basename)) = dir.split() {
let parent_tree = trees_to_write.get_mut(&parent).unwrap(); let parent_tree = trees_to_write.get_mut(&parent).unwrap();
if tree.is_empty() { if tree.is_empty() {
parent_tree.remove(basename); if let Some(TreeValue::Tree(_)) = parent_tree.value(basename) {
parent_tree.remove(basename);
} else {
// Entry would have been replaced with file (see above)
}
} else { } else {
let tree_id = store.write_tree(&dir, &tree).unwrap(); let tree_id = store.write_tree(&dir, &tree).unwrap();
parent_tree.set(basename.clone(), TreeValue::Tree(tree_id)); parent_tree.set(basename.clone(), TreeValue::Tree(tree_id));

View file

@ -315,7 +315,7 @@ fn test_tree_builder_file_directory_transition(use_git: bool) {
testutils::write_normal_file(&mut tree_builder, &parent_path, ""); testutils::write_normal_file(&mut tree_builder, &parent_path, "");
let tree_id = tree_builder.write_tree(); let tree_id = tree_builder.write_tree();
check_out_tree(&tree_id); check_out_tree(&tree_id);
// TODO: assert!(parent_path.to_fs_path(&workspace_root).is_file()); assert!(parent_path.to_fs_path(&workspace_root).is_file());
assert!(!child_path.to_fs_path(&workspace_root).exists()); assert!(!child_path.to_fs_path(&workspace_root).exists());
} }