Skip to content

Commit 145c8bf

Browse files
committed
Switch to status tab after merge / rebase with conflicts
Issue gitui-org#926
1 parent c6abbaf commit 145c8bf

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

asyncgit/src/sync/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub use tags::{
7979
};
8080
pub use tree::{tree_file_content, tree_files, TreeFile};
8181
pub use utils::{
82-
get_head, get_head_tuple, is_bare_repo, is_repo, repo_dir,
83-
stage_add_all, stage_add_file, stage_addremoved, Head,
82+
get_head, get_head_tuple, has_conflicts, is_bare_repo, is_repo,
83+
repo_dir, stage_add_all, stage_add_file, stage_addremoved, Head,
8484
};
8585

8686
#[cfg(test)]

asyncgit/src/sync/utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ pub(crate) fn repo_write_file(
197197
Ok(())
198198
}
199199

200+
/// checks if repository has conflicts
201+
pub fn has_conflicts(repo_path: &str) -> Result<bool> {
202+
let repo = repo(repo_path)?;
203+
let index = repo.index()?;
204+
205+
Ok(index.has_conflicts())
206+
}
207+
200208
#[cfg(test)]
201209
pub(crate) fn repo_read_file(
202210
repo: &Repository,

src/components/branchlist.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ impl BranchListComponent {
368368
{
369369
sync::merge_branch(CWD, &branch.name)?;
370370

371-
self.hide();
372-
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
371+
self.hide_and_check_for_conflicts()?;
373372
}
374373

375374
Ok(())
@@ -381,9 +380,18 @@ impl BranchListComponent {
381380
{
382381
sync::rebase_branch(CWD, &branch.name)?;
383382

384-
self.hide();
383+
self.hide_and_check_for_conflicts()?;
384+
}
385+
386+
Ok(())
387+
}
388+
389+
fn hide_and_check_for_conflicts(&mut self) -> Result<()> {
390+
self.hide();
391+
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
385392

386-
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
393+
if sync::has_conflicts(CWD)? {
394+
self.queue.push(InternalEvent::TabSwitch);
387395
}
388396

389397
Ok(())

0 commit comments

Comments
 (0)