Skip to content

Commit 5dc7366

Browse files
committed
Merge branch 'la/trailer-cleanups' into maint-2.43
* la/trailer-cleanups: trailer: fix comment/cut-line regression with opts->no_divider
2 parents efb050b + bc47139 commit 5dc7366

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

t/t7502-commit-porcelain.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,24 @@ test_expect_success 'commit --trailer not confused by --- separator' '
485485
test_cmp expected actual
486486
'
487487

488+
test_expect_success 'commit --trailer with --verbose' '
489+
cat >msg <<-\EOF &&
490+
subject
491+
492+
body
493+
EOF
494+
GIT_EDITOR=: git commit --edit -F msg --allow-empty \
495+
--trailer="my-trailer: value" --verbose &&
496+
{
497+
cat msg &&
498+
echo &&
499+
echo "my-trailer: value"
500+
} >expected &&
501+
git cat-file commit HEAD >commit.msg &&
502+
sed -e "1,/^\$/d" commit.msg >actual &&
503+
test_cmp expected actual
504+
'
505+
488506
test_expect_success 'multiple -m' '
489507
490508
>negative &&

t/t7513-interpret-trailers.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,4 +1916,23 @@ test_expect_success 'suppress --- handling' '
19161916
test_cmp expected actual
19171917
'
19181918

1919+
test_expect_success 'suppressing --- does not disable cut-line handling' '
1920+
echo "real-trailer: before the cut" >expected &&
1921+
1922+
git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1923+
subject
1924+
1925+
This input has a cut-line in it; we should stop parsing when we see it
1926+
and consider only trailers before that line.
1927+
1928+
real-trailer: before the cut
1929+
1930+
# ------------------------ >8 ------------------------
1931+
# Nothing below this line counts as part of the commit message.
1932+
not-a-trailer: too late
1933+
EOF
1934+
1935+
test_cmp expected actual
1936+
'
1937+
19191938
test_done

trailer.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -845,16 +845,15 @@ static size_t find_end_of_log_message(const char *input, int no_divider)
845845
/* Assume the naive end of the input is already what we want. */
846846
end = strlen(input);
847847

848-
if (no_divider)
849-
return end;
850-
851848
/* Optionally skip over any patch part ("---" line and below). */
852-
for (s = input; *s; s = next_line(s)) {
853-
const char *v;
849+
if (!no_divider) {
850+
for (s = input; *s; s = next_line(s)) {
851+
const char *v;
854852

855-
if (skip_prefix(s, "---", &v) && isspace(*v)) {
856-
end = s - input;
857-
break;
853+
if (skip_prefix(s, "---", &v) && isspace(*v)) {
854+
end = s - input;
855+
break;
856+
}
858857
}
859858
}
860859

0 commit comments

Comments
 (0)