From 0e2b3db1d936fe3371473c5ce64e28f0e454ae9b Mon Sep 17 00:00:00 2001 From: Sainath Singineedi <44405294+sainad2222@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:29:59 +0530 Subject: [PATCH] Add confirmation dialog for undo commit (#1909) --- CHANGELOG.md | 3 ++- src/app.rs | 14 +++++++++++++- src/components/reset.rs | 4 ++++ src/queue.rs | 1 + src/strings.rs | 6 ++++++ src/tabs/status.rs | 7 ++----- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86dbdfe0..f70adb04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * `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 ### Fixes diff --git a/src/app.rs b/src/app.rs index cbf69159..2bdb2754 100644 --- a/src/app.rs +++ b/src/app.rs @@ -26,12 +26,17 @@ use crate::{ setup_popups, strings::{self, ellipsis_trim_start, order}, tabs::{FilesTab, Revlog, StashList, Stashing, Status}, + try_or_popup, ui::style::{SharedTheme, Theme}, AsyncAppNotification, AsyncNotification, }; use anyhow::{bail, Result}; use asyncgit::{ - sync::{self, utils::repo_work_dir, RepoPath, RepoPathRef}, + sync::{ + self, + utils::{repo_work_dir, undo_last_commit}, + RepoPath, RepoPathRef, + }, AsyncGitNotification, PushType, }; use crossbeam_channel::Sender; @@ -1076,6 +1081,13 @@ impl App { Action::AbortRebase => { self.status_tab.abort_rebase(); } + Action::UndoCommit => { + try_or_popup!( + self, + "undo commit failed:", + undo_last_commit(&self.repo.borrow()) + ); + } }; flags.insert(NeedsUpdate::ALL); diff --git a/src/components/reset.rs b/src/components/reset.rs index 6130419f..aa8cd1dd 100644 --- a/src/components/reset.rs +++ b/src/components/reset.rs @@ -213,6 +213,10 @@ impl ConfirmComponent { strings::confirm_title_abortrevert(), strings::confirm_msg_revertchanges(), ), + Action::UndoCommit => ( + strings::confirm_title_undo_commit(), + strings::confirm_msg_undo_commit(), + ), }; } diff --git a/src/queue.rs b/src/queue.rs index 68531985..170bc68c 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -54,6 +54,7 @@ pub enum Action { AbortMerge, AbortRebase, AbortRevert, + UndoCommit, } #[derive(Debug)] diff --git a/src/strings.rs b/src/strings.rs index 8134b5b6..7a73b1f9 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -145,6 +145,9 @@ pub fn stash_popup_msg(_key_config: &SharedKeyConfig) -> String { pub fn confirm_title_reset() -> String { "Reset".to_string() } +pub fn confirm_title_undo_commit() -> String { + "Undo commit".to_string() +} pub fn confirm_title_stashdrop( _key_config: &SharedKeyConfig, 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?" ) } +pub fn confirm_msg_undo_commit() -> String { + "confirm undo last commit?".to_string() +} pub fn confirm_msg_stashdrop( _key_config: &SharedKeyConfig, ids: &[CommitId], diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 837b87b1..d7e32374 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -610,11 +610,8 @@ impl Status { } fn undo_last_commit(&self) { - try_or_popup!( - self, - "undo commit failed:", - sync::utils::undo_last_commit(&self.repo.borrow()) - ); + self.queue + .push(InternalEvent::ConfirmAction(Action::UndoCommit)); } fn branch_compare(&mut self) {