From 2b20a248fabc800cd7ffbccb7062901c48ae2e45 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Thu, 2 May 2024 17:00:20 -0700 Subject: [PATCH] better test for bug #3223 --- lib/tests/test_local_working_copy.rs | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/lib/tests/test_local_working_copy.rs b/lib/tests/test_local_working_copy.rs index 361aa7aed7..d17683898c 100644 --- a/lib/tests/test_local_working_copy.rs +++ b/lib/tests/test_local_working_copy.rs @@ -20,6 +20,7 @@ use std::path::Path; use std::sync::Arc; use indoc::indoc; +use insta::{assert_debug_snapshot, assert_snapshot}; use itertools::Itertools; use jj_lib::backend::{MergedTreeId, TreeId, TreeValue}; use jj_lib::file_util::{check_symlink_support, try_symlink}; @@ -385,6 +386,59 @@ fn test_acl() { assert!(became_public_path.to_fs_path(&workspace_root).is_file()); } +#[test] +fn test_conflict_empty_vs_nonempty_issue_3223() { + let settings = testutils::user_settings(); + let mut test_workspace = TestWorkspace::init(&settings); + let repo = &test_workspace.repo; + + let path = RepoPath::from_internal_string("file"); + let empty_tree = create_tree(repo, &[]); + let tree1 = create_tree(repo, &[(path, "")]); // empty file + let tree2 = create_tree(repo, &[(path, "nonempty")]); + let merged_tree = tree1.merge(&empty_tree, &tree2).unwrap(); + // The tree representation is conflicted... + assert_debug_snapshot!(tree_entries(&merged_tree), @r###" + [ + ( + "file", + Some( + Conflicted( + [ + Some( + File { + id: FileId( + "482ae5a29fbe856c7272", + ), + executable: false, + }, + ), + None, + Some( + File { + id: FileId( + "2f381f1aab1e326fe57d", + ), + executable: false, + }, + ), + ], + ), + ), + ), + ] + "###); + let merged_commit = commit_with_tree(repo.store(), merged_tree.id()); + let repo = &test_workspace.repo; + let ws = &mut test_workspace.workspace; + ws.check_out(repo.op_id().clone(), None, &merged_commit) + .unwrap(); + let file_contents = std::fs::read_to_string(path.to_fs_path(ws.workspace_root())).unwrap(); + // BUG: The file on disk does *not* have conflict markers. So, it's + // impossible to resolve the conflict. + assert_snapshot!(file_contents, @"nonempty"); +} + #[test] fn test_tree_builder_file_directory_transition() { let settings = testutils::user_settings();