aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-02-22 16:09:45 -0800
committerJunio C Hamano <gitster@pobox.com>2024-02-22 16:09:45 -0800
commit5dc73662976e81de19a5b3a76f4733962f541df5 (patch)
tree659cc6379239ff29345605e75404a19d276c45b1
parentefb050becb6bc703f76382e1f1b6273100e6ace3 (diff)
parentbc47139f4ff6c0c41d4c854ca74c35b1006a464a (diff)
downloadgit-5dc73662976e81de19a5b3a76f4733962f541df5.tar.gz
Merge branch 'la/trailer-cleanups' into maint-2.43
* la/trailer-cleanups: trailer: fix comment/cut-line regression with opts->no_divider
-rwxr-xr-xt/t7502-commit-porcelain.sh18
-rwxr-xr-xt/t7513-interpret-trailers.sh19
-rw-r--r--trailer.c15
3 files changed, 44 insertions, 8 deletions
diff --git a/t/t7502-commit-porcelain.sh b/t/t7502-commit-porcelain.sh
index 61c8e810cc..a87c211d0b 100755
--- a/t/t7502-commit-porcelain.sh
+++ b/t/t7502-commit-porcelain.sh
@@ -485,6 +485,24 @@ test_expect_success 'commit --trailer not confused by --- separator' '
test_cmp expected actual
'
+test_expect_success 'commit --trailer with --verbose' '
+ cat >msg <<-\EOF &&
+ subject
+
+ body
+ EOF
+ GIT_EDITOR=: git commit --edit -F msg --allow-empty \
+ --trailer="my-trailer: value" --verbose &&
+ {
+ cat msg &&
+ echo &&
+ echo "my-trailer: value"
+ } >expected &&
+ git cat-file commit HEAD >commit.msg &&
+ sed -e "1,/^\$/d" commit.msg >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'multiple -m' '
>negative &&
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 832aff0616..ec9c6de114 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -1916,4 +1916,23 @@ test_expect_success 'suppress --- handling' '
test_cmp expected actual
'
+test_expect_success 'suppressing --- does not disable cut-line handling' '
+ echo "real-trailer: before the cut" >expected &&
+
+ git interpret-trailers --parse --no-divider >actual <<-\EOF &&
+ subject
+
+ This input has a cut-line in it; we should stop parsing when we see it
+ and consider only trailers before that line.
+
+ real-trailer: before the cut
+
+ # ------------------------ >8 ------------------------
+ # Nothing below this line counts as part of the commit message.
+ not-a-trailer: too late
+ EOF
+
+ test_cmp expected actual
+'
+
test_done
diff --git a/trailer.c b/trailer.c
index 3a0710a458..ef9df4af55 100644
--- a/trailer.c
+++ b/trailer.c
@@ -845,16 +845,15 @@ static size_t find_end_of_log_message(const char *input, int no_divider)
/* Assume the naive end of the input is already what we want. */
end = strlen(input);
- if (no_divider)
- return end;
-
/* Optionally skip over any patch part ("---" line and below). */
- for (s = input; *s; s = next_line(s)) {
- const char *v;
+ if (!no_divider) {
+ for (s = input; *s; s = next_line(s)) {
+ const char *v;
- if (skip_prefix(s, "---", &v) && isspace(*v)) {
- end = s - input;
- break;
+ if (skip_prefix(s, "---", &v) && isspace(*v)) {
+ end = s - input;
+ break;
+ }
}
}