From d4db614a0104dcd57383ae6b218e8511cc8ade10 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 15 Aug 2021 18:13:39 +0200 Subject: [PATCH] update branch list if a push notification arrives --- src/app.rs | 1 + src/components/branchlist.rs | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/app.rs b/src/app.rs index 43fe83f7..000fbf0f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -359,6 +359,7 @@ impl App { self.push_popup.update_git(ev)?; self.push_tags_popup.update_git(ev)?; self.pull_popup.update_git(ev)?; + self.select_branch_popup.update_git(ev)?; } self.files_tab.update_async(ev); diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index 753eb9a5..0c144b26 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -16,7 +16,7 @@ use asyncgit::{ self, branch::checkout_remote_branch, checkout_branch, get_branches_info, BranchInfo, }, - CWD, + AsyncGitNotification, CWD, }; use crossterm::event::Event; use std::{cell::Cell, convert::TryInto}; @@ -286,23 +286,39 @@ impl BranchListComponent { /// pub fn open(&mut self) -> Result<()> { - self.update_branches()?; self.show()?; + self.update_branches()?; Ok(()) } /// fetch list of branches pub fn update_branches(&mut self) -> Result<()> { - self.branches = get_branches_info(CWD, self.local)?; - //remove remote branch called `HEAD` - if !self.local { - self.branches - .iter() - .position(|b| b.name.ends_with("/HEAD")) - .map(|idx| self.branches.remove(idx)); + if self.is_visible() { + self.branches = get_branches_info(CWD, self.local)?; + //remove remote branch called `HEAD` + if !self.local { + self.branches + .iter() + .position(|b| b.name.ends_with("/HEAD")) + .map(|idx| self.branches.remove(idx)); + } + self.set_selection(self.selection)?; } - self.set_selection(self.selection)?; + Ok(()) + } + + /// + pub fn update_git( + &mut self, + ev: AsyncGitNotification, + ) -> Result<()> { + if self.is_visible() { + if let AsyncGitNotification::Push = ev { + self.update_branches()?; + } + } + Ok(()) }