Skip to content

Commit bea78e7

Browse files
authored
Improve abort behavior if edit causes conflicts (#27)
leave the repo in a healthy state.
1 parent cd6ab6e commit bea78e7

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Unreleased
22

33
* Correctly retarget branches if the target of the edit is also a branch (#24)
4+
* Check if main, master, develop, or trunk exist as reasonable default upstream branches
5+
* Leave the repo in a less confusing state if the edit target is a conflict
46

57
# Version 0.2.1
68

src/lib.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use anyhow::{anyhow, bail, Context};
44
use console::style;
55
use dialoguer::{Confirm, Select};
66
use git2::{
7-
Branch, BranchType, Commit, Diff, DiffFormat, DiffStatsFormat, Object, Oid, Rebase, Repository,
7+
AnnotatedCommit, Branch, BranchType, Commit, Diff, DiffFormat, DiffStatsFormat, Object, Oid,
8+
Rebase, Repository,
89
};
910
use syntect::easy::HighlightLines;
1011
use syntect::highlighting::ThemeSet;
@@ -64,25 +65,37 @@ fn do_rebase(
6465

6566
let mut branches = RepoBranches::for_repo(repo)?;
6667

67-
apply_diff_in_rebase(repo, rebase, diff, &mut branches)?;
68+
if let Err(e) = apply_diff_in_rebase(repo, rebase, diff, &mut branches) {
69+
print_help_and_abort_rebase(rebase, &first_parent).context("aborting rebase")?;
70+
return Err(e);
71+
}
6872

6973
match do_rebase_inner(repo, rebase, fixup_message, branches) {
7074
Ok(_) => {
7175
rebase.finish(None)?;
7276
Ok(())
7377
}
7478
Err(e) => {
75-
eprintln!("Aborting rebase, please apply it manualy via");
76-
eprintln!(
77-
" git rebase --interactive --autosquash {}~",
78-
first_parent.id()
79-
);
80-
rebase.abort()?;
79+
print_help_and_abort_rebase(rebase, &first_parent).context("aborting rebase")?;
8180
Err(e)
8281
}
8382
}
8483
}
8584

85+
fn print_help_and_abort_rebase(
86+
rebase: &mut Rebase,
87+
first_parent: &AnnotatedCommit,
88+
) -> Result<(), git2::Error> {
89+
eprintln!("Aborting rebase, your changes are in the head commit.");
90+
eprintln!("You can apply it manually via:");
91+
eprintln!(
92+
" git rebase --interactive --autosquash {}~",
93+
first_parent.id()
94+
);
95+
rebase.abort()?;
96+
Ok(())
97+
}
98+
8699
fn apply_diff_in_rebase(
87100
repo: &Repository,
88101
rebase: &mut Rebase,

0 commit comments

Comments
 (0)