diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index cb0b7f7434..c470649fc5 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -32,7 +32,7 @@ use jj_lib::git::{ use jj_lib::git_backend::GitBackend; use jj_lib::object_id::ObjectId; use jj_lib::op_store::{BranchTarget, RefTarget, RemoteRef, RemoteRefState}; -use jj_lib::refs::BranchPushUpdate; +use jj_lib::refs::{merge_ref_targets, BranchPushUpdate}; use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo}; use jj_lib::settings::{GitSettings, UserSettings}; use jj_lib::signing::Signer; @@ -2789,12 +2789,21 @@ fn test_push_branches_unexpectedly_moved_sideways_on_remote() { let sideways_commit = write_random_commit(tx.mut_repo(), &settings); setup.jj_repo = tx.commit("test"); let mut tx = setup.jj_repo.start_transaction(&settings); + let index = setup.jj_repo.index(); // The main branch is actually at `initial_commit` on the remote. If we expected // it to be at `sideways_commit`, we cannot delete it or move it anywhere else. // However, "moving" it to the same place it already is is OK, following the // behavior in `test_merge_ref_targets`. + let result = merge_ref_targets( + index, + RefTarget::absent_ref(), + &RefTarget::normal(sideways_commit.id().clone()), + &RefTarget::normal(setup.initial_commit.id().clone()), + ); + assert_ne!(result, RefTarget::absent()); + dbg!(result); let targets = GitBranchPushTargets { branch_updates: vec![( "main".to_owned(), @@ -2826,6 +2835,17 @@ fn test_push_branches_unexpectedly_moved_sideways_on_remote() { ) "###); + let result = merge_ref_targets( + index, + &RefTarget::normal(setup.child_of_initial_commit.id().clone()), + &RefTarget::normal(sideways_commit.id().clone()), + &RefTarget::normal(setup.initial_commit.id().clone()), + ); + assert_ne!( + result, + RefTarget::normal(setup.child_of_initial_commit.id().clone()) + ); + dbg!(result); let targets = GitBranchPushTargets { branch_updates: vec![( "main".to_owned(), @@ -2920,6 +2940,14 @@ fn test_push_branches_unexpectedly_moved_sideways_on_remote() { "###); // Moving the branch to the same place it already is is OK. + let result = merge_ref_targets( + index, + &RefTarget::normal(setup.initial_commit.id().clone()), + &RefTarget::normal(sideways_commit.id().clone()), + &RefTarget::normal(setup.initial_commit.id().clone()), + ); + assert_eq!(result, RefTarget::normal(setup.initial_commit.id().clone())); + dbg!(result); let targets = GitBranchPushTargets { branch_updates: vec![( "main".to_owned(),