mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
git_ui: Fix creating worktree not possible if default branch unavailable (#57918)
Follow up to #57704 This makes sure that we offer a worktree creation option in case resolving the default branch fails Release Notes: - git: Fixed an issue where worktree creation would not be possible if resolving default branch fails
This commit is contained in:
parent
f0ed342c19
commit
d74e47ea51
1 changed files with 43 additions and 12 deletions
|
|
@ -420,8 +420,9 @@ impl WorktreePickerDelegate {
|
|||
fn build_fixed_entries(&self) -> Vec<WorktreeEntry> {
|
||||
let mut entries = Vec::new();
|
||||
|
||||
if !self.has_multiple_repositories {
|
||||
if let Some(ref default_branch) = self.default_branch {
|
||||
if self.has_multiple_repositories {
|
||||
entries.push(WorktreeEntry::CreateFromCurrentBranch);
|
||||
} else if let Some(ref default_branch) = self.default_branch {
|
||||
let is_different = self
|
||||
.current_branch_name
|
||||
.as_ref()
|
||||
|
|
@ -432,7 +433,6 @@ impl WorktreePickerDelegate {
|
|||
if is_different {
|
||||
entries.push(WorktreeEntry::CreateFromCurrentBranch);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
entries.push(WorktreeEntry::CreateFromCurrentBranch);
|
||||
}
|
||||
|
|
@ -1539,6 +1539,37 @@ mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_current_branch_create_target_is_shown_without_default_branch(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let (_fs, worktree_picker, _repository, _worktree_path, mut cx) =
|
||||
init_worktree_picker_test(cx).await;
|
||||
|
||||
worktree_picker.update_in(&mut cx, |worktree_picker, window, cx| {
|
||||
worktree_picker.picker.update(cx, |picker, cx| {
|
||||
picker.delegate.default_branch = None;
|
||||
picker.refresh(window, cx);
|
||||
});
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
worktree_picker.update(&mut cx, |worktree_picker, cx| {
|
||||
worktree_picker.picker.update(cx, |picker, _| {
|
||||
assert!(matches!(
|
||||
picker.delegate.matches.first(),
|
||||
Some(WorktreeEntry::CreateFromCurrentBranch)
|
||||
));
|
||||
assert!(
|
||||
!picker.delegate.matches.iter().any(|entry| matches!(
|
||||
entry,
|
||||
WorktreeEntry::CreateFromDefaultBranch { .. }
|
||||
))
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_delete_dirty_worktree_prompts_for_force_delete(cx: &mut TestAppContext) {
|
||||
let (fs, worktree_picker, repository, worktree_path, mut cx) =
|
||||
|
|
|
|||
Loading…
Reference in a new issue