add per-commit publishing from sync status
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Error;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
@@ -7,12 +7,16 @@ use gpui::{
|
||||
Styled as _, Task, UniformListScrollHandle, WeakEntity, Window, div, uniform_list,
|
||||
};
|
||||
use signed_git::{CommitList, Repo};
|
||||
use signed_state::RepoStore;
|
||||
use ui::common::v_flex;
|
||||
use signed_state::{Backend, RepoStore, SyncStatusDirectory};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::{Sizable as _, v_flex};
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::spinner::Spinner;
|
||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
use ui::tooltip::Tooltip;
|
||||
|
||||
use super::RepoDetailView;
|
||||
use super::commit_diff::CommitDiffView;
|
||||
use super::helpers::commit_row;
|
||||
use crate::shared::panels;
|
||||
@@ -21,6 +25,8 @@ use crate::workspace::Workspace;
|
||||
pub struct RepoHistoryView {
|
||||
store: Entity<RepoStore>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
detail: WeakEntity<RepoDetailView>,
|
||||
sync_directory: Entity<SyncStatusDirectory>,
|
||||
worktree: Option<PathBuf>,
|
||||
all_commits: Option<CommitList>,
|
||||
loading_all_commits: bool,
|
||||
@@ -29,10 +35,17 @@ pub struct RepoHistoryView {
|
||||
}
|
||||
|
||||
impl RepoHistoryView {
|
||||
pub fn new(store: Entity<RepoStore>, workspace: WeakEntity<Workspace>) -> Self {
|
||||
pub fn new(
|
||||
store: Entity<RepoStore>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
detail: WeakEntity<RepoDetailView>,
|
||||
sync_directory: Entity<SyncStatusDirectory>,
|
||||
) -> Self {
|
||||
Self {
|
||||
store,
|
||||
workspace,
|
||||
detail,
|
||||
sync_directory,
|
||||
worktree: None,
|
||||
all_commits: None,
|
||||
loading_all_commits: false,
|
||||
@@ -45,6 +58,10 @@ impl RepoHistoryView {
|
||||
self.worktree = path;
|
||||
}
|
||||
|
||||
pub fn worktree(&self) -> Option<&Path> {
|
||||
self.worktree.as_deref()
|
||||
}
|
||||
|
||||
/// Number of commits reachable from HEAD, for the Commits tab label.
|
||||
pub fn commit_count(&self) -> Option<usize> {
|
||||
self.all_commits.as_ref().map(|list| list.total)
|
||||
@@ -142,6 +159,26 @@ impl Render for RepoHistoryView {
|
||||
let shown = commits.len();
|
||||
let total = list.total;
|
||||
let view = cx.entity().downgrade();
|
||||
let detail = self.detail.clone();
|
||||
|
||||
let user = Backend::global(cx).read(cx).current_user();
|
||||
let author = user.is_some_and(|user| self.store.read(cx).is_author(&user));
|
||||
let checkout = self.worktree.clone();
|
||||
|
||||
let ahead = self
|
||||
.store
|
||||
.read(cx)
|
||||
.addr()
|
||||
.cloned()
|
||||
.filter(|_| author)
|
||||
.map(|addr| {
|
||||
self.sync_directory.read_with(cx, |directory, cx| {
|
||||
directory.ahead_commits_of(&addr, checkout.as_deref(), cx)
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let pushing = self.store.read(cx).pushing;
|
||||
|
||||
v_flex()
|
||||
.relative()
|
||||
@@ -156,9 +193,42 @@ impl Render for RepoHistoryView {
|
||||
let id = commit.id.clone();
|
||||
let view = view.clone();
|
||||
|
||||
let action = ahead
|
||||
.iter()
|
||||
.find(|(id, _)| id.starts_with(commit.id.as_str()))
|
||||
.map(|(ahead, path)| {
|
||||
let detail = detail.clone();
|
||||
let path = path.clone();
|
||||
let target = ahead.clone();
|
||||
let short = commit.id.clone();
|
||||
|
||||
Button::new(("sync-commit", ix))
|
||||
.label("Sync")
|
||||
.icon(Icon::named(IconRole::ArrowUp))
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.small()
|
||||
.disabled(pushing)
|
||||
.tooltip(Tooltip::text(format!("Sync up to {short}")))
|
||||
.on_click(move |_, window, cx| {
|
||||
cx.stop_propagation();
|
||||
if let Some(detail) = detail.upgrade() {
|
||||
detail.update(cx, |this, cx| {
|
||||
this.sync_checkout_commit(
|
||||
path.clone(),
|
||||
target.clone(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
}
|
||||
})
|
||||
.into_any_element()
|
||||
});
|
||||
|
||||
commit_row(
|
||||
ix,
|
||||
&commit,
|
||||
action,
|
||||
move |window, cx| {
|
||||
if let Err(error) = view.update(cx, |this, cx| {
|
||||
this.open_commit_diff(&id, window, cx);
|
||||
|
||||
Reference in New Issue
Block a user