Skip to content

Commit

Permalink
better test for bug jj-vcs#3223
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed May 17, 2024
1 parent ffc50a5 commit e26c139
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/tests/test_local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::os::unix::net::UnixListener;
use std::path::Path;
use std::sync::Arc;

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};
Expand Down Expand Up @@ -290,6 +291,61 @@ fn test_conflict_subdirectory() {
.unwrap();
}

#[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 commit1 = commit_with_tree(repo.store(), tree1.id());
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, &commit1).unwrap();
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();
// 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();
Expand Down

0 comments on commit e26c139

Please sign in to comment.