Skip to content

Commit

Permalink
tests: demonstrate spurious branch conflict after git export
Browse files Browse the repository at this point in the history
This is a test case for #463. It's not exactly the same case, but I'm
confident that the root cause is the same (that the
`.jj/repo/git_export_operation_id` doesn't include the git refs we
just updated).
  • Loading branch information
martinvonz committed Nov 3, 2022
1 parent 8dd7400 commit 12e07b1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,57 @@ fn test_export_refs_unborn_git_branch() {
assert!(!git_repo.head_detached().unwrap());
}

#[test]
fn test_export_import_sequence() {
// Import a branch pointing to A, modify it in jj to point to B, export it,
// modify it in git to point to C, then import it again. There should be no
// conflict.
let mut test_data = GitRepoData::create();
let git_repo = test_data.git_repo;
let mut tx = test_data.repo.start_transaction("test");
let commit_a =
create_random_commit(&test_data.settings, &test_data.repo).write_to_repo(tx.mut_repo());
let commit_b =
create_random_commit(&test_data.settings, &test_data.repo).write_to_repo(tx.mut_repo());
let commit_c =
create_random_commit(&test_data.settings, &test_data.repo).write_to_repo(tx.mut_repo());
test_data.repo = tx.commit();

// Import the branch pointing to A
git_repo
.reference("refs/heads/main", git_id(&commit_a), true, "test")
.unwrap();
let mut tx = test_data.repo.start_transaction("test");
git::import_refs(tx.mut_repo(), &git_repo).unwrap();
test_data.repo = tx.commit();

// Modify the branch in jj to point to B
let mut tx = test_data.repo.start_transaction("test");
tx.mut_repo()
.set_local_branch("main".to_string(), RefTarget::Normal(commit_b.id().clone()));
test_data.repo = tx.commit();

// Export the branch to git
assert_eq!(git::export_refs(&test_data.repo, &git_repo), Ok(()));

// Modify the branch in git to point to C
git_repo
.reference("refs/heads/main", git_id(&commit_c), true, "test")
.unwrap();

// Import from git
let mut tx = test_data.repo.start_transaction("test");
git::import_refs(tx.mut_repo(), &git_repo).unwrap();
// TODO: The branch should point to C, it shouldn't be a conflict
assert_eq!(
tx.mut_repo().view().get_local_branch("main"),
Some(RefTarget::Conflict {
removes: vec![commit_a.id().clone()],
adds: vec![commit_b.id().clone(), commit_c.id().clone()],
})
);
}

#[test]
fn test_init() {
let settings = testutils::user_settings();
Expand Down

0 comments on commit 12e07b1

Please sign in to comment.