Skip to content

Commit

Permalink
parent_of_initial_git_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed May 9, 2024
1 parent 25daeb8 commit 3ff3980
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2439,15 +2439,25 @@ struct PushTestSetup {
source_repo_dir: PathBuf,
jj_repo: Arc<ReadonlyRepo>,
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();
Expand Down Expand Up @@ -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();
Expand All @@ -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,
}
}

Expand All @@ -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! {},
Expand All @@ -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
Expand All @@ -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,
},
);
Expand Down Expand Up @@ -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()),
},
),
],
Expand All @@ -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());
Expand All @@ -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,
},
);
Expand Down Expand Up @@ -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(),
);
Expand All @@ -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
Expand All @@ -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(),
);
Expand All @@ -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(),
);
Expand Down

0 comments on commit 3ff3980

Please sign in to comment.