From 7634056f9ae413dabe1bd5eaf54d2fbe12524edf Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 16:49:38 -0400 Subject: [PATCH] Don't render "Initialize Repository" button when no worktrees (cherry-pick #26713) (#26727) Cherry-picked Don't render "Initialize Repository" button when no worktrees (#26713) Closes #26676 Release Notes: - Fixed the git panel to not show an "Initialize Repositories" button in empty projects Co-authored-by: Cole Miller --- crates/git_ui/src/git_panel.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index f42b085480c404ed057bb863329e1a20f5e37692..6a72409f12ea881bab48aef5bb78bac8d76a7355 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -3048,21 +3048,24 @@ impl GitPanel { "No Git repositories" }, )) - .children(self.active_repository.is_none().then(|| { - h_flex().w_full().justify_around().child( - panel_filled_button("Initialize Repository") - .tooltip(Tooltip::for_action_title_in( - "git init", - &git::Init, - &self.focus_handle, - )) - .on_click(move |_, _, cx| { - cx.defer(move |cx| { - cx.dispatch_action(&git::Init); - }) - }), - ) - })) + .children({ + let worktree_count = self.project.read(cx).visible_worktrees(cx).count(); + (worktree_count > 0 && self.active_repository.is_none()).then(|| { + h_flex().w_full().justify_around().child( + panel_filled_button("Initialize Repository") + .tooltip(Tooltip::for_action_title_in( + "git init", + &git::Init, + &self.focus_handle, + )) + .on_click(move |_, _, cx| { + cx.defer(move |cx| { + cx.dispatch_action(&git::Init); + }) + }), + ) + }) + }) .text_ui_sm(cx) .mx_auto() .text_color(Color::Placeholder.color(cx)),