Add tests for integrate_upstream_commits_for_series assuring same behavior

This commit is contained in:
Kiril Videlov 2024-10-17 11:30:07 +02:00
parent 169fe207ce
commit dd6d62cf42
No known key found for this signature in database
GPG Key ID: A4C733025427C471

View File

@ -348,6 +348,75 @@ mod test {
.unwrap(),
vec![remote_y.id(), remote_x.id(), local_b.id(), local_a.id()],
);
// Also ensure the series implementation does the same thing
let (BranchHeadAndTree { head, tree: _tree }, _) = ctx
.inner_integrate_upstream_commits_for_series(local_b.id())
.unwrap();
assert_eq!(
test_repository
.repository
.l(head, LogUntil::Commit(base_commit.id()), false)
.unwrap(),
vec![remote_y.id(), remote_x.id(), local_b.id(), local_a.id()],
);
}
/// Full Stack: Base -> A -> B -> C -> D
/// Series One: A -> B
/// Series Two: C -> D
/// Series One Remote: A -> B -> X -> Y
///
/// Result Stack: Base -> A -> B -> X -> Y -> C -> D
/// Result Series One Head: Y
#[test]
fn other_added_remote_changes_multiple_series() {
let test_repository = TestingRepository::open();
let base_commit = test_repository.commit_tree(None, &[("foo.txt", "foo")]);
let local_a = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "foo1")]);
let local_b = test_repository.commit_tree(Some(&local_a), &[("foo.txt", "foo2")]);
let local_c = test_repository.commit_tree(Some(&local_b), &[("foo.txt", "fooC")]);
let local_d = test_repository.commit_tree(Some(&local_c), &[("foo.txt", "fooD")]);
let remote_x = test_repository.commit_tree(Some(&local_b), &[("foo.txt", "foo3")]);
let remote_y = test_repository.commit_tree(Some(&remote_x), &[("foo.txt", "foo4")]);
let ctx = IntegrateUpstreamContext {
repository: &test_repository.repository,
target_branch_head: base_commit.id(),
branch_head: local_d.id(),
branch_tree: local_d.tree_id(),
branch_name: "test",
remote_head: remote_y.id(),
remote_branch_name: "test",
prefers_merge: false,
};
let (BranchHeadAndTree { head, tree: _tree }, new_series_head) = ctx
.inner_integrate_upstream_commits_for_series(local_b.id()) // series head is earlier than stack head
.unwrap();
assert_eq!(new_series_head, remote_y.id());
assert_eq!(
test_repository
.repository
.l(head, LogUntil::Commit(base_commit.id()), false)
.unwrap()
.iter()
.map(|c| {
let commit = test_repository.repository.find_commit(*c).unwrap();
commit.message().unwrap().to_string()
})
.collect::<Vec<_>>(),
vec![
local_d.message().unwrap(),
local_c.message().unwrap(),
remote_y.message().unwrap(),
remote_x.message().unwrap(),
local_b.message().unwrap(),
local_a.message().unwrap()
],
);
}
/// Local: Base -> A -> B
@ -427,6 +496,43 @@ mod test {
);
assert_commit_tree_matches(&test_repository.repository, &new_a, &[("foo.txt", b"foo")]);
// Ensure the series implementation does the same
let (BranchHeadAndTree { head, tree: _tree }, _) = ctx
.inner_integrate_upstream_commits_for_series(local_b.id())
.unwrap();
let commits = test_repository
.repository
.log(head, LogUntil::Commit(base_commit.id()), false)
.unwrap();
assert_eq!(commits.len(), 4);
let new_y = commits[0].clone();
let new_b_prime = commits[1].clone();
let new_b = commits[2].clone();
let new_a = commits[3].clone();
assert_commit_tree_matches(
&test_repository.repository,
&new_y,
&[("foo.txt", b"foo3")],
);
assert_commit_tree_matches(
&test_repository.repository,
&new_b_prime,
&[("foo.txt", b"foo1"), ("bar.txt", b"foo2")],
);
assert_commit_tree_matches(
&test_repository.repository,
&new_b,
&[("foo.txt", b"foo1")],
);
assert_commit_tree_matches(&test_repository.repository, &new_a, &[("foo.txt", b"foo")]);
}
/// Local: Base -> A -> B
@ -518,6 +624,55 @@ mod test {
);
assert_commit_tree_matches(&test_repository.repository, &new_a, &[("foo.txt", b"foo")]);
// Also ensure the series implementation does the same thing
let (BranchHeadAndTree { head, tree: _tree }, _) = ctx
.inner_integrate_upstream_commits_for_series(local_b.id())
.unwrap();
let commits = test_repository
.repository
.log(head, LogUntil::Commit(base_commit.id()), false)
.unwrap();
assert_eq!(commits.len(), 4);
let new_y = commits[0].clone();
let new_b_prime = commits[1].clone();
let new_b = commits[2].clone();
let new_a = commits[3].clone();
assert!(new_y.is_conflicted());
assert_commit_tree_matches(
&test_repository.repository,
&new_y,
&[
(".auto-resolution/foo.txt", b"foo1"),
(".conflict-base-0/foo.txt", b"foo2"),
(".conflict-side-0/foo.txt", b"foo1"),
(".conflict-side-1/foo.txt", b"foo3"),
],
);
assert!(new_b_prime.is_conflicted());
assert_commit_tree_matches(
&test_repository.repository,
&new_b_prime,
&[
(".auto-resolution/foo.txt", b"foo1"),
(".conflict-base-0/foo.txt", b"foo"),
(".conflict-side-0/foo.txt", b"foo1"),
(".conflict-side-1/foo.txt", b"foo2"),
],
);
assert_commit_tree_matches(
&test_repository.repository,
&new_b,
&[("foo.txt", b"foo1")],
);
assert_commit_tree_matches(&test_repository.repository, &new_a, &[("foo.txt", b"foo")]);
}
/// Local: Base -> A -> B
@ -591,6 +746,36 @@ mod test {
);
assert_commit_tree_matches(&test_repository.repository, &new_a, &[("foo.txt", b"foo")]);
// Also ensure the series implementation does the same thing
let (BranchHeadAndTree { head, tree: _tree }, _) = ctx
.inner_integrate_upstream_commits_for_series(local_b.id())
.unwrap();
let commits = test_repository
.repository
.log(head, LogUntil::Commit(base_commit.id()), false)
.unwrap();
assert_eq!(commits.len(), 3);
let new_y = commits[0].clone();
let new_b = commits[1].clone();
let new_a = commits[2].clone();
assert_commit_tree_matches(
&test_repository.repository,
&new_y,
&[("foo.txt", b"foo3")],
);
assert_commit_tree_matches(
&test_repository.repository,
&new_b,
&[("foo.txt", b"foo1")],
);
assert_commit_tree_matches(&test_repository.repository, &new_a, &[("foo.txt", b"foo")]);
}
}