From bc611bca5235445fd02b890b4b0ff3b54488fa0f Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Thu, 19 Aug 2021 22:20:54 +0200 Subject: [PATCH] allow inspecting top commit in branchlist --- CHANGELOG.md | 1 + src/components/blame_file.rs | 2 +- src/components/branchlist.rs | 32 +++++++++++++++++++++++++++----- src/strings.rs | 6 ++++-- src/tabs/revlog.rs | 2 +- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad7e430..f98f2c7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ![name-validation](assets/branch-validation.gif) ## Added +- allow opening top commit of a branch - new options popup (show untracked files, diff settings) ([#849](https://github.com/extrawurst/gitui/issues/849)) - mark and drop multiple stashes ([#854](https://github.com/extrawurst/gitui/issues/854)) - check branch name validity while typing ([#559](https://github.com/extrawurst/gitui/issues/559)) diff --git a/src/components/blame_file.rs b/src/components/blame_file.rs index be1a0151..2c26b167 100644 --- a/src/components/blame_file.rs +++ b/src/components/blame_file.rs @@ -166,7 +166,7 @@ impl Component for BlameFileComponent { ); out.push( CommandInfo::new( - strings::commands::log_details_open( + strings::commands::commit_details_open( &self.key_config, ), true, diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index b183cace..1c0a2afc 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -14,7 +14,7 @@ use anyhow::Result; use asyncgit::{ sync::{ self, branch::checkout_remote_branch, checkout_branch, - get_branches_info, BranchInfo, + get_branches_info, BranchInfo, CommitId, }, AsyncGitNotification, CWD, }; @@ -118,6 +118,14 @@ impl Component for BranchListComponent { true, )); + out.push(CommandInfo::new( + strings::commands::commit_details_open( + &self.key_config, + ), + true, + true, + )); + out.push(CommandInfo::new( strings::commands::toggle_branch_popup( &self.key_config, @@ -192,6 +200,9 @@ impl Component for BranchListComponent { return self .move_selection(ScrollType::PageUp) .map(Into::into); + } else if e == self.key_config.tab_toggle { + self.local = !self.local; + self.update_branches()?; } else if e == self.key_config.enter { try_or_popup!( self, @@ -234,13 +245,18 @@ impl Component for BranchListComponent { "merge branch error:", self.merge_branch() ); - self.hide(); self.queue.push(InternalEvent::Update( NeedsUpdate::ALL, )); - } else if e == self.key_config.tab_toggle { - self.local = !self.local; - self.update_branches()?; + } else if e == self.key_config.move_right + && self.valid_selection() + { + self.hide(); + if let Some(b) = self.get_selected() { + self.queue.push( + InternalEvent::InspectCommit(b, None), + ); + } } } @@ -351,6 +367,12 @@ impl BranchListComponent { .count() > 0 } + fn get_selected(&self) -> Option { + self.branches + .get(usize::from(self.selection)) + .map(|b| b.top_commit) + } + /// fn move_selection(&mut self, scroll: ScrollType) -> Result { let new_selection = match scroll { diff --git a/src/strings.rs b/src/strings.rs index d802b886..14804edc 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -929,7 +929,8 @@ pub mod commands { CMD_GROUP_LOG, ) } - pub fn log_details_open( + + pub fn commit_details_open( key_config: &SharedKeyConfig, ) -> CommandText { CommandText::new( @@ -938,9 +939,10 @@ pub mod commands { key_config.get_hint(key_config.focus_right), ), "inspect selected commit in detail", - CMD_GROUP_LOG, + CMD_GROUP_GENERAL, ) } + pub fn blame_file(key_config: &SharedKeyConfig) -> CommandText { CommandText::new( format!( diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index 22c5b07d..ddcf74af 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -292,7 +292,7 @@ impl Component for Revlog { )); out.push(CommandInfo::new( - strings::commands::log_details_open(&self.key_config), + strings::commands::commit_details_open(&self.key_config), true, (self.visible && self.commit_details.is_visible()) || force_all,