Skip to content

Commit 535f660

Browse files
committed
Warn once about modified hunk with no target commit
1 parent 88e8f1d commit 535f660

File tree

1 file changed

+26
-71
lines changed

1 file changed

+26
-71
lines changed

src/lib.rs

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
129129

130130
let mut hunks_with_commit = vec![];
131131

132+
let mut modified_hunks_without_target = 0usize;
132133
let mut patches_considered = 0usize;
133134
'patch: for index_patch in index.iter() {
134135
let old_path = index_patch.new_path.as_slice();
@@ -266,11 +267,7 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
266267
// the hunk commutes with every commit in the stack,
267268
// so there is no commit to absorb it into
268269
None => {
269-
warn!(
270-
logger,
271-
"Could not find a commit to fix up, use \
272-
--base to increase the search range."
273-
);
270+
modified_hunks_without_target += 1;
274271
continue 'hunk;
275272
}
276273
};
@@ -380,6 +377,15 @@ fn run_with_repo(logger: &slog::Logger, config: &Config, repo: &git2::Repository
380377
--base to increase the search range."
381378
)
382379
}
380+
381+
if modified_hunks_without_target > 0 {
382+
warn!(
383+
logger,
384+
"Could not find a commit to fix up, use \
385+
--base to increase the search range."
386+
);
387+
}
388+
383389
if stack.is_empty() {
384390
crit!(logger, "No commits available to fix up, exiting");
385391
return Ok(());
@@ -627,11 +633,6 @@ mod tests {
627633
"msg": "Could not find a commit to fix up, \
628634
use --base to increase the search range.",
629635
}),
630-
&json!({
631-
"level": "WARN",
632-
"msg": "Could not find a commit to fix up, \
633-
use --base to increase the search range.",
634-
}),
635636
],
636637
);
637638
}
@@ -725,11 +726,6 @@ mod tests {
725726
"msg": "Could not find a commit to fix up, \
726727
use --base to increase the search range.",
727728
}),
728-
&json!({
729-
"level": "WARN",
730-
"msg": "Could not find a commit to fix up, \
731-
use --base to increase the search range.",
732-
}),
733729
],
734730
);
735731
}
@@ -793,11 +789,6 @@ mod tests {
793789
"msg": "Could not find a commit to fix up, \
794790
use --base to increase the search range.",
795791
}),
796-
&json!({
797-
"level": "WARN",
798-
"msg": "Could not find a commit to fix up, \
799-
use --base to increase the search range.",
800-
}),
801792
&json!({
802793
"level": "CRIT",
803794
"msg": "No commits available to fix up, exiting",
@@ -838,11 +829,6 @@ mod tests {
838829
"msg": "Could not find a commit to fix up, \
839830
use --base to increase the search range.",
840831
}),
841-
&json!({
842-
"level": "WARN",
843-
"msg": "Could not find a commit to fix up, \
844-
use --base to increase the search range.",
845-
}),
846832
&json!({
847833
"level": "CRIT",
848834
"msg": "No commits available to fix up, exiting",
@@ -924,18 +910,11 @@ mod tests {
924910

925911
log_utils::assert_log_messages_are(
926912
capturing_logger.visible_logs(),
927-
vec![
928-
&json!({
929-
"level": "WARN",
930-
"msg": "Could not find a commit to fix up, \
931-
use --base to increase the search range.",
932-
}),
933-
&json!({
934-
"level": "WARN",
935-
"msg": "Could not find a commit to fix up, \
936-
use --base to increase the search range.",
937-
}),
938-
],
913+
vec![&json!({
914+
"level": "WARN",
915+
"msg": "Could not find a commit to fix up, \
916+
use --base to increase the search range.",
917+
})],
939918
);
940919
}
941920

@@ -963,18 +942,11 @@ mod tests {
963942

964943
log_utils::assert_log_messages_are(
965944
capturing_logger.visible_logs(),
966-
vec![
967-
&json!({
968-
"level": "WARN",
969-
"msg": "Could not find a commit to fix up, \
970-
use --base to increase the search range.",
971-
}),
972-
&json!({
973-
"level": "WARN",
974-
"msg": "Could not find a commit to fix up, \
975-
use --base to increase the search range.",
976-
}),
977-
],
945+
vec![&json!({
946+
"level": "WARN",
947+
"msg": "Could not find a commit to fix up, \
948+
use --base to increase the search range.",
949+
})],
978950
);
979951
}
980952

@@ -1001,18 +973,11 @@ mod tests {
1001973

1002974
log_utils::assert_log_messages_are(
1003975
capturing_logger.visible_logs(),
1004-
vec![
1005-
&json!({
1006-
"level": "WARN",
1007-
"msg": "Could not find a commit to fix up, \
1008-
use --base to increase the search range.",
1009-
}),
1010-
&json!({
1011-
"level": "WARN",
1012-
"msg": "Could not find a commit to fix up, \
1013-
use --base to increase the search range.",
1014-
}),
1015-
],
976+
vec![&json!({
977+
"level": "WARN",
978+
"msg": "Could not find a commit to fix up, \
979+
use --base to increase the search range.",
980+
})],
1016981
);
1017982
}
1018983

@@ -1069,11 +1034,6 @@ mod tests {
10691034
"msg": "Could not find a commit to fix up, \
10701035
use --base to increase the search range.",
10711036
}),
1072-
&json!({
1073-
"level": "WARN",
1074-
"msg": "Could not find a commit to fix up, \
1075-
use --base to increase the search range.",
1076-
}),
10771037
&json!({"level": "CRIT", "msg": "No commits available to fix up, exiting"}),
10781038
],
10791039
);
@@ -1190,11 +1150,6 @@ mod tests {
11901150
"msg": "Could not find a commit to fix up, \
11911151
use --base to increase the search range.",
11921152
}),
1193-
&json!({
1194-
"level": "WARN",
1195-
"msg": "Could not find a commit to fix up, \
1196-
use --base to increase the search range.",
1197-
}),
11981153
&json!({"level": "CRIT", "msg": "No commits available to fix up, exiting"}),
11991154
],
12001155
);

0 commit comments

Comments
 (0)