Add confirmation dialog for undo commit (#1909)

This commit is contained in:
Sainath Singineedi 2023-10-17 11:29:59 +05:30 committed by GitHub
parent 2fd957e2c8
commit 0e2b3db1d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 7 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
* `theme.ron` now supports customizing line break symbol ([#1894](https://github.com/extrawurst/gitui/issues/1894)) * `theme.ron` now supports customizing line break symbol ([#1894](https://github.com/extrawurst/gitui/issues/1894))
* add confirmation for dialog for undo commit ([#1912](https://github.com/extrawurst/gitui/issues/1912))
## [0.24.3] - 2023-09-09 ## [0.24.3] - 2023-09-09

View file

@ -26,12 +26,17 @@ use crate::{
setup_popups, setup_popups,
strings::{self, ellipsis_trim_start, order}, strings::{self, ellipsis_trim_start, order},
tabs::{FilesTab, Revlog, StashList, Stashing, Status}, tabs::{FilesTab, Revlog, StashList, Stashing, Status},
try_or_popup,
ui::style::{SharedTheme, Theme}, ui::style::{SharedTheme, Theme},
AsyncAppNotification, AsyncNotification, AsyncAppNotification, AsyncNotification,
}; };
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use asyncgit::{ use asyncgit::{
sync::{self, utils::repo_work_dir, RepoPath, RepoPathRef}, sync::{
self,
utils::{repo_work_dir, undo_last_commit},
RepoPath, RepoPathRef,
},
AsyncGitNotification, PushType, AsyncGitNotification, PushType,
}; };
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
@ -1076,6 +1081,13 @@ impl App {
Action::AbortRebase => { Action::AbortRebase => {
self.status_tab.abort_rebase(); self.status_tab.abort_rebase();
} }
Action::UndoCommit => {
try_or_popup!(
self,
"undo commit failed:",
undo_last_commit(&self.repo.borrow())
);
}
}; };
flags.insert(NeedsUpdate::ALL); flags.insert(NeedsUpdate::ALL);

View file

@ -213,6 +213,10 @@ impl ConfirmComponent {
strings::confirm_title_abortrevert(), strings::confirm_title_abortrevert(),
strings::confirm_msg_revertchanges(), strings::confirm_msg_revertchanges(),
), ),
Action::UndoCommit => (
strings::confirm_title_undo_commit(),
strings::confirm_msg_undo_commit(),
),
}; };
} }

View file

@ -54,6 +54,7 @@ pub enum Action {
AbortMerge, AbortMerge,
AbortRebase, AbortRebase,
AbortRevert, AbortRevert,
UndoCommit,
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -145,6 +145,9 @@ pub fn stash_popup_msg(_key_config: &SharedKeyConfig) -> String {
pub fn confirm_title_reset() -> String { pub fn confirm_title_reset() -> String {
"Reset".to_string() "Reset".to_string()
} }
pub fn confirm_title_undo_commit() -> String {
"Undo commit".to_string()
}
pub fn confirm_title_stashdrop( pub fn confirm_title_stashdrop(
_key_config: &SharedKeyConfig, _key_config: &SharedKeyConfig,
multiple: bool, multiple: bool,
@ -203,6 +206,9 @@ pub fn confirm_msg_reset_lines(lines: usize) -> String {
"are you sure you want to discard {lines} selected lines?" "are you sure you want to discard {lines} selected lines?"
) )
} }
pub fn confirm_msg_undo_commit() -> String {
"confirm undo last commit?".to_string()
}
pub fn confirm_msg_stashdrop( pub fn confirm_msg_stashdrop(
_key_config: &SharedKeyConfig, _key_config: &SharedKeyConfig,
ids: &[CommitId], ids: &[CommitId],

View file

@ -610,11 +610,8 @@ impl Status {
} }
fn undo_last_commit(&self) { fn undo_last_commit(&self) {
try_or_popup!( self.queue
self, .push(InternalEvent::ConfirmAction(Action::UndoCommit));
"undo commit failed:",
sync::utils::undo_last_commit(&self.repo.borrow())
);
} }
fn branch_compare(&mut self) { fn branch_compare(&mut self) {