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