Skip to content

Commit

Permalink
Add a test to verify that jj-vcs#2766 was fixed.
Browse files Browse the repository at this point in the history
Also verified that this fails without the previous commit.
  • Loading branch information
matts1 committed Jan 3, 2024
1 parent a9a62d5 commit 54e96fa
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion lib/tests/test_rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use jj_lib::merged_tree::MergedTree;
use jj_lib::op_store::{RefTarget, RemoteRef, RemoteRefState, WorkspaceId};
use jj_lib::repo::Repo;
use jj_lib::repo_path::RepoPath;
use jj_lib::rewrite::{restore_tree, EmptyBehaviour, RebaseOptions};
use jj_lib::rewrite::{rebase_commit_with_options, restore_tree, EmptyBehaviour, RebaseOptions};
use maplit::{hashmap, hashset};
use test_case::test_case;
use testutils::{
Expand Down Expand Up @@ -1612,3 +1612,56 @@ fn test_empty_commit_option(empty_behavior: EmptyBehaviour) {
}
);
}

#[test]
fn test_rebase_commit_via_rebase_api() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init();
let repo = &test_repo.repo;

// Rebase B onto B2
//
// C
// |
// B B2
// |/
// A
let mut tx = repo.start_transaction(&settings);
let commit_a = write_random_commit(tx.mut_repo(), &settings);
let commit_b = create_random_commit(tx.mut_repo(), &settings)
.set_parents(vec![commit_a.id().clone()])
.write()
.unwrap();
let commit_c = create_random_commit(tx.mut_repo(), &settings)
.set_parents(vec![commit_b.id().clone()])
.write()
.unwrap();
let commit_b2 = create_random_commit(tx.mut_repo(), &settings)
.set_parents(vec![commit_a.id().clone()])
.set_tree_id(commit_b.tree_id().clone())
.write()
.unwrap();

let commit_b2_id = commit_b2.id().clone();
rebase_commit_with_options(
&settings,
tx.mut_repo(),
&commit_b,
&[commit_b2],
&RebaseOptions {
empty: EmptyBehaviour::AbandonAllEmpty,
},
)
.unwrap();
let rebase_map = tx
.mut_repo()
.rebase_descendants_return_map(&settings)
.unwrap();
assert_eq!(rebase_map.len(), 1);
let new_commit_c = assert_rebased_onto(tx.mut_repo(), &rebase_map, &commit_c, &[&commit_b2_id]);

assert_eq!(
*tx.mut_repo().view().heads(),
hashset! {new_commit_c.id().clone()}
);
}

0 comments on commit 54e96fa

Please sign in to comment.