Skip to content

Commit f96c385

Browse files
rjustogitster
authored andcommitted
format-patch: assume --cover-letter for diff in multi-patch series
When we deal with a multi-patch series in git-format-patch(1), if we see `--interdiff` or `--range-diff` but no `--cover-letter`, we return with an error, saying: fatal: --range-diff requires --cover-letter or single patch or: fatal: --interdiff requires --cover-letter or single patch This makes sense because the cover-letter is where we place the diff from the previous version. However, considering that `format-patch` generates a multi-patch as needed, let's adopt a similar "cover as necessary" approach when using `--interdiff` or `--range-diff`. Therefore, relax the requirement for an explicit `--cover-letter` in a multi-patch series when the user says `--iterdiff` or `--range-diff`. Still, if only to return the error, respect "format.coverLetter=no" and `--no-cover-letter`. Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc665cd commit f96c385

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

builtin/log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
22552255
if (cover_letter == -1) {
22562256
if (config_cover_letter == COVER_AUTO)
22572257
cover_letter = (total > 1);
2258+
else if ((idiff_prev.nr || rdiff_prev) && (total > 1))
2259+
cover_letter = (config_cover_letter != COVER_OFF);
22582260
else
22592261
cover_letter = (config_cover_letter == COVER_ON);
22602262
}

t/t3206-range-diff.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,20 @@ do
545545
'
546546
done
547547

548+
test_expect_success "--range-diff implies --cover-letter for multi-patch series" '
549+
test_when_finished "rm -f v2-000?-*" &&
550+
git format-patch -v2 --range-diff=topic main..unmodified &&
551+
test_grep "^Range-diff against v1:$" v2-0000-cover-letter.patch
552+
'
553+
554+
test_expect_success "explicit --no-cover-letter defeats implied --cover-letter" '
555+
test_when_finished "rm -f v2-000?-*" &&
556+
test_must_fail git format-patch --no-cover-letter \
557+
-v2 --range-diff=topic main..unmodified &&
558+
test_must_fail git -c format.coverLetter=no format-patch \
559+
-v2 --range-diff=topic main..unmodified
560+
'
561+
548562
test_expect_success 'format-patch --range-diff as commentary' '
549563
git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
550564
test_when_finished "rm 0001-*" &&

t/t4014-format-patch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,21 @@ test_expect_success 'interdiff: solo-patch' '
24452445
test_cmp expect actual
24462446
'
24472447

2448+
test_expect_success 'interdiff: multi-patch, implicit --cover-letter' '
2449+
test_when_finished "rm -f v23-0*.patch" &&
2450+
git format-patch --interdiff=boop~2 -2 -v23 &&
2451+
test_grep "^Interdiff against v22:$" v23-0000-cover-letter.patch &&
2452+
test_cmp expect actual
2453+
'
2454+
2455+
test_expect_success 'interdiff: explicit --no-cover-letter defeats implied --cover-letter' '
2456+
test_when_finished "rm -f v23-0*.patch" &&
2457+
test_must_fail git format-patch --no-cover-letter \
2458+
--interdiff=boop~2 -2 -v23 &&
2459+
test_must_fail git -c format.coverLetter=no format-patch \
2460+
--interdiff=boop~2 -2 -v23
2461+
'
2462+
24482463
test_expect_success 'format-patch does not respect diff.noprefix' '
24492464
git -c diff.noprefix format-patch -1 --stdout >actual &&
24502465
grep "^--- a/blorp" actual

0 commit comments

Comments
 (0)