Skip to content

Conflict free rebase #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 3 additions & 5 deletions asyncgit/src/sync/branch/merge_rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,7 +11,7 @@ use scopetime::scope_time;
pub fn merge_upstream_rebase(
repo_path: &str,
branch_name: &str,
) -> Result<()> {
) -> Result<CommitId> {
scope_time!("merge_upstream_rebase");

let repo = utils::repo(repo_path)?;
Expand All @@ -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)]
Expand Down
29 changes: 27 additions & 2 deletions asyncgit/src/sync/rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
4 changes: 3 additions & 1 deletion src/components/branchlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down