git: No-op when trying to commit with nothing staged or no commit message (#23491)

The buttons are disabled in this case, but users can still trigger a
commit via the actions directly, and an error toast seems a bit loud for
this.

cc @iamnbutler 

Release Notes:

- N/A
This commit is contained in:
Cole Miller 2025-01-22 18:04:14 -05:00 committed by GitHub
parent db65ee0add
commit 78a8c1a68a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 46 deletions

View file

@ -314,32 +314,28 @@ impl RepositoryHandle {
&& (commit_all || self.have_staged_changes());
}
pub fn commit(
&self,
err_sender: mpsc::Sender<anyhow::Error>,
cx: &mut AppContext,
) -> anyhow::Result<()> {
if !self.can_commit(false, cx) {
return Err(anyhow!("Unable to commit"));
}
pub fn commit(&self, mut err_sender: mpsc::Sender<anyhow::Error>, cx: &mut AppContext) {
let message = self.commit_message.read(cx).as_rope().clone();
self.update_sender
.unbounded_send((Message::Commit(self.git_repo.clone(), message), err_sender))
.map_err(|_| anyhow!("Failed to submit commit operation"))?;
let result = self.update_sender.unbounded_send((
Message::Commit(self.git_repo.clone(), message),
err_sender.clone(),
));
if result.is_err() {
cx.spawn(|_| async move {
err_sender
.send(anyhow!("Failed to submit commit operation"))
.await
.ok();
})
.detach();
return;
}
self.commit_message.update(cx, |commit_message, cx| {
commit_message.set_text("", cx);
});
Ok(())
}
pub fn commit_all(
&self,
err_sender: mpsc::Sender<anyhow::Error>,
cx: &mut AppContext,
) -> anyhow::Result<()> {
if !self.can_commit(true, cx) {
return Err(anyhow!("Unable to commit"));
}
pub fn commit_all(&self, mut err_sender: mpsc::Sender<anyhow::Error>, cx: &mut AppContext) {
let to_stage = self
.repository_entry
.status()
@ -347,15 +343,22 @@ impl RepositoryHandle {
.map(|entry| entry.repo_path.clone())
.collect::<Vec<_>>();
let message = self.commit_message.read(cx).as_rope().clone();
self.update_sender
.unbounded_send((
Message::StageAndCommit(self.git_repo.clone(), message, to_stage),
err_sender,
))
.map_err(|_| anyhow!("Failed to submit commit operation"))?;
let result = self.update_sender.unbounded_send((
Message::StageAndCommit(self.git_repo.clone(), message, to_stage),
err_sender.clone(),
));
if result.is_err() {
cx.spawn(|_| async move {
err_sender
.send(anyhow!("Failed to submit commit all operation"))
.await
.ok();
})
.detach();
return;
}
self.commit_message.update(cx, |commit_message, cx| {
commit_message.set_text("", cx);
});
Ok(())
}
}