@@ -4,7 +4,8 @@ use anyhow::{anyhow, bail, Context};
4
4
use console:: style;
5
5
use dialoguer:: { Confirm , Select } ;
6
6
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 ,
8
9
} ;
9
10
use syntect:: easy:: HighlightLines ;
10
11
use syntect:: highlighting:: ThemeSet ;
@@ -64,25 +65,37 @@ fn do_rebase(
64
65
65
66
let mut branches = RepoBranches :: for_repo ( repo) ?;
66
67
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
+ }
68
72
69
73
match do_rebase_inner ( repo, rebase, fixup_message, branches) {
70
74
Ok ( _) => {
71
75
rebase. finish ( None ) ?;
72
76
Ok ( ( ) )
73
77
}
74
78
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" ) ?;
81
80
Err ( e)
82
81
}
83
82
}
84
83
}
85
84
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
+
86
99
fn apply_diff_in_rebase (
87
100
repo : & Repository ,
88
101
rebase : & mut Rebase ,
0 commit comments