Skip to content

Commit f27227a

Browse files
author
Stephan Dilly
authored
Conflict free rebase (#896)
* unittest for rebasing with conflicts * hide branchlist after rebase
1 parent bf56d3b commit f27227a

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
![emojified-commit-message](assets/emojified-commit-message.png)
1717

1818
## Added
19-
- add supporting rebasing on branch ([#816](https://github.com/extrawurst/gitui/issues/816))
19+
- add supporting rebasing on branch (if conflict-free) ([#816](https://github.com/extrawurst/gitui/issues/816))
2020
- fuzzy find files ([#891](https://github.com/extrawurst/gitui/issues/891))
2121
- visualize progress during async syntax highlighting ([#889](https://github.com/extrawurst/gitui/issues/889))
2222
- added support for markdown emoji's in commits [[@andrewpollack](https://github.com/andrewpollack)] ([#768](https://github.com/extrawurst/gitui/issues/768))

asyncgit/src/sync/branch/merge_rebase.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
error::{Error, Result},
5-
sync::{rebase::conflict_free_rebase, utils},
5+
sync::{rebase::conflict_free_rebase, utils, CommitId},
66
};
77
use git2::BranchType;
88
use scopetime::scope_time;
@@ -11,7 +11,7 @@ use scopetime::scope_time;
1111
pub fn merge_upstream_rebase(
1212
repo_path: &str,
1313
branch_name: &str,
14-
) -> Result<()> {
14+
) -> Result<CommitId> {
1515
scope_time!("merge_upstream_rebase");
1616

1717
let repo = utils::repo(repo_path)?;
@@ -27,9 +27,7 @@ pub fn merge_upstream_rebase(
2727
let annotated_upstream =
2828
repo.find_annotated_commit(upstream_commit.id())?;
2929

30-
conflict_free_rebase(&repo, &annotated_upstream)?;
31-
32-
Ok(())
30+
conflict_free_rebase(&repo, &annotated_upstream)
3331
}
3432

3533
#[cfg(test)]

asyncgit/src/sync/rebase.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ pub fn conflict_free_rebase(
4040
#[cfg(test)]
4141
mod tests {
4242
use crate::sync::{
43-
checkout_branch, create_branch, rebase_branch,
43+
checkout_branch, create_branch, rebase_branch, repo_state,
4444
tests::{repo_init, write_commit_file},
45-
CommitId,
45+
CommitId, RepoState,
4646
};
4747
use git2::Repository;
4848

@@ -84,4 +84,29 @@ mod tests {
8484

8585
assert_eq!(parent_ids(&repo, r), vec![c3]);
8686
}
87+
88+
#[test]
89+
fn test_conflict() {
90+
let (_td, repo) = repo_init().unwrap();
91+
let root = repo.path().parent().unwrap();
92+
let repo_path = root.as_os_str().to_str().unwrap();
93+
94+
write_commit_file(&repo, "test.txt", "test1", "commit1");
95+
96+
create_branch(repo_path, "foo").unwrap();
97+
98+
write_commit_file(&repo, "test.txt", "test2", "commit2");
99+
100+
checkout_branch(repo_path, "refs/heads/master").unwrap();
101+
102+
write_commit_file(&repo, "test.txt", "test3", "commit3");
103+
104+
checkout_branch(repo_path, "refs/heads/foo").unwrap();
105+
106+
let res = rebase_branch(repo_path, "master");
107+
108+
assert!(res.is_err());
109+
110+
assert_eq!(repo_state(repo_path).unwrap(), RepoState::Clean);
111+
}
87112
}

src/components/branchlist.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,14 @@ impl BranchListComponent {
375375
Ok(())
376376
}
377377

378-
fn rebase_branch(&self) -> Result<()> {
378+
fn rebase_branch(&mut self) -> Result<()> {
379379
if let Some(branch) =
380380
self.branches.get(usize::from(self.selection))
381381
{
382382
sync::rebase_branch(CWD, &branch.name)?;
383383

384+
self.hide();
385+
384386
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
385387
}
386388

0 commit comments

Comments
 (0)