diff --git a/src/commands/operation.rs b/src/commands/operation.rs index 7ae83a078a..254cf8491e 100644 --- a/src/commands/operation.rs +++ b/src/commands/operation.rs @@ -167,6 +167,12 @@ fn view_with_desired_portions_restored( current_view.git_refs.clone() }; + if what.contains(&UndoWhatToRestore::RemoteTracking) == what.contains(&UndoWhatToRestore::Repo) + { + // new_view already contains the correct branches; we can short-curcuit + return new_view; + } + let mut all_branch_names: BTreeSet<_> = view_being_restored.branches.keys().collect(); all_branch_names.append(&mut current_view.branches.keys().collect()); @@ -175,8 +181,6 @@ fn view_with_desired_portions_restored( } else { current_view }; - // Short-term TODO: we will optimize this to avoid recreating branches if they - // are already correct in `new_view` let mut new_branches = BTreeMap::default(); for branch_name in all_branch_names { let local_target = new_view