Skip to content

Commit

Permalink
test_import_refs_reimport.rs: Demonstrate #864's root cause
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed May 13, 2023
1 parent 58e9bf8 commit 5922bed
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ fn test_import_refs_reimport() {
let commit2 = empty_git_commit(&git_repo, "refs/heads/main", &[&commit1]);
let commit3 = empty_git_commit(&git_repo, "refs/heads/feature1", &[&commit2]);
let commit4 = empty_git_commit(&git_repo, "refs/heads/feature2", &[&commit2]);
// let commit5 = ... will be introduced in the next commit
let commit5 = empty_git_commit(&git_repo, "refs/heads/feature-remote", &[&commit2]);
git_ref(
&git_repo,
"refs/remotes/origin/feature-remote",
commit5.id(),
);
let pgp_key_oid = git_repo.blob(b"my PGP key").unwrap();
git_repo
.reference("refs/tags/my-gpg-key", pgp_key_oid, false, "")
Expand All @@ -191,12 +196,19 @@ fn test_import_refs_reimport() {
let expected_heads = hashset! {
jj_id(&commit3),
jj_id(&commit4),
jj_id(&commit5),
};
let view = repo.view();
assert_eq!(*view.heads(), expected_heads);
assert!(matches!(view.branches().get("feature-remote"), Some(_)));

// Delete feature1 and rewrite feature2
// Delete feature1 locally
delete_git_ref(&git_repo, "refs/heads/feature1");
// Simulate fetching from a remote where feature-remote branch was deleted to
// test #864. This leads to the following import deleting the corresponding
// local branch.
delete_git_ref(&git_repo, "refs/remotes/origin/feature-remote");
// Rewrite feature2
delete_git_ref(&git_repo, "refs/heads/feature2");
let commit6 = empty_git_commit(&git_repo, "refs/heads/feature2", &[&commit2]);

Expand All @@ -219,6 +231,9 @@ fn test_import_refs_reimport() {

let view = repo.view();
let expected_heads = hashset! {
// BUG: commit5 is still listed as a head (#864) even though the
// feature-remote branch was deleted as we'll see below.
jj_id(&commit5),
jj_id(&commit6),
commit7.id().clone(),
};
Expand Down Expand Up @@ -248,10 +263,11 @@ fn test_import_refs_reimport() {
view.branches().get("feature2"),
Some(expected_feature2_branch).as_ref()
);
assert_eq!(view.branches().get("feature-remote"), None);

assert!(view.tags().is_empty());

assert_eq!(view.git_refs().len(), 3);
assert_eq!(view.git_refs().len(), 4);
assert_eq!(
view.git_refs().get("refs/heads/main"),
Some(commit2_target).as_ref()
Expand All @@ -265,6 +281,13 @@ fn test_import_refs_reimport() {
view.git_refs().get("refs/heads/feature2"),
Some(commit6_target).as_ref()
);
let commit5_target = RefTarget::Normal(jj_id(&commit5));
assert_eq!(
// The git repo ref for the local feature-remote branch continues to exist until
// the next `jj git export`
view.git_refs().get("refs/heads/feature-remote"),
Some(commit5_target).as_ref()
);
}

#[test]
Expand Down

0 comments on commit 5922bed

Please sign in to comment.