From 8b4d5b761e5db626bcbd2aff0eb938ac58bcd854 Mon Sep 17 00:00:00 2001 From: kpbaks Date: Sat, 18 Jan 2025 20:35:23 +0100 Subject: [PATCH 1/3] fix: disable blame and history popup for untracked files An untracked file does not have any history data. Right now when you press `B` for the blame popup or the `H` for the history popup you get an empty popup where the title spins endlessly trying to find the file in the commit history, and show relevant information. This commit disables the two actions in the `StatusTreeComponent`, when the selected item is a file which is not tracked by git. --- src/components/status_tree.rs | 84 ++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/src/components/status_tree.rs b/src/components/status_tree.rs index 1d5f39cb6f..8ed267768c 100644 --- a/src/components/status_tree.rs +++ b/src/components/status_tree.rs @@ -395,11 +395,18 @@ impl Component for StatusTreeComponent { out: &mut Vec, force_all: bool, ) -> CommandBlocking { + let available = self.focused || force_all; + let selection = self.selection_file(); + let selected_is_file = selection.is_some(); + let tracked = selection.is_some_and(|s| { + !matches!(s.status, StatusItemType::New) + }); + out.push( CommandInfo::new( strings::commands::navigate_tree(&self.key_config), !self.is_empty(), - self.focused || force_all, + available, ) .order(order::NAV), ); @@ -407,8 +414,8 @@ impl Component for StatusTreeComponent { out.push( CommandInfo::new( strings::commands::blame_file(&self.key_config), - self.selection_file().is_some(), - self.focused || force_all, + selected_is_file && tracked, + available, ) .order(order::RARE_ACTION), ); @@ -418,8 +425,8 @@ impl Component for StatusTreeComponent { strings::commands::open_file_history( &self.key_config, ), - self.selection_file().is_some(), - self.focused || force_all, + selected_is_file && tracked, + available, ) .order(order::RARE_ACTION), ); @@ -427,8 +434,8 @@ impl Component for StatusTreeComponent { out.push( CommandInfo::new( strings::commands::edit_item(&self.key_config), - self.selection_file().is_some(), - self.focused || force_all, + selected_is_file, + available, ) .order(order::RARE_ACTION), ); @@ -436,8 +443,8 @@ impl Component for StatusTreeComponent { out.push( CommandInfo::new( strings::commands::copy_path(&self.key_config), - self.selection_file().is_some(), - self.focused || force_all, + selected_is_file, + available, ) .order(order::RARE_ACTION), ); @@ -449,30 +456,53 @@ impl Component for StatusTreeComponent { if self.focused { if let Event::Key(e) = ev { return if key_match(e, self.key_config.keys.blame) { - if let Some(status_item) = self.selection_file() { - self.hide(); - self.queue.push(InternalEvent::OpenPopup( - StackablePopupOpen::BlameFile( - BlameFileOpen { - file_path: status_item.path, - commit_id: self.revision, - selection: None, - }, - ), - )); + match self.selection_file() { + Some(status_item) + if !matches!( + status_item.status, + StatusItemType::New + ) => + { + self.hide(); + self.queue.push( + InternalEvent::OpenPopup( + StackablePopupOpen::BlameFile( + BlameFileOpen { + file_path: status_item + .path, + commit_id: self.revision, + selection: None, + }, + ), + ), + ); + } + _ => {} } Ok(EventState::Consumed) } else if key_match( e, self.key_config.keys.file_history, ) { - if let Some(status_item) = self.selection_file() { - self.hide(); - self.queue.push(InternalEvent::OpenPopup( - StackablePopupOpen::FileRevlog( - FileRevOpen::new(status_item.path), - ), - )); + match self.selection_file() { + Some(status_item) + if !matches!( + status_item.status, + StatusItemType::New + ) => + { + self.hide(); + self.queue.push( + InternalEvent::OpenPopup( + StackablePopupOpen::FileRevlog( + FileRevOpen::new( + status_item.path, + ), + ), + ), + ); + } + _ => {} } Ok(EventState::Consumed) } else if key_match(e, self.key_config.keys.edit_file) From 2634d40867b1b18bc63740355f63011a02561210 Mon Sep 17 00:00:00 2001 From: kpbaks Date: Sun, 19 Jan 2025 11:48:22 +0100 Subject: [PATCH 2/3] fixup! fix: disable blame and history popup for untracked files --- src/components/status_tree.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/status_tree.rs b/src/components/status_tree.rs index 8ed267768c..1cd8bd941b 100644 --- a/src/components/status_tree.rs +++ b/src/components/status_tree.rs @@ -452,6 +452,7 @@ impl Component for StatusTreeComponent { CommandBlocking::PassingOn } + #[expect(clippy::cognitive_complexity)] fn event(&mut self, ev: &Event) -> Result { if self.focused { if let Event::Key(e) = ev { From 9b76e4c7e5ae3fec8a8d84ac7d8311f43ae94a0a Mon Sep 17 00:00:00 2001 From: kpbaks Date: Sat, 30 Aug 2025 23:38:25 +0200 Subject: [PATCH 3/3] fixup! fix: disable blame and history popup for untracked files --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e60180cdc5..9fb43befbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixes * resolve `core.hooksPath` relative to `GIT_WORK_TREE` [[@naseschwarz](https://github.com/naseschwarz)] ([#2571](https://github.com/gitui-org/gitui/issues/2571)) * yanking commit ranges no longer generates incorrect dotted range notations, but lists each individual commit [[@naseschwarz](https://github.com/naseschwarz)] (https://github.com/gitui-org/gitui/issues/2576) +* disable blame and history popup keybinds for untracked files [[@kpbaks](https://github.com/kpbaks)] ([#2489](https://github.com/gitui-org/gitui/pull/2489)) ## [0.27.0] - 2024-01-14