From 3ff3980b3bf5786258d44181838a9de72e0a590c Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Wed, 8 May 2024 21:26:36 -0700 Subject: [PATCH] parent_of_initial_git_commit --- lib/tests/test_git.rs | 47 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index a78523532f..b7a334b348 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -2439,15 +2439,25 @@ struct PushTestSetup { source_repo_dir: PathBuf, jj_repo: Arc, initial_commit: Commit, - new_commit: Commit, + child_of_initial_commit: Commit, + #[allow(dead_code)] // For next commit + parent_of_initial_commit: Commit, } +/// Set up a situation where `main` is at `initial_commit`, the child of +/// `parent_of_initial_commit`, both in the source repo and in jj's clone of the +/// repo. In jj's clone, there is also `child_of_initial_commit.` fn set_up_push_repos(settings: &UserSettings, temp_dir: &TempDir) -> PushTestSetup { let source_repo_dir = temp_dir.path().join("source"); let clone_repo_dir = temp_dir.path().join("clone"); let jj_repo_dir = temp_dir.path().join("jj"); let source_repo = git2::Repository::init_bare(&source_repo_dir).unwrap(); - let initial_git_commit = empty_git_commit(&source_repo, "refs/heads/main", &[]); + let parent_of_initial_git_commit = empty_git_commit(&source_repo, "refs/heads/main", &[]); + let initial_git_commit = empty_git_commit( + &source_repo, + "refs/heads/main", + &[&parent_of_initial_git_commit], + ); let clone_repo = git2::Repository::clone(source_repo_dir.to_str().unwrap(), clone_repo_dir).unwrap(); std::fs::create_dir(&jj_repo_dir).unwrap(); @@ -2475,8 +2485,12 @@ fn set_up_push_repos(settings: &UserSettings, temp_dir: &TempDir) -> PushTestSet .store() .get_commit(&jj_id(&initial_git_commit)) .unwrap(); + let parent_of_initial_commit = jj_repo + .store() + .get_commit(&jj_id(&parent_of_initial_git_commit)) + .unwrap(); let mut tx = jj_repo.start_transaction(settings); - let new_commit = create_random_commit(tx.mut_repo(), settings) + let child_of_initial_commit = create_random_commit(tx.mut_repo(), settings) .set_parents(vec![initial_commit.id().clone()]) .write() .unwrap(); @@ -2499,7 +2513,8 @@ fn set_up_push_repos(settings: &UserSettings, temp_dir: &TempDir) -> PushTestSet source_repo_dir, jj_repo, initial_commit, - new_commit, + child_of_initial_commit, + parent_of_initial_commit, } } @@ -2516,7 +2531,7 @@ fn test_push_branches_success() { "main".to_owned(), BranchPushUpdate { old_target: Some(setup.initial_commit.id().clone()), - new_target: Some(setup.new_commit.id().clone()), + new_target: Some(setup.child_of_initial_commit.id().clone()), }, )], force_pushed_branches: hashset! {}, @@ -2536,7 +2551,7 @@ fn test_push_branches_success() { .find_reference("refs/heads/main") .unwrap() .target(); - let new_oid = git_id(&setup.new_commit); + let new_oid = git_id(&setup.child_of_initial_commit); assert_eq!(new_target, Some(new_oid)); // Check that the ref got updated in the cloned repo. This just tests our @@ -2552,12 +2567,12 @@ fn test_push_branches_success() { let view = tx.mut_repo().view(); assert_eq!( *view.get_git_ref("refs/remotes/origin/main"), - RefTarget::normal(setup.new_commit.id().clone()), + RefTarget::normal(setup.child_of_initial_commit.id().clone()), ); assert_eq!( *view.get_remote_branch("main", "origin"), RemoteRef { - target: RefTarget::normal(setup.new_commit.id().clone()), + target: RefTarget::normal(setup.child_of_initial_commit.id().clone()), state: RemoteRefState::Tracking, }, ); @@ -2643,7 +2658,7 @@ fn test_push_branches_mixed_deletion_and_addition() { "topic".to_owned(), BranchPushUpdate { old_target: None, - new_target: Some(setup.new_commit.id().clone()), + new_target: Some(setup.child_of_initial_commit.id().clone()), }, ), ], @@ -2664,7 +2679,7 @@ fn test_push_branches_mixed_deletion_and_addition() { .find_reference("refs/heads/topic") .unwrap() .target(); - assert_eq!(new_target, Some(git_id(&setup.new_commit))); + assert_eq!(new_target, Some(git_id(&setup.child_of_initial_commit))); // Check that the main ref got deleted in the source repo assert!(source_repo.find_reference("refs/heads/main").is_err()); @@ -2675,12 +2690,12 @@ fn test_push_branches_mixed_deletion_and_addition() { assert!(view.get_remote_branch("main", "origin").is_absent()); assert_eq!( *view.get_git_ref("refs/remotes/origin/topic"), - RefTarget::normal(setup.new_commit.id().clone()), + RefTarget::normal(setup.child_of_initial_commit.id().clone()), ); assert_eq!( *view.get_remote_branch("topic", "origin"), RemoteRef { - target: RefTarget::normal(setup.new_commit.id().clone()), + target: RefTarget::normal(setup.child_of_initial_commit.id().clone()), state: RemoteRefState::Tracking, }, ); @@ -2775,7 +2790,7 @@ fn test_push_updates_success() { qualified_name: "refs/heads/main".to_string(), force: false, expected_current_target: Some(setup.initial_commit.id().clone()), - new_target: Some(setup.new_commit.id().clone()), + new_target: Some(setup.child_of_initial_commit.id().clone()), }], git::RemoteCallbacks::default(), ); @@ -2787,7 +2802,7 @@ fn test_push_updates_success() { .find_reference("refs/heads/main") .unwrap() .target(); - let new_oid = git_id(&setup.new_commit); + let new_oid = git_id(&setup.child_of_initial_commit); assert_eq!(new_target, Some(new_oid)); // Check that the ref got updated in the cloned repo. This just tests our @@ -2812,7 +2827,7 @@ fn test_push_updates_no_such_remote() { qualified_name: "refs/heads/main".to_string(), force: false, expected_current_target: Some(setup.initial_commit.id().clone()), - new_target: Some(setup.new_commit.id().clone()), + new_target: Some(setup.child_of_initial_commit.id().clone()), }], git::RemoteCallbacks::default(), ); @@ -2831,7 +2846,7 @@ fn test_push_updates_invalid_remote() { qualified_name: "refs/heads/main".to_string(), force: false, expected_current_target: Some(setup.initial_commit.id().clone()), - new_target: Some(setup.new_commit.id().clone()), + new_target: Some(setup.child_of_initial_commit.id().clone()), }], git::RemoteCallbacks::default(), );