Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git_ui: Show more information in the branch picker #25359

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c4c3659
Show info
Angelk90 Feb 21, 2025
6fb3ae1
Remove white space
Angelk90 Feb 21, 2025
f85c692
Fix format code
Angelk90 Feb 21, 2025
5de724c
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 21, 2025
80298ee
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 22, 2025
2cf2fcd
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 22, 2025
106c796
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 22, 2025
f53dae2
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 24, 2025
949e936
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 24, 2025
85c7075
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 24, 2025
71beb90
Revise the design (and show just SHA number and time)
danilo-leal Feb 25, 2025
3502294
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 25, 2025
27d3980
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 25, 2025
6be0dab
Fix
Angelk90 Feb 25, 2025
f5df1fa
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 25, 2025
97f810b
Add commit message and tidy the UI
danilo-leal Feb 26, 2025
a6f7dfa
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 26, 2025
4835e8e
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 26, 2025
00a5e97
Don't duplicate short SHA length
maxdeviant Feb 26, 2025
212ebef
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 26, 2025
2d92f83
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 26, 2025
0a3d794
Merge branch 'main' into show-branch-info
Angelk90 Feb 28, 2025
37a7f68
Fix
Angelk90 Feb 28, 2025
b48affc
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Feb 28, 2025
4d43797
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Mar 4, 2025
18f6546
Merge branch 'main' into show-branch-info
Angelk90 Mar 5, 2025
656d263
Merge branch 'main' into show-branch-info
Angelk90 Mar 6, 2025
b85d0af
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Mar 7, 2025
bf7f540
Fix
Angelk90 Mar 7, 2025
2fc0cdc
Fix format code
Angelk90 Mar 7, 2025
637bef9
Merge branch 'zed-industries:main' into show-branch-info
Angelk90 Mar 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion crates/git/src/repository.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::status::FileStatus;
use crate::GitHostingProviderRegistry;
use crate::{blame::Blame, status::GitStatus};
use crate::{GitHostingProviderRegistry, SHORT_SHA_LENGTH};
use anyhow::{anyhow, Context, Result};
use askpass::{AskPassResult, AskPassSession};
use collections::{HashMap, HashSet};
Expand Down Expand Up @@ -120,6 +120,12 @@ pub struct CommitDetails {
pub committer_name: SharedString,
}

impl CommitDetails {
pub fn short_sha(&self) -> SharedString {
self.sha[..SHORT_SHA_LENGTH].to_string().into()
}
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Remote {
pub name: SharedString,
Expand Down
1 change: 1 addition & 0 deletions crates/git_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ strum.workspace = true
telemetry.workspace = true
theme.workspace = true
time.workspace = true
time_format.workspace = true
ui.workspace = true
util.workspace = true
workspace.workspace = true
Expand Down
126 changes: 114 additions & 12 deletions crates/git_ui/src/branch_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use gpui::{
Task, Window,
};
use picker::{Picker, PickerDelegate};
use project::git::Repository;
use project::git::{GitRepo, Repository};
use std::sync::Arc;
use time::OffsetDateTime;
use time_format::format_local_timestamp;
use ui::{prelude::*, HighlightedLabel, ListItem, ListItemSpacing, PopoverMenuHandle};
use util::ResultExt;
use workspace::notifications::DetachAndPromptErr;
Expand Down Expand Up @@ -366,17 +368,50 @@ impl PickerDelegate for BranchListDelegate {
cx.emit(DismissEvent);
}

fn render_header(&self, _: &mut Window, _cx: &mut Context<Picker<Self>>) -> Option<AnyElement> {
if self.last_query.is_empty() && !self.matches.is_empty() {
Some(
Label::new("Recent Branches")
.size(LabelSize::Small)
.color(Color::Muted)
.mt_1()
.mb_0p5()
.ml_2()
.into_any_element(),
)
} else {
None
}
}

fn render_match(
&self,
ix: usize,
selected: bool,
_window: &mut Window,
_cx: &mut Context<Picker<Self>>,
cx: &mut Context<Picker<Self>>,
) -> Option<Self::ListItem> {
let hit = &self.matches[ix];
let shortened_branch_name =
util::truncate_and_trailoff(&hit.name(), self.branch_name_trailoff_after);

let repo = self.repo.clone();

let branch_name = match hit {
BranchEntry::Branch(branch) => Some(branch.string.as_str()),
BranchEntry::History(branch) => Some(branch.as_str()),
BranchEntry::NewBranch { name } => Some(name.as_str()),
};

let commit_info = repo.as_ref().and_then(|repo_entity| {
let repo = repo_entity.read(cx);
let git_repo = match &repo.git_repo {
GitRepo::Local(git_repo) => git_repo.as_ref(),
_ => return None,
};
branch_name.and_then(|name| git_repo.show(name).ok())
});

Some(
ListItem::new(SharedString::from(format!("vcs-menu-{ix}")))
.inset(true)
Expand All @@ -386,13 +421,6 @@ impl PickerDelegate for BranchListDelegate {
})
.spacing(ListItemSpacing::Sparse)
.toggle_state(selected)
.when(matches!(hit, BranchEntry::History(_)), |el| {
el.end_slot(
Icon::new(IconName::HistoryRerun)
.color(Color::Muted)
.size(IconSize::Small),
)
})
.map(|el| match hit {
BranchEntry::Branch(branch) => {
let highlights: Vec<_> = branch
Expand All @@ -404,10 +432,84 @@ impl PickerDelegate for BranchListDelegate {

el.child(HighlightedLabel::new(shortened_branch_name, highlights))
}
BranchEntry::History(_) => el.child(Label::new(shortened_branch_name)),
BranchEntry::NewBranch { name } => {
el.child(Label::new(format!("Create branch '{name}'")))
BranchEntry::History(_) => {
let (commit_sha, commit_time, commit_message) = commit_info
.as_ref()
.map(|commit| {
let commit_message = commit.message.clone();
let commit_time =
OffsetDateTime::from_unix_timestamp(commit.commit_timestamp)
.unwrap_or_else(|_| OffsetDateTime::now_utc());
let formatted_time = format_local_timestamp(
commit_time,
OffsetDateTime::now_utc(),
time_format::TimestampFormat::Relative,
);
(commit.short_sha(), formatted_time, commit_message)
})
.unwrap_or_else(|| {
(
"No Commit SHA".into(),
"Unknown Date".to_string(),
SharedString::from("No commit message available"),
)
});
el.child(
v_flex()
.w_full()
.child(
h_flex()
.w_full()
.gap_2()
.justify_between()
.child(
div().max_w_80().child(
Label::new(shortened_branch_name).truncate(),
),
)
.child(
h_flex()
.gap_2()
.child(
Label::new(commit_sha)
.size(LabelSize::Small)
.color(Color::Muted)
.into_element(),
)
.child(div().size_1().rounded_full().bg(
cx.theme().colors().text_muted.opacity(0.6),
))
.child(
Label::new(commit_time)
.size(LabelSize::Small)
.color(Color::Muted)
.into_element(),
),
),
)
.child(
div().max_w_96().child(
Label::new(
commit_message
.split('\n')
.next()
.unwrap_or_default()
.to_string(),
)
.size(LabelSize::Small)
.truncate()
.color(Color::Muted),
),
),
)
}

BranchEntry::NewBranch { name } => el.child(
h_flex()
.gap_1()
.child(Label::new("Create Branch:"))
.child(Label::new(name.to_string()).buffer_font(cx)),
),
}),
)
}
Expand Down
Loading