1use ::settings::Settings;
2use git::status::FileStatus;
3use git_panel_settings::GitPanelSettings;
4use gpui::App;
5use project_diff::ProjectDiff;
6use ui::{ActiveTheme, Color, Icon, IconName, IntoElement};
7use workspace::Workspace;
8
9mod askpass_modal;
10pub mod branch_picker;
11mod commit_modal;
12pub mod git_panel;
13mod git_panel_settings;
14pub mod picker_prompt;
15pub mod project_diff;
16mod remote_output_toast;
17pub mod repository_selector;
18
19pub fn init(cx: &mut App) {
20 GitPanelSettings::register(cx);
21 branch_picker::init(cx);
22 cx.observe_new(ProjectDiff::register).detach();
23 commit_modal::init(cx);
24 git_panel::init(cx);
25
26 cx.observe_new(|workspace: &mut Workspace, _, cx| {
27 let project = workspace.project().read(cx);
28 if project.is_via_collab() {
29 return;
30 }
31 workspace.register_action(|workspace, _: &git::Fetch, window, cx| {
32 let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
33 return;
34 };
35 panel.update(cx, |panel, cx| {
36 panel.fetch(window, cx);
37 });
38 });
39 workspace.register_action(|workspace, _: &git::Push, window, cx| {
40 let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
41 return;
42 };
43 panel.update(cx, |panel, cx| {
44 panel.push(false, window, cx);
45 });
46 });
47 workspace.register_action(|workspace, _: &git::ForcePush, window, cx| {
48 let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
49 return;
50 };
51 panel.update(cx, |panel, cx| {
52 panel.push(true, window, cx);
53 });
54 });
55 workspace.register_action(|workspace, _: &git::Pull, window, cx| {
56 let Some(panel) = workspace.panel::<git_panel::GitPanel>(cx) else {
57 return;
58 };
59 panel.update(cx, |panel, cx| {
60 panel.pull(window, cx);
61 });
62 });
63 })
64 .detach();
65}
66
67// TODO: Add updated status colors to theme
68pub fn git_status_icon(status: FileStatus, cx: &App) -> impl IntoElement {
69 let (icon_name, color) = if status.is_conflicted() {
70 (
71 IconName::Warning,
72 cx.theme().colors().version_control_conflict,
73 )
74 } else if status.is_deleted() {
75 (
76 IconName::SquareMinus,
77 cx.theme().colors().version_control_deleted,
78 )
79 } else if status.is_modified() {
80 (
81 IconName::SquareDot,
82 cx.theme().colors().version_control_modified,
83 )
84 } else {
85 (
86 IconName::SquarePlus,
87 cx.theme().colors().version_control_added,
88 )
89 };
90 Icon::new(icon_name).color(Color::Custom(color))
91}