Merge branch 'jk/trailer-fixes' into maint

"git interpret-trailers" and its underlying machinery had a buggy
code that attempted to ignore patch text after commit log message,
which triggered in various codepaths that will always get the log
message alone and never get such an input.

* jk/trailer-fixes:
  append_signoff: use size_t for string offsets
  sequencer: ignore "---" divider when parsing trailers
  pretty, ref-filter: format %(trailers) with no_divider option
  interpret-trailers: allow suppressing "---" divider
  interpret-trailers: tighten check for "---" patch boundary
  trailer: pass process_trailer_opts to trailer_info_get()
  trailer: use size_t for iterating trailer list
  trailer: use size_t for string offsets
This commit is contained in:
Junio C Hamano
2018-11-21 22:57:41 +09:00
14 changed files with 175 additions and 39 deletions

View File

@ -598,4 +598,27 @@ test_expect_success ':only and :unfold work together' '
test_cmp expect actual
'
test_expect_success 'trailer parsing not fooled by --- line' '
git commit --allow-empty -F - <<-\EOF &&
this is the subject
This is the body. The message has a "---" line which would confuse a
message+patch parser. But here we know we have only a commit message,
so we get it right.
trailer: wrong
---
This is more body.
trailer: right
EOF
{
echo "trailer: right" &&
echo
} >expect &&
git log --no-walk --format="%(trailers)" >actual &&
test_cmp expect actual
'
test_done

View File

@ -715,6 +715,29 @@ test_expect_success 'basic atom: head contents:trailers' '
test_cmp expect actual.clean
'
test_expect_success 'trailer parsing not fooled by --- line' '
git commit --allow-empty -F - <<-\EOF &&
this is the subject
This is the body. The message has a "---" line which would confuse a
message+patch parser. But here we know we have only a commit message,
so we get it right.
trailer: wrong
---
This is more body.
trailer: right
EOF
{
echo "trailer: right" &&
echo
} >expect &&
git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
test_cmp expect actual
'
test_expect_success 'Add symbolic ref for the following tests' '
git symbolic-ref refs/heads/sym refs/heads/master
'

View File

@ -517,6 +517,22 @@ Myfooter: x" &&
test_cmp expected actual
'
test_expect_success 'signoff not confused by ---' '
cat >expected <<-EOF &&
subject
body
---
these dashes confuse the parser!
Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
EOF
# should be a noop, since we already signed
git commit --allow-empty --signoff -F expected &&
git log -1 --pretty=format:%B >actual &&
test_cmp expected actual
'
test_expect_success 'multiple -m' '
>negative &&

View File

@ -1417,4 +1417,46 @@ test_expect_success 'unfold' '
test_cmp expected actual
'
test_expect_success 'handling of --- lines in input' '
echo "real-trailer: just right" >expected &&
git interpret-trailers --parse >actual <<-\EOF &&
subject
body
not-a-trailer: too soon
------ this is just a line in the commit message with a bunch of
------ dashes; it does not have any syntactic meaning.
real-trailer: just right
---
below the dashed line may be a patch, etc.
not-a-trailer: too late
EOF
test_cmp expected actual
'
test_expect_success 'suppress --- handling' '
echo "real-trailer: just right" >expected &&
git interpret-trailers --parse --no-divider >actual <<-\EOF &&
subject
This commit message has a "---" in it, but because we tell
interpret-trailers not to respect that, it has no effect.
not-a-trailer: too soon
---
This is still the commit message body.
real-trailer: just right
EOF
test_cmp expected actual
'
test_done