From 5922bed86c8d6f3bf6f81af75032639b72ebf141 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Mon, 8 May 2023 12:54:37 -0700 Subject: [PATCH] test_import_refs_reimport.rs: Demonstrate #864's root cause --- lib/tests/test_git.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index 37fa700f72..a57f7c590c 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -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, "") @@ -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]); @@ -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(), }; @@ -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() @@ -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]