Skip to content

Commit 044496e

Browse files
committed
Exit later if no commits found in stack
1 parent a8fb298 commit 044496e

File tree

1 file changed

+53
-7
lines changed

1 file changed

+53
-7
lines changed

src/lib.rs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
4444
config.force_detach,
4545
logger,
4646
)?;
47-
if stack.is_empty() {
48-
crit!(logger, "No commits available to fix up, exiting");
49-
return Ok(());
50-
}
5147

5248
let autostage_enabled = config::auto_stage_if_nothing_staged(repo);
5349
let index_was_empty = nothing_left_in_index(repo)?;
@@ -374,7 +370,14 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
374370
--base to increase the search range."
375371
)
376372
}
377-
} else if config.and_rebase {
373+
}
374+
375+
if stack.is_empty() {
376+
crit!(logger, "No commits available to fix up, exiting");
377+
return Ok(());
378+
}
379+
380+
if config.and_rebase && patches_considered != 0 {
378381
use std::process::Command;
379382
// unwrap() is safe here, as we exit early if the stack is empty
380383
let last_commit_in_stack = &stack.last().unwrap().0;
@@ -777,6 +780,16 @@ mod tests {
777780
"level": "WARN",
778781
"msg": "Please try a different --base",
779782
}),
783+
&json!({
784+
"level": "WARN",
785+
"msg": "Could not find a commit to fix up, \
786+
use --base to increase the search range.",
787+
}),
788+
&json!({
789+
"level": "WARN",
790+
"msg": "Could not find a commit to fix up, \
791+
use --base to increase the search range.",
792+
}),
780793
&json!({
781794
"level": "CRIT",
782795
"msg": "No commits available to fix up, exiting",
@@ -812,6 +825,16 @@ mod tests {
812825
"level": "WARN",
813826
"msg": "Will not fix up past the merge commit",
814827
}),
828+
&json!({
829+
"level": "WARN",
830+
"msg": "Could not find a commit to fix up, \
831+
use --base to increase the search range.",
832+
}),
833+
&json!({
834+
"level": "WARN",
835+
"msg": "Could not find a commit to fix up, \
836+
use --base to increase the search range.",
837+
}),
815838
&json!({
816839
"level": "CRIT",
817840
"msg": "No commits available to fix up, exiting",
@@ -1031,7 +1054,17 @@ mod tests {
10311054
&json!({
10321055
"level": "WARN",
10331056
"msg": "Will not fix up past commits not authored by you, \
1034-
use --force-author to override"
1057+
use --force-author to override",
1058+
}),
1059+
&json!({
1060+
"level": "WARN",
1061+
"msg": "Could not find a commit to fix up, \
1062+
use --base to increase the search range.",
1063+
}),
1064+
&json!({
1065+
"level": "WARN",
1066+
"msg": "Could not find a commit to fix up, \
1067+
use --base to increase the search range.",
10351068
}),
10361069
&json!({"level": "CRIT", "msg": "No commits available to fix up, exiting"}),
10371070
],
@@ -1140,7 +1173,20 @@ mod tests {
11401173
"level": "WARN",
11411174
"msg": "HEAD is not a branch, but --force-detach used to continue.",
11421175
}),
1143-
&json!({"level": "WARN", "msg": "Please use --base to specify a base commit."}),
1176+
&json!({
1177+
"level": "WARN",
1178+
"msg": "Please use --base to specify a base commit.",
1179+
}),
1180+
&json!({
1181+
"level": "WARN",
1182+
"msg": "Could not find a commit to fix up, \
1183+
use --base to increase the search range.",
1184+
}),
1185+
&json!({
1186+
"level": "WARN",
1187+
"msg": "Could not find a commit to fix up, \
1188+
use --base to increase the search range.",
1189+
}),
11441190
&json!({"level": "CRIT", "msg": "No commits available to fix up, exiting"}),
11451191
],
11461192
);

0 commit comments

Comments
 (0)