Skip to content

Commit

Permalink
view: test that merging divergent rewrites results in both commits vi…
Browse files Browse the repository at this point in the history
…sible

It seems that we didn't have a test for this simple case. I wrote this
test case while working on #111 but I don't know why I didn't push it
back then.
  • Loading branch information
martinvonz committed Dec 2, 2022
1 parent 47067c1 commit b80c39d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/tests/test_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,38 @@ fn commit_transactions(settings: &UserSettings, txs: Vec<Transaction>) -> Arc<Re
repo
}

#[test]
fn test_merge_views_divergent() {
// We start with just commit A. Operation 1 rewrites it as A2. Operation 2
// rewrites it as A3.
let settings = testutils::user_settings();
let test_repo = TestRepo::init(false);

let mut tx = test_repo.repo.start_transaction(&settings, "test");
let commit_a = create_random_commit(&settings, &test_repo.repo).write_to_repo(tx.mut_repo());
let repo = tx.commit();

let mut tx1 = repo.start_transaction(&settings, "test");
let commit_a2 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
.set_description("A2".to_string())
.write_to_repo(tx1.mut_repo());
tx1.mut_repo().rebase_descendants(&settings).unwrap();

let mut tx2 = repo.start_transaction(&settings, "test");
let commit_a3 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
.set_description("A3".to_string())
.write_to_repo(tx2.mut_repo());
tx2.mut_repo().rebase_descendants(&settings).unwrap();

let repo = commit_transactions(&settings, vec![tx1, tx2]);

// A2 and A3 should be heads.
assert_eq!(
*repo.view().heads(),
hashset! {commit_a2.id().clone(), commit_a3.id().clone()}
);
}

#[test_case(false ; "rewrite first")]
#[test_case(true ; "add child first")]
fn test_merge_views_child_on_rewritten(child_first: bool) {
Expand Down

0 comments on commit b80c39d

Please sign in to comment.