diff --git a/CHANGELOG.md b/CHANGELOG.md index 6de7dfe88d..576d89bf33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ![emojified-commit-message](assets/emojified-commit-message.png) ## Added -- add supporting rebasing on branch ([#816](https://github.com/extrawurst/gitui/issues/816)) +- add supporting rebasing on branch (if conflict-free) ([#816](https://github.com/extrawurst/gitui/issues/816)) - fuzzy find files ([#891](https://github.com/extrawurst/gitui/issues/891)) - visualize progress during async syntax highlighting ([#889](https://github.com/extrawurst/gitui/issues/889)) - added support for markdown emoji's in commits [[@andrewpollack](https://github.com/andrewpollack)] ([#768](https://github.com/extrawurst/gitui/issues/768)) diff --git a/asyncgit/src/sync/branch/merge_rebase.rs b/asyncgit/src/sync/branch/merge_rebase.rs index 7c8ac7ef3e..271ee03f2a 100644 --- a/asyncgit/src/sync/branch/merge_rebase.rs +++ b/asyncgit/src/sync/branch/merge_rebase.rs @@ -2,7 +2,7 @@ use crate::{ error::{Error, Result}, - sync::{rebase::conflict_free_rebase, utils}, + sync::{rebase::conflict_free_rebase, utils, CommitId}, }; use git2::BranchType; use scopetime::scope_time; @@ -11,7 +11,7 @@ use scopetime::scope_time; pub fn merge_upstream_rebase( repo_path: &str, branch_name: &str, -) -> Result<()> { +) -> Result { scope_time!("merge_upstream_rebase"); let repo = utils::repo(repo_path)?; @@ -27,9 +27,7 @@ pub fn merge_upstream_rebase( let annotated_upstream = repo.find_annotated_commit(upstream_commit.id())?; - conflict_free_rebase(&repo, &annotated_upstream)?; - - Ok(()) + conflict_free_rebase(&repo, &annotated_upstream) } #[cfg(test)] diff --git a/asyncgit/src/sync/rebase.rs b/asyncgit/src/sync/rebase.rs index 020f8f257a..053eb483a0 100644 --- a/asyncgit/src/sync/rebase.rs +++ b/asyncgit/src/sync/rebase.rs @@ -40,9 +40,9 @@ pub fn conflict_free_rebase( #[cfg(test)] mod tests { use crate::sync::{ - checkout_branch, create_branch, rebase_branch, + checkout_branch, create_branch, rebase_branch, repo_state, tests::{repo_init, write_commit_file}, - CommitId, + CommitId, RepoState, }; use git2::Repository; @@ -84,4 +84,29 @@ mod tests { assert_eq!(parent_ids(&repo, r), vec![c3]); } + + #[test] + fn test_conflict() { + let (_td, repo) = repo_init().unwrap(); + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + + write_commit_file(&repo, "test.txt", "test1", "commit1"); + + create_branch(repo_path, "foo").unwrap(); + + write_commit_file(&repo, "test.txt", "test2", "commit2"); + + checkout_branch(repo_path, "refs/heads/master").unwrap(); + + write_commit_file(&repo, "test.txt", "test3", "commit3"); + + checkout_branch(repo_path, "refs/heads/foo").unwrap(); + + let res = rebase_branch(repo_path, "master"); + + assert!(res.is_err()); + + assert_eq!(repo_state(repo_path).unwrap(), RepoState::Clean); + } } diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index e5fd184e43..e092b952b2 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -375,12 +375,14 @@ impl BranchListComponent { Ok(()) } - fn rebase_branch(&self) -> Result<()> { + fn rebase_branch(&mut self) -> Result<()> { if let Some(branch) = self.branches.get(usize::from(self.selection)) { sync::rebase_branch(CWD, &branch.name)?; + self.hide(); + self.queue.push(InternalEvent::Update(NeedsUpdate::ALL)); }