diff --git a/cli/src/commands/workspace/forget.rs b/cli/src/commands/workspace/forget.rs index dffec246a4..8b5f416bd8 100644 --- a/cli/src/commands/workspace/forget.rs +++ b/cli/src/commands/workspace/forget.rs @@ -89,8 +89,11 @@ pub fn cmd_workspace_forget( // bundle every workspace forget into a single transaction, so that e.g. // undo correctly restores all of them at once. let mut tx = workspace_command.start_transaction(); - wss.iter() - .try_for_each(|ws| tx.repo_mut().remove_wc_commit(ws))?; + wss.iter().try_for_each(|ws| { + tx.repo_mut().remove_git_head_target(ws); + tx.repo_mut().remove_wc_commit(ws) + })?; + let description = if let [ws] = wss.as_slice() { format!("forget workspace {}", ws.as_str()) } else { diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 37f72da542..943e0a0b19 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1346,6 +1346,10 @@ impl MutableRepo { Ok(()) } + pub fn remove_git_head_target(&mut self, workspace_id: &WorkspaceId) { + self.view_mut().remove_git_head_target(workspace_id); + } + pub fn remove_wc_commit(&mut self, workspace_id: &WorkspaceId) -> Result<(), EditCommitError> { self.maybe_abandon_wc_commit(workspace_id)?; self.view_mut().remove_wc_commit(workspace_id); @@ -1656,6 +1660,9 @@ impl MutableRepo { } else { // The other side removed the workspace. We want to remove it even if the self // side changed the working-copy commit. + // TODO: remove the git_heads entry as well. May want to migrate to a + // HashMap in the View, and simply remove a workspace + // all at once. However this proved more tricky than expected. self.view_mut().remove_wc_commit(workspace_id); } } diff --git a/lib/src/view.rs b/lib/src/view.rs index f9e9a98abc..50e18bd0e2 100644 --- a/lib/src/view.rs +++ b/lib/src/view.rs @@ -324,6 +324,10 @@ impl View { self.data.git_heads = git_heads; } + pub(crate) fn remove_git_head_target(&mut self, workspace_id: &WorkspaceId) { + self.data.git_heads.remove(workspace_id); + } + /// Iterates all commit ids referenced by this view. /// /// This can include hidden commits referenced by remote branches, previous