diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 69b5b840e44..a36fbe0a617 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 04cf07633b5..b131749c5aa 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 {