From 3fe3cfc3bffca50711f56b7201a37abb670ae4d5 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Sun, 7 Apr 2024 17:19:13 +0200 Subject: [PATCH 1/4] allow triggering branch reset from branch popup --- src/app.rs | 2 +- src/keys/key_list.rs | 2 ++ src/popups/branchlist.rs | 17 +++++++++++++++++ src/strings.rs | 12 ++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index f2b4a4a9bb..e35da87051 100644 --- a/src/app.rs +++ b/src/app.rs @@ -482,13 +482,13 @@ impl App { pull_popup, fetch_popup, tag_commit_popup, + reset_popup, create_branch_popup, rename_branch_popup, select_branch_popup, revision_files_popup, submodule_popup, tags_popup, - reset_popup, options_popup, help_popup, revlog, diff --git a/src/keys/key_list.rs b/src/keys/key_list.rs index 71e6756db4..a542ef938a 100644 --- a/src/keys/key_list.rs +++ b/src/keys/key_list.rs @@ -99,6 +99,7 @@ pub struct KeysList { pub delete_branch: GituiKeyEvent, pub merge_branch: GituiKeyEvent, pub rebase_branch: GituiKeyEvent, + pub reset_branch: GituiKeyEvent, pub compare_commits: GituiKeyEvent, pub tags: GituiKeyEvent, pub delete_tag: GituiKeyEvent, @@ -190,6 +191,7 @@ impl Default for KeysList { delete_branch: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT), merge_branch: GituiKeyEvent::new(KeyCode::Char('m'), KeyModifiers::empty()), rebase_branch: GituiKeyEvent::new(KeyCode::Char('R'), KeyModifiers::SHIFT), + reset_branch: GituiKeyEvent::new(KeyCode::Char('s'), KeyModifiers::empty()), compare_commits: GituiKeyEvent::new(KeyCode::Char('C'), KeyModifiers::SHIFT), tags: GituiKeyEvent::new(KeyCode::Char('T'), KeyModifiers::SHIFT), delete_tag: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT), diff --git a/src/popups/branchlist.rs b/src/popups/branchlist.rs index f7c9b94dd5..658e742181 100644 --- a/src/popups/branchlist.rs +++ b/src/popups/branchlist.rs @@ -211,6 +211,12 @@ impl Component for BranchListPopup { true, true, )); + + out.push(CommandInfo::new( + strings::commands::reset_branch(&self.key_config), + self.valid_selection(), + true, + )); } visibility_blocking(self) } @@ -288,6 +294,13 @@ impl Component for BranchListPopup { && self.has_remotes { self.queue.push(InternalEvent::FetchRemotes); + } else if key_match(e, self.key_config.keys.reset_branch) + { + if let Some(b) = self.get_selected_branch() { + self.queue.push(InternalEvent::OpenResetPopup( + b.top_commit, + )); + } } else if key_match( e, self.key_config.keys.cmd_bar_toggle, @@ -515,6 +528,10 @@ impl BranchListPopup { .map(|b| b.top_commit) } + fn get_selected_branch(&self) -> Option<&BranchInfo> { + self.branches.get(usize::from(self.selection)) + } + /// fn move_selection(&mut self, scroll: ScrollType) -> Result { let new_selection = match scroll { diff --git a/src/strings.rs b/src/strings.rs index 67eb79ba7a..b9a761111b 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -1410,6 +1410,18 @@ pub mod commands { CMD_GROUP_LOG, ) } + + pub fn reset_branch(key_config: &SharedKeyConfig) -> CommandText { + CommandText::new( + format!( + "Reset [{}]", + key_config.get_hint(key_config.keys.reset_branch), + ), + "confirm reset", + CMD_GROUP_BRANCHES, + ) + } + pub fn reset_type(key_config: &SharedKeyConfig) -> CommandText { CommandText::new( format!( From c73f2f2e578d286fb5d117f57ee36943c3530572 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Sun, 7 Apr 2024 17:21:35 +0200 Subject: [PATCH 2/4] changelog entry --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d439524a1..bf1de5be09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Added -* provide nightly builds (see [NIGHTLIES.md](./NIGHTLIES.md)) ([#2083](https://github.com/extrawurst/gitui/issues/2083)) * sign commits using openpgp [[@hendrikmaus](https://github.com/hendrikmaus)] ([#97](https://github.com/extrawurst/gitui/issues/97)) -* support `core.commitChar` filtering [[@concelare](https://github.com/concelare)] ([#2136](https://github.com/extrawurst/gitui/issues/2136)) +* provide nightly builds (see [NIGHTLIES.md](./NIGHTLIES.md)) ([#2083](https://github.com/extrawurst/gitui/issues/2083)) * more version info in `gitui -V` and `help popup` (including git hash) +* support `core.commitChar` filtering [[@concelare](https://github.com/concelare)] ([#2136](https://github.com/extrawurst/gitui/issues/2136)) +* allow reset in branch popup ([#2170](https://github.com/extrawurst/gitui/issues/2170)) ### Changed * Make info and error message popups scrollable [[@MichaelAug](https://github.com/MichaelAug)] ([#1138](https://github.com/extrawurst/gitui/issues/1138)) From 51f32eb596ca8add6656ad794e77e3bedd721b3c Mon Sep 17 00:00:00 2001 From: extrawurst Date: Sun, 7 Apr 2024 17:23:19 +0200 Subject: [PATCH 3/4] cleanup --- src/popups/branchlist.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/popups/branchlist.rs b/src/popups/branchlist.rs index 658e742181..599b3bea23 100644 --- a/src/popups/branchlist.rs +++ b/src/popups/branchlist.rs @@ -283,7 +283,7 @@ impl Component for BranchListPopup { ) && self.valid_selection() { self.hide(); - if let Some(commit_id) = self.get_selected() { + if let Some(commit_id) = self.get_selected_commit() { self.queue.push(InternalEvent::OpenPopup( StackablePopupOpen::CompareCommits( InspectCommitOpen::new(commit_id), @@ -296,9 +296,9 @@ impl Component for BranchListPopup { self.queue.push(InternalEvent::FetchRemotes); } else if key_match(e, self.key_config.keys.reset_branch) { - if let Some(b) = self.get_selected_branch() { + if let Some(commit_id) = self.get_selected_commit() { self.queue.push(InternalEvent::OpenResetPopup( - b.top_commit, + commit_id, )); } } else if key_match( @@ -479,7 +479,7 @@ impl BranchListPopup { } fn inspect_head_of_branch(&mut self) { - if let Some(commit_id) = self.get_selected() { + if let Some(commit_id) = self.get_selected_commit() { self.hide(); self.queue.push(InternalEvent::OpenPopup( StackablePopupOpen::InspectCommit( @@ -522,16 +522,13 @@ impl BranchListPopup { .count() > 0 } - fn get_selected(&self) -> Option { + // top commit of selected branch + fn get_selected_commit(&self) -> Option { self.branches .get(usize::from(self.selection)) .map(|b| b.top_commit) } - fn get_selected_branch(&self) -> Option<&BranchInfo> { - self.branches.get(usize::from(self.selection)) - } - /// fn move_selection(&mut self, scroll: ScrollType) -> Result { let new_selection = match scroll { From 7aa051c6a5454ff6b71335827bf47ccf9404d26e Mon Sep 17 00:00:00 2001 From: extrawurst Date: Sun, 7 Apr 2024 17:27:42 +0200 Subject: [PATCH 4/4] cleanup some whitespaces --- src/strings.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/strings.rs b/src/strings.rs index b9a761111b..70ca9e3e8f 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -1403,7 +1403,7 @@ pub mod commands { pub fn reset_commit(key_config: &SharedKeyConfig) -> CommandText { CommandText::new( format!( - "Confirm [{}]", + "Confirm [{}]", key_config.get_hint(key_config.keys.enter), ), "confirm reset", @@ -1414,7 +1414,7 @@ pub mod commands { pub fn reset_branch(key_config: &SharedKeyConfig) -> CommandText { CommandText::new( format!( - "Reset [{}]", + "Reset [{}]", key_config.get_hint(key_config.keys.reset_branch), ), "confirm reset", @@ -1425,7 +1425,7 @@ pub mod commands { pub fn reset_type(key_config: &SharedKeyConfig) -> CommandText { CommandText::new( format!( - "Change Type [{}{}]", + "Change Type [{}{}]", key_config.get_hint(key_config.keys.move_up), key_config.get_hint(key_config.keys.move_down) ),