From dfa4d7789d8ae51c42e34ea0924e598b127dfff3 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Mon, 1 Mar 2021 11:10:25 +0100 Subject: [PATCH] only even try to ff merge when there is something incoming (#554) * Update pull.rs --- src/components/pull.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/components/pull.rs b/src/components/pull.rs index d984ef00..f4a0a0a3 100644 --- a/src/components/pull.rs +++ b/src/components/pull.rs @@ -127,19 +127,7 @@ impl PullComponent { self.git_fetch.last_result()? { if err.is_empty() { - let merge_res = - sync::branch_merge_upstream_fastforward( - CWD, - &self.branch, - ); - if let Err(err) = merge_res { - self.queue.borrow_mut().push_back( - InternalEvent::ShowErrorMsg(format!( - "merge failed:\n{}", - err - )), - ); - } + self.do_merge()?; } else { self.queue.borrow_mut().push_back( InternalEvent::ShowErrorMsg(format!( @@ -154,6 +142,28 @@ impl PullComponent { Ok(()) } + + // check if something is incoming and try a ff merge then + fn do_merge(&self) -> Result<()> { + let branch_compare = + sync::branch_compare_upstream(CWD, &self.branch)?; + if branch_compare.behind > 0 { + let merge_res = sync::branch_merge_upstream_fastforward( + CWD, + &self.branch, + ); + if let Err(err) = merge_res { + self.queue.borrow_mut().push_back( + InternalEvent::ShowErrorMsg(format!( + "merge failed:\n{}", + err + )), + ); + } + } + + Ok(()) + } } impl DrawableComponent for PullComponent {