From f936d7320d70d837a6a06ad41d431259f91cfcef Mon Sep 17 00:00:00 2001
From: Sainath Singineedi <sainathsingineedi2222@gmail.com>
Date: Mon, 2 Oct 2023 00:30:22 +0530
Subject: [PATCH 1/4] Add confirmation dialog for undo commit

---
 src/app.rs              |  9 ++++++++-
 src/components/reset.rs |  4 ++++
 src/queue.rs            |  1 +
 src/strings.rs          |  6 ++++++
 src/tabs/status.rs      | 10 +++++-----
 5 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/app.rs b/src/app.rs
index cbf69159ed..3e1dbaf1a9 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -31,7 +31,11 @@ use crate::{
 };
 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 +1080,9 @@ impl App {
 			Action::AbortRebase => {
 				self.status_tab.abort_rebase();
 			}
+			Action::UndoCommit => {
+				let _ = undo_last_commit(&self.repo.borrow());
+			}
 		};
 
 		flags.insert(NeedsUpdate::ALL);
diff --git a/src/components/reset.rs b/src/components/reset.rs
index 6130419f65..a0daca3f3c 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 68531985e6..de24524f42 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 8134b5b6f6..3a4a791f61 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 837b87b140..034dfae256 100644
--- a/src/tabs/status.rs
+++ b/src/tabs/status.rs
@@ -610,11 +610,11 @@ 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) {

From 1ade7c878732fb1b2d94717b7842776fccc8d505 Mon Sep 17 00:00:00 2001
From: Sainath Singineedi <sainathsingineedi2222@gmail.com>
Date: Mon, 2 Oct 2023 19:18:48 +0530
Subject: [PATCH 2/4] Add changelog

---
 CHANGELOG.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 86dbdfe0ef..f70adb04ab 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

From 0f8bc483725a2b204ee09a82b6b0d236f743b20b Mon Sep 17 00:00:00 2001
From: Sainath Singineedi <sainathsingineedi2222@gmail.com>
Date: Tue, 3 Oct 2023 11:31:41 +0530
Subject: [PATCH 3/4] Fix lints

---
 src/queue.rs       | 2 +-
 src/strings.rs     | 4 ++--
 src/tabs/status.rs | 7 ++-----
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/queue.rs b/src/queue.rs
index de24524f42..170bc68ca3 100644
--- a/src/queue.rs
+++ b/src/queue.rs
@@ -54,7 +54,7 @@ pub enum Action {
 	AbortMerge,
 	AbortRebase,
 	AbortRevert,
-    UndoCommit,
+	UndoCommit,
 }
 
 #[derive(Debug)]
diff --git a/src/strings.rs b/src/strings.rs
index 3a4a791f61..7a73b1f97a 100644
--- a/src/strings.rs
+++ b/src/strings.rs
@@ -146,7 +146,7 @@ pub fn confirm_title_reset() -> String {
 	"Reset".to_string()
 }
 pub fn confirm_title_undo_commit() -> String {
-    "Undo commit".to_string()
+	"Undo commit".to_string()
 }
 pub fn confirm_title_stashdrop(
 	_key_config: &SharedKeyConfig,
@@ -207,7 +207,7 @@ pub fn confirm_msg_reset_lines(lines: usize) -> String {
 	)
 }
 pub fn confirm_msg_undo_commit() -> String {
-    "confirm undo last commit?".to_string()
+	"confirm undo last commit?".to_string()
 }
 pub fn confirm_msg_stashdrop(
 	_key_config: &SharedKeyConfig,
diff --git a/src/tabs/status.rs b/src/tabs/status.rs
index 034dfae256..d7e323740f 100644
--- a/src/tabs/status.rs
+++ b/src/tabs/status.rs
@@ -610,11 +610,8 @@ impl Status {
 	}
 
 	fn undo_last_commit(&self) {
-        self.queue.push(
-            InternalEvent::ConfirmAction(
-                Action::UndoCommit,
-            ),
-        );
+		self.queue
+			.push(InternalEvent::ConfirmAction(Action::UndoCommit));
 	}
 
 	fn branch_compare(&mut self) {

From 35417ec12eefcc06b4cda44bba7394b46f166494 Mon Sep 17 00:00:00 2001
From: Sainath Singineedi <sainathsingineedi2222@gmail.com>
Date: Tue, 17 Oct 2023 09:55:32 +0530
Subject: [PATCH 4/4] PR resolves v1

---
 src/app.rs              | 7 ++++++-
 src/components/reset.rs | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/app.rs b/src/app.rs
index 3e1dbaf1a9..2bdb2754ef 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -26,6 +26,7 @@ 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,
 };
@@ -1081,7 +1082,11 @@ impl App {
 				self.status_tab.abort_rebase();
 			}
 			Action::UndoCommit => {
-				let _ = undo_last_commit(&self.repo.borrow());
+				try_or_popup!(
+					self,
+					"undo commit failed:",
+					undo_last_commit(&self.repo.borrow())
+				);
 			}
 		};
 
diff --git a/src/components/reset.rs b/src/components/reset.rs
index a0daca3f3c..aa8cd1dd78 100644
--- a/src/components/reset.rs
+++ b/src/components/reset.rs
@@ -215,7 +215,7 @@ impl ConfirmComponent {
                 ),
                 Action::UndoCommit => (
                     strings::confirm_title_undo_commit(),
-                    strings:: confirm_msg_undo_commit(),
+                    strings::confirm_msg_undo_commit(),
                 ),
             };
 		}