Skip to content

Commit

Permalink
MutableRepo: add test of updating away from empty merge commit
Browse files Browse the repository at this point in the history
Merge commits are very similar to non-merge commits in jj. An empty
merge commit with no description is not really different from an empty
non-merge commit with no description. As we discussed on
#2859, we should not treat
merge commits differently when updating away from them. This patch
adds test for the current behavior (which is to leave the merge commit
in place).
  • Loading branch information
martinvonz committed May 28, 2024
1 parent b02a181 commit afeb5c2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/tests/test_mut_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,46 @@ fn test_edit_previous_empty() {
assert!(!mut_repo.view().heads().contains(old_wc_commit.id()));
}

#[test]
fn test_edit_previous_empty_merge() {
// Test that MutableRepo::edit() abandons the previous commit if it was
// an empty merge commit.
let settings = testutils::user_settings();
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

let mut tx = repo.start_transaction(&settings);
let mut_repo = tx.mut_repo();
let old_parent1 = write_random_commit(mut_repo, &settings);
let old_parent2 = write_random_commit(mut_repo, &settings);
let empty_tree = repo.store().root_commit().tree().unwrap();
let old_parent_tree = old_parent1
.tree()
.unwrap()
.merge(&empty_tree, &old_parent2.tree().unwrap())
.unwrap();
let old_wc_commit = mut_repo
.new_commit(
&settings,
vec![old_parent1.id().clone(), old_parent2.id().clone()],
repo.store().empty_merged_tree_id(),
)
.set_tree_id(old_parent_tree.id())
.write()
.unwrap();
let ws_id = WorkspaceId::default();
mut_repo.edit(ws_id.clone(), &old_wc_commit).unwrap();
let repo = tx.commit("test");

let mut tx = repo.start_transaction(&settings);
let mut_repo = tx.mut_repo();
let new_wc_commit = write_random_commit(mut_repo, &settings);
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
mut_repo.rebase_descendants(&settings).unwrap();
// TODO: The old commit should no longer be visible
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
}

#[test]
fn test_edit_previous_empty_with_description() {
// Test that MutableRepo::edit() does not abandon the previous commit if it
Expand Down

0 comments on commit afeb5c2

Please sign in to comment.