From 99553731fe4b58aa2356ee84d9778b644ae2ca35 Mon Sep 17 00:00:00 2001 From: Alessandro Menezes Date: Wed, 6 Oct 2021 07:46:28 -0400 Subject: [PATCH 1/2] Switch to status tab after merge / rebase with conflicts Issue #926 --- CHANGELOG.md | 1 + asyncgit/src/sync/mod.rs | 4 ++-- asyncgit/src/sync/utils.rs | 8 ++++++++ src/components/branchlist.rs | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 885a11b06f..f2e7297829 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Added - support rebasing branches with conflicts ([#895](https://github.com/extrawurst/gitui/issues/895)) +- switch to status tab after merging or rebasing with conflicts ([#926](https://github.com/extrawurst/gitui/issues/926)) ## Fixed - fix supported checkout of hierarchical branchnames ([#921](https://github.com/extrawurst/gitui/issues/921)) diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 2eb32bb34b..1ff7620d06 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -79,8 +79,8 @@ pub use tags::{ }; pub use tree::{tree_file_content, tree_files, TreeFile}; pub use utils::{ - get_head, get_head_tuple, is_bare_repo, is_repo, repo_dir, - stage_add_all, stage_add_file, stage_addremoved, Head, + get_head, get_head_tuple, has_conflicts, is_bare_repo, is_repo, + repo_dir, stage_add_all, stage_add_file, stage_addremoved, Head, }; #[cfg(test)] diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 52cfcb3dc8..9c0e20a2ee 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -197,6 +197,14 @@ pub(crate) fn repo_write_file( Ok(()) } +/// checks if repository has conflicts +pub fn has_conflicts(repo_path: &str) -> Result { + let repo = repo(repo_path)?; + let index = repo.index()?; + + Ok(index.has_conflicts()) +} + #[cfg(test)] pub(crate) fn repo_read_file( repo: &Repository, diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index e092b952b2..6ba7195335 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -368,8 +368,7 @@ impl BranchListComponent { { sync::merge_branch(CWD, &branch.name)?; - self.hide(); - self.queue.push(InternalEvent::Update(NeedsUpdate::ALL)); + self.hide_and_check_for_conflicts()?; } Ok(()) @@ -381,9 +380,18 @@ impl BranchListComponent { { sync::rebase_branch(CWD, &branch.name)?; - self.hide(); + self.hide_and_check_for_conflicts()?; + } + + Ok(()) + } + + fn hide_and_check_for_conflicts(&mut self) -> Result<()> { + self.hide(); + self.queue.push(InternalEvent::Update(NeedsUpdate::ALL)); - self.queue.push(InternalEvent::Update(NeedsUpdate::ALL)); + if sync::has_conflicts(CWD)? { + self.queue.push(InternalEvent::TabSwitch); } Ok(()) From 6256a95601e39c8297dcf9904ac3d1c98f2aa431 Mon Sep 17 00:00:00 2001 From: Alessandro Menezes Date: Wed, 6 Oct 2021 18:55:55 -0400 Subject: [PATCH 2/2] Switch to Status tab if repo state is not `Clean` --- asyncgit/src/sync/mod.rs | 4 ++-- asyncgit/src/sync/utils.rs | 8 -------- src/components/branchlist.rs | 9 +++++---- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 1ff7620d06..2eb32bb34b 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -79,8 +79,8 @@ pub use tags::{ }; pub use tree::{tree_file_content, tree_files, TreeFile}; pub use utils::{ - get_head, get_head_tuple, has_conflicts, is_bare_repo, is_repo, - repo_dir, stage_add_all, stage_add_file, stage_addremoved, Head, + get_head, get_head_tuple, is_bare_repo, is_repo, repo_dir, + stage_add_all, stage_add_file, stage_addremoved, Head, }; #[cfg(test)] diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 9c0e20a2ee..52cfcb3dc8 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -197,14 +197,6 @@ pub(crate) fn repo_write_file( Ok(()) } -/// checks if repository has conflicts -pub fn has_conflicts(repo_path: &str) -> Result { - let repo = repo(repo_path)?; - let index = repo.index()?; - - Ok(index.has_conflicts()) -} - #[cfg(test)] pub(crate) fn repo_read_file( repo: &Repository, diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index 6ba7195335..7360268ec5 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -19,6 +19,7 @@ use asyncgit::{ RemoteBranch, }, checkout_branch, get_branches_info, BranchInfo, CommitId, + RepoState, }, AsyncGitNotification, CWD, }; @@ -368,7 +369,7 @@ impl BranchListComponent { { sync::merge_branch(CWD, &branch.name)?; - self.hide_and_check_for_conflicts()?; + self.hide_and_switch_tab()?; } Ok(()) @@ -380,17 +381,17 @@ impl BranchListComponent { { sync::rebase_branch(CWD, &branch.name)?; - self.hide_and_check_for_conflicts()?; + self.hide_and_switch_tab()?; } Ok(()) } - fn hide_and_check_for_conflicts(&mut self) -> Result<()> { + fn hide_and_switch_tab(&mut self) -> Result<()> { self.hide(); self.queue.push(InternalEvent::Update(NeedsUpdate::ALL)); - if sync::has_conflicts(CWD)? { + if sync::repo_state(CWD)? != RepoState::Clean { self.queue.push(InternalEvent::TabSwitch); }