Skip to content

Commit

Permalink
view: remove git heads from view when forgetting workspace (but not w…
Browse files Browse the repository at this point in the history
…hen merging view, yet)
  • Loading branch information
cormacrelf committed Oct 5, 2024
1 parent 295c1eb commit aaebbbb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cli/src/commands/workspace/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<WorkspaceId, WorkspaceView> 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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aaebbbb

Please sign in to comment.