Notify on stash drop

This commit is contained in:
Alvaro Parker 2025-08-13 14:31:24 -04:00
parent 46ed4fad44
commit e570a99cfc
No known key found for this signature in database
2 changed files with 85 additions and 31 deletions

View file

@ -7,7 +7,7 @@ use gpui::{
SharedString, Styled, Subscription, Task, Window, actions, px, rems,
};
use picker::{Picker, PickerDelegate, PickerEditorPosition};
use project::git_store::Repository;
use project::git_store::{Repository, RepositoryEvent};
use std::sync::Arc;
use ui::{HighlightedLabel, KeyBinding, ListItem, ListItemSpacing, prelude::*};
use util::ResultExt;
@ -63,7 +63,7 @@ pub struct StashList {
width: Rems,
pub picker: Entity<Picker<StashListDelegate>>,
picker_focus_handle: FocusHandle,
_subscription: Subscription,
_subscriptions: Vec<Subscription>,
}
impl StashList {
@ -74,10 +74,34 @@ impl StashList {
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let mut _subscriptions = Vec::new();
let stash_request = repository
.clone()
.map(|repository| repository.read_with(cx, |repo, _| repo.stash_entries.clone()));
if let Some(repo) = repository.clone() {
_subscriptions.push(
cx.subscribe_in(&repo, window, |this, _, event, window, cx| {
if matches!(event, RepositoryEvent::Updated { .. }) {
let stash_entries = this.picker.read_with(cx, |picker, cx| {
picker.delegate.repo.clone().map(|repo| {
repo.read(cx)
.snapshot()
.stash_entries
.entries
.to_vec()
.clone()
})
});
this.picker.update(cx, |this, cx| {
this.delegate.all_stash_entries = stash_entries;
this.refresh(window, cx);
});
}
}),
)
}
cx.spawn_in(window, async move |this, cx| {
let stash_entries = stash_request
.map(|git_stash| git_stash.entries.to_vec())
@ -101,15 +125,15 @@ impl StashList {
picker.delegate.focus_handle = picker_focus_handle.clone();
});
let _subscription = cx.subscribe(&picker, |_, _, _, cx| {
_subscriptions.push(cx.subscribe(&picker, |_, _, _, cx| {
cx.emit(DismissEvent);
});
}));
Self {
picker,
picker_focus_handle,
width,
_subscription,
_subscriptions,
}
}
@ -207,7 +231,7 @@ impl StashListDelegate {
cx.spawn(async move |_, cx| {
repo.update(cx, |repo, cx| repo.stash_drop(Some(stash_index), cx))?
.await?;
.await??;
Ok(())
})
.detach_and_prompt_err("Failed to apply stash", window, cx, |e, _, _| {

View file

@ -1805,7 +1805,7 @@ impl GitStore {
.update(&mut cx, |repository_handle, cx| {
repository_handle.stash_drop(stash_index, cx)
})?
.await?;
.await??;
Ok(proto::Ack {})
}
@ -3791,17 +3791,46 @@ impl Repository {
&mut self,
index: Option<usize>,
cx: &mut Context<Self>,
) -> Task<anyhow::Result<()>> {
) -> oneshot::Receiver<anyhow::Result<()>> {
let id = self.id;
cx.spawn(async move |this, cx| {
this.update(cx, |this, _| {
this.send_job(None, move |git_repo, _cx| async move {
let updates_tx = self
.git_store()
.and_then(|git_store| match &git_store.read(cx).state {
GitStoreState::Local { downstream, .. } => downstream
.as_ref()
.map(|downstream| downstream.updates_tx.clone()),
_ => None,
});
let this = cx.weak_entity();
self.send_job(None, move |git_repo, mut cx| async move {
match git_repo {
RepositoryState::Local {
backend,
environment,
..
} => backend.stash_drop(index, environment).await,
} => {
let result = backend.stash_drop(index, environment).await;
if result.is_ok() {
if let Ok(stash_entries) = backend.stash_entries().await {
let snapshot = this.update(&mut cx, |this, cx| {
this.snapshot.stash_entries = stash_entries;
let snapshot = this.snapshot.clone();
cx.emit(RepositoryEvent::Updated {
full_scan: false,
new_instance: false,
});
snapshot
})?;
if let Some(updates_tx) = updates_tx {
updates_tx
.unbounded_send(DownstreamUpdate::UpdateRepository(snapshot))
.ok();
}
}
}
result
}
RepositoryState::Remote { project_id, client } => {
client
.request(proto::StashDrop {
@ -3815,10 +3844,6 @@ impl Repository {
}
}
})
})?
.await??;
Ok(())
})
}
pub fn commit(
@ -4694,12 +4719,17 @@ impl Repository {
.await;
this.update(&mut cx, |this, cx| {
let needs_update = !changed_path_statuses.is_empty()
|| this.snapshot.stash_entries != stash_entries;
this.snapshot.stash_entries = stash_entries;
if !changed_path_statuses.is_empty() {
this.snapshot
.statuses_by_path
.edit(changed_path_statuses, &());
this.snapshot.scan_id += 1;
}
if needs_update {
if let Some(updates_tx) = updates_tx {
updates_tx
.unbounded_send(DownstreamUpdate::UpdateRepository(