From fafa9b70fccf03c00ac3b7c8513398fd634c14eb Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 17 Dec 2022 12:14:53 -0800 Subject: [PATCH] view: also merge `git_heads` when merging views I don't know if I had just forgotten to merge `git_heads` when I added it to the view object, but it seems like it should be merged just like refs. --- lib/src/repo.rs | 12 ++++++++++++ lib/tests/test_view.rs | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 69b5b840e..a36fbe0a6 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -39,6 +39,7 @@ use crate::op_store::{ BranchTarget, OpStore, OperationId, OperationMetadata, RefTarget, WorkspaceId, }; use crate::operation::Operation; +use crate::refs::merge_ref_targets; use crate::rewrite::DescendantRebaser; use crate::settings::{RepoSettings, UserSettings}; use crate::simple_op_heads_store::SimpleOpHeadsStore; @@ -1108,6 +1109,17 @@ impl MutableRepo { other_target.as_ref(), ); } + + if let Some(new_git_head) = merge_ref_targets( + self.index.as_index_ref(), + self.view().git_head(), + base.git_head(), + other.git_head(), + ) { + self.set_git_head(new_git_head); + } else { + self.clear_git_head(); + } } /// Finds and records commits that were rewritten or abandoned between diff --git a/lib/tests/test_view.rs b/lib/tests/test_view.rs index 04cf07633..b131749c5 100644 --- a/lib/tests/test_view.rs +++ b/lib/tests/test_view.rs @@ -462,8 +462,7 @@ fn test_merge_views_git_heads() { removes: vec![tx0_head.id().clone()], adds: vec![tx1_head.id().clone(), tx2_head.id().clone()], }; - // TODO: Should be equal - assert_ne!(repo.view().git_head(), Some(&expected_git_head)); + assert_eq!(repo.view().git_head(), Some(&expected_git_head)); } fn commit_transactions(settings: &UserSettings, txs: Vec) -> Arc {