2014-10-13 18:16:30 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013, 2014 Christian Couder
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='git interpret-trailers'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
# When we want one trailing space at the end of each line, let's use sed
|
|
|
|
# to make sure that these spaces are not removed by any automatic tool.
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
: >empty &&
|
|
|
|
cat >basic_message <<-\EOF &&
|
|
|
|
subject
|
|
|
|
|
|
|
|
body
|
|
|
|
EOF
|
|
|
|
cat >complex_message_body <<-\EOF &&
|
|
|
|
my subject
|
|
|
|
|
|
|
|
my body which is long
|
|
|
|
and contains some special
|
|
|
|
chars like : = ? !
|
|
|
|
|
|
|
|
EOF
|
|
|
|
sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by: Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
cat >basic_patch <<-\EOF
|
|
|
|
---
|
|
|
|
foo.txt | 2 +-
|
|
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
|
|
|
|
diff --git a/foo.txt b/foo.txt
|
|
|
|
index 0353767..1d91aa1 100644
|
|
|
|
--- a/foo.txt
|
|
|
|
+++ b/foo.txt
|
|
|
|
@@ -1,3 +1,3 @@
|
|
|
|
|
|
|
|
-bar
|
|
|
|
+baz
|
|
|
|
|
|
|
|
--
|
|
|
|
1.9.rc0.11.ga562ddc
|
|
|
|
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
trailer: add new .cmd config option
The `trailer.<token>.command` configuration variable
specifies a command (run via the shell, so it does not have
to be a single name or path to the command, but can be a
shell script), and the first occurrence of substring $ARG is
replaced with the value given to the `interpret-trailer`
command for the token in a '--trailer <token>=<value>' argument.
This has three downsides:
* The use of $ARG in the mechanism misleads the users that
the value is passed in the shell variable, and tempt them
to use $ARG more than once, but that would not work, as
the second and subsequent $ARG are not replaced.
* Because $ARG is textually replaced without regard to the
shell language syntax, even '$ARG' (inside a single-quote
pair), which a user would expect to stay intact, would be
replaced, and worse, if the value had an unmatched single
quote (imagine a name like "O'Connor", substituted into
NAME='$ARG' to make it NAME='O'Connor'), it would result in
a broken command that is not syntactically correct (or
worse).
* The first occurrence of substring `$ARG` will be replaced
with the empty string, in the command when the command is
first called to add a trailer with the specified <token>.
This is a bad design, the nature of automatic execution
causes it to add a trailer that we don't expect.
Introduce a new `trailer.<token>.cmd` configuration that
takes higher precedence to deprecate and eventually remove
`trailer.<token>.command`, which passes the value as an
argument to the command. Instead of "$ARG", users can
refer to the value as positional argument, $1, in their
scripts. At the same time, in order to allow
`git interpret-trailers` to better simulate the behavior
of `git command -s`, 'trailer.<token>.cmd' will not
automatically execute.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-05-03 15:41:05 +00:00
|
|
|
test_expect_success 'with cmd' '
|
|
|
|
test_when_finished "git config --remove-section trailer.bug" &&
|
|
|
|
git config trailer.bug.key "Bug-maker: " &&
|
|
|
|
git config trailer.bug.ifExists "add" &&
|
|
|
|
git config trailer.bug.cmd "echo \"maybe is\"" &&
|
|
|
|
cat >expected2 <<-EOF &&
|
|
|
|
|
|
|
|
Bug-maker: maybe is him
|
|
|
|
Bug-maker: maybe is me
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
|
|
|
|
>actual2 &&
|
|
|
|
test_cmp expected2 actual2
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with cmd and $1' '
|
|
|
|
test_when_finished "git config --remove-section trailer.bug" &&
|
|
|
|
git config trailer.bug.key "Bug-maker: " &&
|
|
|
|
git config trailer.bug.ifExists "add" &&
|
|
|
|
git config trailer.bug.cmd "echo \"\$1\" is" &&
|
|
|
|
cat >expected2 <<-EOF &&
|
|
|
|
|
|
|
|
Bug-maker: him is him
|
|
|
|
Bug-maker: me is me
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
|
|
|
|
>actual2 &&
|
|
|
|
test_cmp expected2 actual2
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with cmd and $1 with sh -c' '
|
|
|
|
test_when_finished "git config --remove-section trailer.bug" &&
|
|
|
|
git config trailer.bug.key "Bug-maker: " &&
|
|
|
|
git config trailer.bug.ifExists "replace" &&
|
|
|
|
git config trailer.bug.cmd "sh -c \"echo who is \"\$1\"\"" &&
|
|
|
|
cat >expected2 <<-EOF &&
|
|
|
|
|
|
|
|
Bug-maker: who is me
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
|
|
|
|
>actual2 &&
|
|
|
|
test_cmp expected2 actual2
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with cmd and $1 with shell script' '
|
|
|
|
test_when_finished "git config --remove-section trailer.bug" &&
|
|
|
|
git config trailer.bug.key "Bug-maker: " &&
|
|
|
|
git config trailer.bug.ifExists "replace" &&
|
|
|
|
git config trailer.bug.cmd "./echoscript" &&
|
|
|
|
cat >expected2 <<-EOF &&
|
|
|
|
|
|
|
|
Bug-maker: who is me
|
|
|
|
EOF
|
|
|
|
cat >echoscript <<-EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
echo who is "\$1"
|
|
|
|
EOF
|
|
|
|
chmod +x echoscript &&
|
|
|
|
git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
|
|
|
|
>actual2 &&
|
|
|
|
test_cmp expected2 actual2
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'without config' '
|
|
|
|
sed -e "s/ Z\$/ /" >expected <<-\EOF &&
|
|
|
|
|
|
|
|
ack: Peff
|
|
|
|
Reviewed-by: Z
|
|
|
|
Acked-by: Johan
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \
|
|
|
|
--trailer "Acked-by: Johan" empty >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'without config in another order' '
|
|
|
|
sed -e "s/ Z\$/ /" >expected <<-\EOF &&
|
|
|
|
|
|
|
|
Acked-by: Johan
|
|
|
|
Reviewed-by: Z
|
|
|
|
ack: Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \
|
|
|
|
--trailer "ack = Peff" empty >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--trim-empty without config' '
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
ack: Peff
|
|
|
|
Acked-by: Johan
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer ack=Peff \
|
|
|
|
--trailer "Reviewed-by" --trailer "Acked-by: Johan" \
|
|
|
|
--trailer "sob:" empty >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with config option on the command line' '
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
Acked-by: Johan
|
|
|
|
Reviewed-by: Peff
|
|
|
|
EOF
|
tests: fix broken &&-chains in `{...}` groups
The top-level &&-chain checker built into t/test-lib.sh causes tests to
magically exit with code 117 if the &&-chain is broken. However, it has
the shortcoming that the magic does not work within `{...}` groups,
`(...)` subshells, `$(...)` substitutions, or within bodies of compound
statements, such as `if`, `for`, `while`, `case`, etc. `chainlint.sed`
partly fills in the gap by catching broken &&-chains in `(...)`
subshells, but bugs can still lurk behind broken &&-chains in the other
cases.
Fix broken &&-chains in `{...}` groups in order to reduce the number of
possible lurking bugs.
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-12-09 05:11:08 +00:00
|
|
|
{ echo && echo "Acked-by: Johan"; } |
|
2014-10-13 18:16:30 +00:00
|
|
|
git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
|
|
|
|
--trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2015-08-26 02:51:00 +00:00
|
|
|
test_expect_success 'with only a title in the message' '
|
2015-08-20 21:59:15 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
area: change
|
|
|
|
|
|
|
|
Reviewed-by: Peff
|
|
|
|
Acked-by: Johan
|
|
|
|
EOF
|
|
|
|
echo "area: change" |
|
|
|
|
git interpret-trailers --trailer "Reviewed-by: Peff" \
|
|
|
|
--trailer "Acked-by: Johan" >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2015-08-30 19:14:40 +00:00
|
|
|
test_expect_success 'with multiline title in the message' '
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
place of
|
|
|
|
code: change
|
|
|
|
|
|
|
|
Reviewed-by: Peff
|
|
|
|
Acked-by: Johan
|
|
|
|
EOF
|
|
|
|
printf "%s\n" "place of" "code: change" |
|
|
|
|
git interpret-trailers --trailer "Reviewed-by: Peff" \
|
|
|
|
--trailer "Acked-by: Johan" >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-10-21 17:55:01 +00:00
|
|
|
test_expect_success 'with non-trailer lines mixed with Signed-off-by' '
|
|
|
|
cat >patch <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
Signed-off-by: a <a@example.com>
|
|
|
|
this is not a trailer
|
|
|
|
EOF
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
Signed-off-by: a <a@example.com>
|
|
|
|
this is not a trailer
|
|
|
|
token: value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "token: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with non-trailer lines mixed with cherry picked from' '
|
|
|
|
cat >patch <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
(cherry picked from commit x)
|
|
|
|
this is not a trailer
|
|
|
|
EOF
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
(cherry picked from commit x)
|
|
|
|
this is not a trailer
|
|
|
|
token: value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "token: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with non-trailer lines mixed with a configured trailer' '
|
|
|
|
cat >patch <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
My-trailer: x
|
|
|
|
this is not a trailer
|
|
|
|
EOF
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
My-trailer: x
|
|
|
|
this is not a trailer
|
|
|
|
token: value
|
|
|
|
EOF
|
|
|
|
test_config trailer.my.key "My-trailer: " &&
|
|
|
|
git interpret-trailers --trailer "token: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with non-trailer lines mixed with a non-configured trailer' '
|
|
|
|
cat >patch <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
I-am-not-configured: x
|
|
|
|
this is not a trailer
|
|
|
|
EOF
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
I-am-not-configured: x
|
|
|
|
this is not a trailer
|
|
|
|
|
|
|
|
token: value
|
|
|
|
EOF
|
|
|
|
test_config trailer.my.key "My-trailer: " &&
|
|
|
|
git interpret-trailers --trailer "token: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with all non-configured trailers' '
|
|
|
|
cat >patch <<-\EOF &&
|
|
|
|
|
|
|
|
I-am-not-configured: x
|
|
|
|
I-am-also-not-configured: x
|
|
|
|
EOF
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
I-am-not-configured: x
|
|
|
|
I-am-also-not-configured: x
|
|
|
|
token: value
|
|
|
|
EOF
|
|
|
|
test_config trailer.my.key "My-trailer: " &&
|
|
|
|
git interpret-trailers --trailer "token: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with non-trailer lines only' '
|
|
|
|
cat >patch <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
EOF
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
this is not a trailer
|
|
|
|
|
|
|
|
token: value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "token: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-10-21 17:55:02 +00:00
|
|
|
test_expect_success 'line with leading whitespace is not trailer' '
|
|
|
|
q_to_tab >patch <<-\EOF &&
|
|
|
|
|
|
|
|
Qtoken: value
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
Qtoken: value
|
|
|
|
|
|
|
|
token: value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "token: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-10-21 17:55:03 +00:00
|
|
|
test_expect_success 'multiline field treated as one trailer for 25% check' '
|
|
|
|
q_to_tab >patch <<-\EOF &&
|
|
|
|
|
|
|
|
Signed-off-by: a <a@example.com>
|
|
|
|
name: value on
|
|
|
|
Qmultiple lines
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
Signed-off-by: a <a@example.com>
|
|
|
|
name: value on
|
|
|
|
Qmultiple lines
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
this is not a trailer
|
|
|
|
name: value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "name: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'multiline field treated as atomic for placement' '
|
|
|
|
q_to_tab >patch <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: value on
|
|
|
|
Qmultiple lines
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: value on
|
|
|
|
Qmultiple lines
|
|
|
|
name: value
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
test_config trailer.name.where after &&
|
|
|
|
git interpret-trailers --trailer "name: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'multiline field treated as atomic for replacement' '
|
|
|
|
q_to_tab >patch <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: value on
|
|
|
|
Qmultiple lines
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
another: trailer
|
|
|
|
name: value
|
|
|
|
EOF
|
|
|
|
test_config trailer.name.ifexists replace &&
|
|
|
|
git interpret-trailers --trailer "name: value" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'multiline field treated as atomic for difference check' '
|
|
|
|
q_to_tab >patch <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
test_config trailer.name.ifexists addIfDifferent &&
|
|
|
|
|
|
|
|
q_to_tab >trailer <<-\EOF &&
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
|
|
|
|
q_to_tab >trailer <<-\EOF &&
|
|
|
|
name: first line
|
|
|
|
QQQQQsecond line
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
QQQQQsecond line
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
|
|
|
|
q_to_tab >trailer <<-\EOF &&
|
|
|
|
name: first line *DIFFERENT*
|
|
|
|
Qsecond line
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
another: trailer
|
|
|
|
name: first line *DIFFERENT*
|
|
|
|
Qsecond line
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'multiline field treated as atomic for neighbor check' '
|
|
|
|
q_to_tab >patch <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
test_config trailer.name.where after &&
|
|
|
|
test_config trailer.name.ifexists addIfDifferentNeighbor &&
|
|
|
|
|
|
|
|
q_to_tab >trailer <<-\EOF &&
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
|
|
|
|
q_to_tab >trailer <<-\EOF &&
|
|
|
|
name: first line
|
|
|
|
QQQQQsecond line
|
|
|
|
EOF
|
|
|
|
q_to_tab >expected <<-\EOF &&
|
|
|
|
|
|
|
|
another: trailer
|
|
|
|
name: first line
|
|
|
|
Qsecond line
|
|
|
|
name: first line
|
|
|
|
QQQQQsecond line
|
|
|
|
another: trailer
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'with config setup' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by: " &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
Acked-by: Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with config setup and ":=" as separators' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
Acked-by= Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with config setup and "%" as separators' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators "%" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
bug% 42
|
|
|
|
count% 10
|
|
|
|
bug% 422
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer "bug = 42" \
|
|
|
|
--trailer count%10 --trailer "test: stuff" \
|
|
|
|
--trailer "bug % 422" empty >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with "%" as separators and a message with trailers' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators "%" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat >special_message <<-\EOF &&
|
|
|
|
Special Message
|
|
|
|
|
|
|
|
bug% 42
|
|
|
|
count% 10
|
|
|
|
bug% 422
|
|
|
|
EOF
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
Special Message
|
|
|
|
|
|
|
|
bug% 42
|
|
|
|
count% 10
|
|
|
|
bug% 422
|
|
|
|
count% 100
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer count%100 \
|
|
|
|
special_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with config setup and ":=#" as separators' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=#" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
|
|
|
|
Bug #42
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with commit basic message' '
|
|
|
|
cat basic_message >expected &&
|
|
|
|
echo >>expected &&
|
|
|
|
git interpret-trailers <basic_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with basic patch' '
|
|
|
|
cat basic_message >input &&
|
|
|
|
cat basic_patch >>input &&
|
|
|
|
cat basic_message >expected &&
|
|
|
|
echo >>expected &&
|
|
|
|
cat basic_patch >>expected &&
|
|
|
|
git interpret-trailers <input >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with commit complex message as argument' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body complex_message_trailers >complex_message &&
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with 2 files arguments' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat basic_message >>expected &&
|
|
|
|
echo >>expected &&
|
|
|
|
cat basic_patch >>expected &&
|
|
|
|
git interpret-trailers complex_message input >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2019-06-19 03:37:28 +00:00
|
|
|
# Cover multiple comment characters with the same test input.
|
|
|
|
for char in "#" ";"
|
|
|
|
do
|
|
|
|
case "$char" in
|
|
|
|
"#")
|
|
|
|
# This is the default, so let's explicitly _not_
|
|
|
|
# set any config to make sure it behaves as we expect.
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
config="-c core.commentChar=$char"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
test_expect_success "with message that has comments ($char)" '
|
|
|
|
cat basic_message >message_with_comments &&
|
|
|
|
sed -e "s/ Z\$/ /" \
|
|
|
|
-e "s/#/$char/g" >>message_with_comments <<-EOF &&
|
|
|
|
# comment
|
|
|
|
|
|
|
|
# other comment
|
|
|
|
Cc: Z
|
|
|
|
# yet another comment
|
|
|
|
Reviewed-by: Johan
|
|
|
|
Reviewed-by: Z
|
|
|
|
# last comment
|
|
|
|
|
|
|
|
EOF
|
|
|
|
cat basic_patch >>message_with_comments &&
|
|
|
|
cat basic_message >expected &&
|
|
|
|
sed -e "s/#/$char/g" >>expected <<-\EOF &&
|
|
|
|
# comment
|
|
|
|
|
|
|
|
Reviewed-by: Johan
|
|
|
|
Cc: Peff
|
|
|
|
# last comment
|
|
|
|
|
|
|
|
EOF
|
|
|
|
cat basic_patch >>expected &&
|
|
|
|
git $config interpret-trailers \
|
|
|
|
--trim-empty --trailer "Cc: Peff" \
|
|
|
|
message_with_comments >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
done
|
2014-10-13 18:16:30 +00:00
|
|
|
|
2014-11-09 09:23:43 +00:00
|
|
|
test_expect_success 'with message that has an old style conflict block' '
|
|
|
|
cat basic_message >message_with_comments &&
|
|
|
|
sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
|
|
|
|
# comment
|
|
|
|
|
|
|
|
# other comment
|
|
|
|
Cc: Z
|
|
|
|
# yet another comment
|
|
|
|
Reviewed-by: Johan
|
|
|
|
Reviewed-by: Z
|
|
|
|
# last comment
|
|
|
|
|
|
|
|
Conflicts:
|
|
|
|
|
|
|
|
EOF
|
|
|
|
cat basic_message >expected &&
|
|
|
|
cat >>expected <<-\EOF &&
|
|
|
|
# comment
|
|
|
|
|
|
|
|
Reviewed-by: Johan
|
|
|
|
Cc: Peff
|
|
|
|
# last comment
|
|
|
|
|
|
|
|
Conflicts:
|
|
|
|
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'with commit complex message and trailer args' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=#" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Bug #42
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "bug: 42" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with complex patch, args and --trim-empty' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=#" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message >complex_patch &&
|
|
|
|
cat basic_patch >>complex_patch &&
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
cat >>expected <<-\EOF &&
|
|
|
|
Acked-by= Peff
|
|
|
|
Bug #42
|
|
|
|
EOF
|
|
|
|
cat basic_patch >>expected &&
|
|
|
|
git interpret-trailers --trim-empty --trailer "ack: Peff" \
|
|
|
|
--trailer "bug: 42" <complex_patch >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-01-14 16:57:55 +00:00
|
|
|
test_expect_success 'in-place editing with basic patch' '
|
|
|
|
cat basic_message >message &&
|
|
|
|
cat basic_patch >>message &&
|
|
|
|
cat basic_message >expected &&
|
|
|
|
echo >>expected &&
|
|
|
|
cat basic_patch >>expected &&
|
|
|
|
git interpret-trailers --in-place message &&
|
|
|
|
test_cmp expected message
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'in-place editing with additional trailer' '
|
|
|
|
cat basic_message >message &&
|
|
|
|
cat basic_patch >>message &&
|
|
|
|
cat basic_message >expected &&
|
|
|
|
echo >>expected &&
|
|
|
|
cat >>expected <<-\EOF &&
|
|
|
|
Reviewed-by: Alice
|
|
|
|
EOF
|
|
|
|
cat basic_patch >>expected &&
|
|
|
|
git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
|
|
|
|
test_cmp expected message
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'in-place editing on stdin disallowed' '
|
|
|
|
test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'in-place editing on non-existing file' '
|
|
|
|
test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
|
|
|
|
test_path_is_missing nonexisting
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
|
|
|
|
cat basic_message >message &&
|
|
|
|
chmod -r message &&
|
|
|
|
test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
|
|
|
|
chmod +r message &&
|
|
|
|
test_cmp message basic_message
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'using "where = before"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=#" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
Acked-by= Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "bug: 42" complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2017-08-01 09:03:32 +00:00
|
|
|
test_expect_success 'overriding configuration with "--where after"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.separators ":=" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "before" &&
|
2017-08-01 09:03:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --where after --trailer "ack: Peff" \
|
|
|
|
complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2023-09-07 22:19:58 +00:00
|
|
|
test_expect_success 'using "--where after" with "--no-where"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "before" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2017-08-01 09:03:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --where after --no-where --trailer "ack: Peff" \
|
|
|
|
--trailer "bug: 42" complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2023-09-07 22:19:59 +00:00
|
|
|
# Check whether using "--no-where" clears out only the "--where after", such
|
|
|
|
# that we still use the configuration in trailer.where (which is different from
|
|
|
|
# the hardcoded default (in WHERE_END) assuming the absence of .gitconfig).
|
|
|
|
# Here, the "start" setting of trailer.where is respected, so the new "Acked-by"
|
|
|
|
# and "Bug" trailers are placed at the beginning, and not at the end which is
|
|
|
|
# the harcoded default.
|
|
|
|
test_expect_success 'using "--where after" with "--no-where" defaults to configuration' '
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
|
|
|
test_config trailer.where "start" &&
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Acked-by= Peff
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --where after --no-where --trailer "ack: Peff" \
|
|
|
|
--trailer "bug: 42" complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
# The "--where after" will only get respected for the trailer that came
|
|
|
|
# immediately after it. For the next trailer (Bug #42), we default to using the
|
|
|
|
# hardcoded WHERE_END because we don't have any "trailer.where" or
|
|
|
|
# "trailer.bug.where" configured.
|
|
|
|
test_expect_success 'using "--no-where" defaults to harcoded default if nothing configured' '
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
Bug #42
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --where after --trailer "ack: Peff" --no-where \
|
|
|
|
--trailer "bug: 42" complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'using "where = after"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "bug: 42" complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "where = end"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.review.key "Reviewed-by" &&
|
|
|
|
test_config trailer.review.where "end" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
Reviewed-by: Junio
|
|
|
|
Reviewed-by: Johannes
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
|
|
|
|
complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "where = start"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.review.key "Reviewed-by" &&
|
|
|
|
test_config trailer.review.where "start" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Reviewed-by: Johannes
|
|
|
|
Reviewed-by: Junio
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
|
|
|
|
complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "where = before" for a token in the middle of the message' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.review.where "before" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:Johan
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
|
|
|
|
--trailer "review: Johan" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "where = before" and --trim-empty' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
cat >>expected <<-\EOF &&
|
|
|
|
Bug #46
|
|
|
|
Bug #42
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:Johan
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer "ack: Peff" \
|
|
|
|
--trailer "bug: 42" --trailer "review: Johan" \
|
|
|
|
--trailer "Bug: 46" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.review.where "before" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
|
|
|
|
--trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
--trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'default "ifExists" is now "addIfDifferent"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Junio
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
|
|
|
|
--trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
--trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "addIfDifferent" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "end" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Acked-by= Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
|
|
|
|
--trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "addIfDifferent" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "before" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
|
|
|
|
--trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "end" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Junio
|
|
|
|
Tested-by: Jakub
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
|
|
|
|
--trailer "ack: Junio" --trailer "bug: 42" \
|
|
|
|
--trailer "Tested-by: Jakub" --trailer "ack: Junio" \
|
|
|
|
--trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Tested-by: Jakub
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
|
|
|
|
--trailer "ack: Junio" --trailer "bug: 42" \
|
|
|
|
--trailer "Tested-by: Jakub" --trailer "ack: Junio" \
|
|
|
|
--trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
cat >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trim-empty --trailer "ack: Peff" \
|
|
|
|
--trailer "Acked-by= Peff" --trailer "review:" \
|
|
|
|
--trailer "ack: Junio" --trailer "bug: 42" \
|
|
|
|
--trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = add" with "where = end"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "add" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "end" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Peff
|
|
|
|
Tested-by: Jakub
|
|
|
|
Acked-by= Junio
|
|
|
|
Tested-by: Johannes
|
|
|
|
Acked-by= Peff
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "Acked-by= Peff" --trailer "review:" \
|
|
|
|
--trailer "Tested-by: Jakub" --trailer "ack: Junio" \
|
|
|
|
--trailer "bug: 42" --trailer "Tested-by: Johannes" \
|
|
|
|
--trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = add" with "where = after"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "add" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "Acked-by= Peff" --trailer "review:" \
|
|
|
|
--trailer "ack: Junio" --trailer "bug: 42" \
|
|
|
|
--trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2017-08-01 09:03:32 +00:00
|
|
|
test_expect_success 'overriding configuration with "--if-exists replace"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "add" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.review.where "before" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2017-08-01 09:03:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Fixes: 22
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --if-exists replace --trailer "review:" \
|
|
|
|
--trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2023-09-07 22:19:59 +00:00
|
|
|
# "trailer.ifexists" is set to "doNothing", so using "--no-if-exists" defaults
|
|
|
|
# to this "doNothing" behavior. So the "Fixes: 53" trailer does not get added.
|
|
|
|
test_expect_success 'using "--if-exists replace" with "--no-if-exists" defaults to configuration' '
|
|
|
|
test_config trailer.ifexists "doNothing" &&
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by: Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --if-exists replace --no-if-exists --trailer "Fixes: 53" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
# No "ifexists" configuration is set, so using "--no-if-exists" makes it default
|
|
|
|
# to addIfDifferentNeighbor. Because we do have a different neighbor "Fixes: 53"
|
|
|
|
# (because it got added by overriding with "--if-exists replace" earlier in the
|
|
|
|
# arguments list), we add "Signed-off-by: addme".
|
|
|
|
test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured' '
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Acked-by: Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
Fixes: 53
|
|
|
|
Signed-off-by: addme
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
|
|
|
|
--trailer "Signed-off-by: addme" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
# The second "Fixes: 53" trailer is discarded, because the "--no-if-exists" here
|
|
|
|
# makes us default to addIfDifferentNeighbor, and we already added the "Fixes:
|
|
|
|
# 53" trailer earlier in the argument list.
|
|
|
|
test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured (no addition)' '
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Acked-by: Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
Fixes: 53
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
|
|
|
|
--trailer "Fixes: 53" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'using "ifExists = replace"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "replace" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Fixes: 22
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" \
|
|
|
|
--trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
|
|
|
|
--trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = replace" with "where = after"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "replace" &&
|
|
|
|
test_config trailer.fix.where "after" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: 22
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" \
|
|
|
|
--trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
|
|
|
|
--trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifExists = doNothing"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=53" \
|
|
|
|
--trailer "ack: Junio" --trailer "fix=22" \
|
|
|
|
--trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'the default is "ifMissing = add"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.cc.key "Cc: " &&
|
|
|
|
test_config trailer.cc.where "before" &&
|
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Cc: Linus
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=53" \
|
|
|
|
--trailer "cc=Linus" --trailer "ack: Junio" \
|
|
|
|
--trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2017-08-01 09:03:32 +00:00
|
|
|
test_expect_success 'overriding configuration with "--if-missing doNothing"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.ifmissing "add" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2017-08-01 09:03:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --if-missing doNothing \
|
|
|
|
--trailer "review:" --trailer "fix=53" \
|
|
|
|
--trailer "cc=Linus" --trailer "ack: Junio" \
|
|
|
|
--trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'when default "ifMissing" is "doNothing"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.ifmissing "doNothing" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=53" \
|
|
|
|
--trailer "cc=Linus" --trailer "ack: Junio" \
|
|
|
|
--trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
2023-09-07 22:19:57 +00:00
|
|
|
test_cmp expected actual
|
2014-10-13 18:16:30 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifMissing = add" with "where = end"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.cc.key "Cc: " &&
|
|
|
|
test_config trailer.cc.ifMissing "add" &&
|
|
|
|
test_config trailer.cc.where "end" &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Cc: Linus
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=53" \
|
|
|
|
--trailer "ack: Junio" --trailer "fix=22" \
|
|
|
|
--trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifMissing = add" with "where = before"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.cc.key "Cc: " &&
|
|
|
|
test_config trailer.cc.ifMissing "add" &&
|
|
|
|
test_config trailer.cc.where "before" &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Cc: Linus
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=53" \
|
|
|
|
--trailer "ack: Junio" --trailer "fix=22" \
|
|
|
|
--trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using "ifMissing = doNothing"' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.cc.ifMissing "doNothing" &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=53" \
|
|
|
|
--trailer "cc=Linus" --trailer "ack: Junio" \
|
|
|
|
--trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2023-09-07 22:19:59 +00:00
|
|
|
# Ignore the "IgnoredTrailer" because of "--if-missing doNothing", but also
|
|
|
|
# ignore the "StillIgnoredTrailer" because we set "trailer.ifMissing" to
|
|
|
|
# "doNothing" in configuration.
|
|
|
|
test_expect_success 'using "--no-if-missing" defaults to configuration' '
|
|
|
|
test_config trailer.ifMissing "doNothing" &&
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by: Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
|
|
|
|
--trailer "StillIgnoredTrailer: ignoreme" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
# Add the "AddedTrailer" because the "--no-if-missing" clears the "--if-missing
|
|
|
|
# doNothing" from earlier in the argument list.
|
|
|
|
test_expect_success 'using "--no-if-missing" defaults to hardcoded default if nothing configured' '
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by: Z
|
|
|
|
Reviewed-by: Z
|
|
|
|
Signed-off-by: Z
|
|
|
|
AddedTrailer: addme
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
|
|
|
|
--trailer "AddedTrailer: addme" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_expect_success 'default "where" is now "after"' '
|
|
|
|
git config trailer.where "after" &&
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.ifExists "add" &&
|
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.ack.where "after" &&
|
|
|
|
test_config trailer.bug.key "Bug #" &&
|
|
|
|
test_config trailer.bug.where "before" &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=#" &&
|
2014-10-13 18:16:30 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Bug #42
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Peff
|
|
|
|
Acked-by= Junio
|
|
|
|
Acked-by= Peff
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Tested-by: Jakub
|
|
|
|
Tested-by: Johannes
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "ack: Peff" \
|
|
|
|
--trailer "Acked-by= Peff" --trailer "review:" \
|
|
|
|
--trailer "Tested-by: Jakub" --trailer "ack: Junio" \
|
|
|
|
--trailer "bug: 42" --trailer "Tested-by: Johannes" \
|
|
|
|
--trailer "ack: Peff" <complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:32 +00:00
|
|
|
test_expect_success 'with simple command' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
|
|
|
|
test_config trailer.sign.key "Signed-off-by: " &&
|
|
|
|
test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
|
|
|
|
test_config trailer.sign.where "after" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Signed-off-by: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=22" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2019-11-05 17:07:25 +00:00
|
|
|
test_expect_success 'with command using committer information' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
|
|
|
|
test_config trailer.sign.key "Signed-off-by: " &&
|
|
|
|
test_config trailer.sign.ifExists "addIfDifferent" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Signed-off-by: C O Mitter <committer@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=22" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with command using author information' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.fix.ifExists "doNothing" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
|
|
|
test_config trailer.sign.key "Signed-off-by: " &&
|
|
|
|
test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
|
|
|
|
test_config trailer.sign.where "after" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Signed-off-by: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=22" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup a commit' '
|
|
|
|
echo "Content of the first commit." > a.txt &&
|
|
|
|
git add a.txt &&
|
|
|
|
git commit -m "Add file a.txt"
|
|
|
|
'
|
|
|
|
|
trailer: add new .cmd config option
The `trailer.<token>.command` configuration variable
specifies a command (run via the shell, so it does not have
to be a single name or path to the command, but can be a
shell script), and the first occurrence of substring $ARG is
replaced with the value given to the `interpret-trailer`
command for the token in a '--trailer <token>=<value>' argument.
This has three downsides:
* The use of $ARG in the mechanism misleads the users that
the value is passed in the shell variable, and tempt them
to use $ARG more than once, but that would not work, as
the second and subsequent $ARG are not replaced.
* Because $ARG is textually replaced without regard to the
shell language syntax, even '$ARG' (inside a single-quote
pair), which a user would expect to stay intact, would be
replaced, and worse, if the value had an unmatched single
quote (imagine a name like "O'Connor", substituted into
NAME='$ARG' to make it NAME='O'Connor'), it would result in
a broken command that is not syntactically correct (or
worse).
* The first occurrence of substring `$ARG` will be replaced
with the empty string, in the command when the command is
first called to add a trailer with the specified <token>.
This is a bad design, the nature of automatic execution
causes it to add a trailer that we don't expect.
Introduce a new `trailer.<token>.cmd` configuration that
takes higher precedence to deprecate and eventually remove
`trailer.<token>.command`, which passes the value as an
argument to the command. Instead of "$ARG", users can
refer to the value as positional argument, $1, in their
scripts. At the same time, in order to allow
`git interpret-trailers` to better simulate the behavior
of `git command -s`, 'trailer.<token>.cmd' will not
automatically execute.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-05-03 15:41:05 +00:00
|
|
|
test_expect_success 'cmd takes precedence over command' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \
|
trailer: add new .cmd config option
The `trailer.<token>.command` configuration variable
specifies a command (run via the shell, so it does not have
to be a single name or path to the command, but can be a
shell script), and the first occurrence of substring $ARG is
replaced with the value given to the `interpret-trailer`
command for the token in a '--trailer <token>=<value>' argument.
This has three downsides:
* The use of $ARG in the mechanism misleads the users that
the value is passed in the shell variable, and tempt them
to use $ARG more than once, but that would not work, as
the second and subsequent $ARG are not replaced.
* Because $ARG is textually replaced without regard to the
shell language syntax, even '$ARG' (inside a single-quote
pair), which a user would expect to stay intact, would be
replaced, and worse, if the value had an unmatched single
quote (imagine a name like "O'Connor", substituted into
NAME='$ARG' to make it NAME='O'Connor'), it would result in
a broken command that is not syntactically correct (or
worse).
* The first occurrence of substring `$ARG` will be replaced
with the empty string, in the command when the command is
first called to add a trailer with the specified <token>.
This is a bad design, the nature of automatic execution
causes it to add a trailer that we don't expect.
Introduce a new `trailer.<token>.cmd` configuration that
takes higher precedence to deprecate and eventually remove
`trailer.<token>.command`, which passes the value as an
argument to the command. Instead of "$ARG", users can
refer to the value as positional argument, $1, in their
scripts. At the same time, in order to allow
`git interpret-trailers` to better simulate the behavior
of `git command -s`, 'trailer.<token>.cmd' will not
automatically execute.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-05-03 15:41:05 +00:00
|
|
|
--abbrev-commit --abbrev=14 \$ARG" &&
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \
|
|
|
|
--abbrev-commit --abbrev=14 \"\$1\" || true" &&
|
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "replace" &&
|
|
|
|
test_config trailer.fix.where "after" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
|
|
|
test_config trailer.sign.key "Signed-off-by: " &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
trailer: add new .cmd config option
The `trailer.<token>.command` configuration variable
specifies a command (run via the shell, so it does not have
to be a single name or path to the command, but can be a
shell script), and the first occurrence of substring $ARG is
replaced with the value given to the `interpret-trailer`
command for the token in a '--trailer <token>=<value>' argument.
This has three downsides:
* The use of $ARG in the mechanism misleads the users that
the value is passed in the shell variable, and tempt them
to use $ARG more than once, but that would not work, as
the second and subsequent $ARG are not replaced.
* Because $ARG is textually replaced without regard to the
shell language syntax, even '$ARG' (inside a single-quote
pair), which a user would expect to stay intact, would be
replaced, and worse, if the value had an unmatched single
quote (imagine a name like "O'Connor", substituted into
NAME='$ARG' to make it NAME='O'Connor'), it would result in
a broken command that is not syntactically correct (or
worse).
* The first occurrence of substring `$ARG` will be replaced
with the empty string, in the command when the command is
first called to add a trailer with the specified <token>.
This is a bad design, the nature of automatic execution
causes it to add a trailer that we don't expect.
Introduce a new `trailer.<token>.cmd` configuration that
takes higher precedence to deprecate and eventually remove
`trailer.<token>.command`, which passes the value as an
argument to the command. Instead of "$ARG", users can
refer to the value as positional argument, $1, in their
scripts. At the same time, in order to allow
`git interpret-trailers` to better simulate the behavior
of `git command -s`, 'trailer.<token>.cmd' will not
automatically execute.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-05-03 15:41:05 +00:00
|
|
|
FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) &&
|
|
|
|
cat complex_message_body >expected2 &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected2 <<-EOF &&
|
|
|
|
Fixes: $FIXED
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Signed-off-by: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
|
|
|
|
<complex_message >actual2 &&
|
|
|
|
test_cmp expected2 actual2
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:32 +00:00
|
|
|
test_expect_success 'with command using $ARG' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
|
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "replace" &&
|
|
|
|
test_config trailer.fix.where "after" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
|
|
|
test_config trailer.sign.key "Signed-off-by: " &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
|
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-EOF &&
|
|
|
|
Fixes: $FIXED
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Signed-off-by: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with failing command using $ARG' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.ack.key "Acked-by= " &&
|
|
|
|
test_config trailer.fix.command "false \$ARG" &&
|
|
|
|
test_config trailer.fix.key "Fixes: " &&
|
|
|
|
test_config trailer.fix.ifExists "replace" &&
|
|
|
|
test_config trailer.fix.where "after" &&
|
|
|
|
test_config trailer.review.key "Reviewed-by:" &&
|
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
|
|
|
test_config trailer.sign.key "Signed-off-by: " &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
|
|
|
test_config trailer.separators ":=" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
cat complex_message_body >expected &&
|
|
|
|
sed -e "s/ Z\$/ /" >>expected <<-EOF &&
|
|
|
|
Fixes: Z
|
|
|
|
Acked-by= Z
|
|
|
|
Reviewed-by:
|
|
|
|
Signed-off-by: Z
|
|
|
|
Signed-off-by: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
|
|
|
|
<complex_message >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with empty tokens' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
|
|
|
test_config trailer.sign.key "Signed-off-by: " &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
|
|
|
|
Signed-off-by: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with command but no key' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
|
|
|
|
sign: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers >actual <<-EOF &&
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with no command and no key' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.review.where "before" &&
|
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
2014-10-13 18:16:32 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
|
|
|
|
review: Junio
|
|
|
|
sign: A U Thor <author@example.com>
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
interpret-trailers: honor the cut line
If a commit message is edited with the "verbose" option, the buffer
will have a cut line and diff after the log message, like so:
my subject
# ------------------------ >8 ------------------------
# Do not touch the line above.
# Everything below will be removed.
diff --git a/foo.txt b/foo.txt
index 5716ca5..7601807 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-bar
+baz
"git interpret-trailers" is unaware of the cut line, and assumes the
trailer block would be at the end of the whole thing. This can easily
be seen with:
$ GIT_EDITOR='git interpret-trailers --in-place --trailer Acked-by:me' \
git commit --amend -v
Teach "git interpret-trailers" to notice the cut-line and ignore the
remainder of the input when looking for a place to add new trailer
block. This makes it consistent with how "git commit -v -s" inserts a
new Signed-off-by: line.
This can be done by the same logic as the existing helper function,
wt_status_truncate_message_at_cut_line(), uses, but it wants the caller
to pass a strbuf to it. Because the function ignore_non_trailer() used
by the command takes a <pointer, length> pair, not a strbuf, steal the
logic from wt_status_truncate_message_at_cut_line() to create a new
wt_status_locate_end() helper function that takes <pointer, length>
pair, and make ignore_non_trailer() call it to help "interpret-trailers".
Since there is only one caller of wt_status_truncate_message_at_cut_line()
in cmd_commit(), rewrite it to call wt_status_locate_end() helper instead
and remove the old helper that no longer has any caller.
Signed-off-by: Brian Malehorn <bmalehorn@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-16 06:06:49 +00:00
|
|
|
test_expect_success 'with cut line' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.review.where "before" &&
|
|
|
|
test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
|
interpret-trailers: honor the cut line
If a commit message is edited with the "verbose" option, the buffer
will have a cut line and diff after the log message, like so:
my subject
# ------------------------ >8 ------------------------
# Do not touch the line above.
# Everything below will be removed.
diff --git a/foo.txt b/foo.txt
index 5716ca5..7601807 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-bar
+baz
"git interpret-trailers" is unaware of the cut line, and assumes the
trailer block would be at the end of the whole thing. This can easily
be seen with:
$ GIT_EDITOR='git interpret-trailers --in-place --trailer Acked-by:me' \
git commit --amend -v
Teach "git interpret-trailers" to notice the cut-line and ignore the
remainder of the input when looking for a place to add new trailer
block. This makes it consistent with how "git commit -v -s" inserts a
new Signed-off-by: line.
This can be done by the same logic as the existing helper function,
wt_status_truncate_message_at_cut_line(), uses, but it wants the caller
to pass a strbuf to it. Because the function ignore_non_trailer() used
by the command takes a <pointer, length> pair, not a strbuf, steal the
logic from wt_status_truncate_message_at_cut_line() to create a new
wt_status_locate_end() helper function that takes <pointer, length>
pair, and make ignore_non_trailer() call it to help "interpret-trailers".
Since there is only one caller of wt_status_truncate_message_at_cut_line()
in cmd_commit(), rewrite it to call wt_status_locate_end() helper instead
and remove the old helper that no longer has any caller.
Signed-off-by: Brian Malehorn <bmalehorn@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-05-16 06:06:49 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
my subject
|
|
|
|
|
|
|
|
review: Brian
|
|
|
|
sign: A U Thor <author@example.com>
|
|
|
|
# ------------------------ >8 ------------------------
|
|
|
|
ignore this
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
|
|
|
|
my subject
|
|
|
|
# ------------------------ >8 ------------------------
|
|
|
|
ignore this
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2017-08-15 10:23:21 +00:00
|
|
|
test_expect_success 'only trailers' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.sign.command "echo config-value" &&
|
|
|
|
test_config trailer.ifexists "addIfDifferent" &&
|
2017-08-15 10:23:21 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
existing: existing-value
|
|
|
|
sign: config-value
|
|
|
|
added: added-value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers \
|
|
|
|
--trailer added:added-value \
|
|
|
|
--only-trailers >actual <<-\EOF &&
|
|
|
|
my subject
|
|
|
|
|
|
|
|
my body
|
|
|
|
|
|
|
|
existing: existing-value
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'only-trailers omits non-trailer in middle of block' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.sign.command "echo config-value" &&
|
2017-08-15 10:23:21 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
Signed-off-by: nobody <nobody@nowhere>
|
|
|
|
Signed-off-by: somebody <somebody@somewhere>
|
|
|
|
sign: config-value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --only-trailers >actual <<-\EOF &&
|
|
|
|
subject
|
|
|
|
|
|
|
|
it is important that the trailers below are signed-off-by
|
|
|
|
so that they meet the "25% trailers Git knows about" heuristic
|
|
|
|
|
|
|
|
Signed-off-by: nobody <nobody@nowhere>
|
|
|
|
this is not a trailer
|
|
|
|
Signed-off-by: somebody <somebody@somewhere>
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2017-08-15 10:23:25 +00:00
|
|
|
test_expect_success 'only input' '
|
2023-09-07 22:19:57 +00:00
|
|
|
test_config trailer.sign.command "echo config-value" &&
|
2017-08-15 10:23:25 +00:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
existing: existing-value
|
|
|
|
EOF
|
|
|
|
git interpret-trailers \
|
|
|
|
--only-trailers --only-input >actual <<-\EOF &&
|
|
|
|
my subject
|
|
|
|
|
|
|
|
my body
|
|
|
|
|
|
|
|
existing: existing-value
|
|
|
|
EOF
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2017-08-15 10:23:29 +00:00
|
|
|
test_expect_success 'unfold' '
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
foo: continued across several lines
|
|
|
|
EOF
|
|
|
|
# pass through tr to make leading and trailing whitespace more obvious
|
|
|
|
tr _ " " <<-\EOF |
|
|
|
|
my subject
|
|
|
|
|
|
|
|
my body
|
|
|
|
|
|
|
|
foo:_
|
|
|
|
__continued
|
|
|
|
___across
|
|
|
|
____several
|
|
|
|
_____lines
|
|
|
|
___
|
|
|
|
EOF
|
|
|
|
git interpret-trailers --only-trailers --only-input --unfold >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
interpret-trailers: tighten check for "---" patch boundary
The interpret-trailers command accepts not only raw commit
messages, but it also can manipulate trailers in
format-patch output. That means it must find the "---"
boundary separating the commit message from the patch.
However, it does so by looking for any line starting with
"---", regardless of whether there is further content.
This is overly lax compared to the parsing done in
mailinfo.c's patchbreak(), and may cause false positives
(e.g., t/perf output tables uses dashes; if you cut and
paste them into your commit message, it fools the parser).
We could try to reuse patchbreak() here, but it actually has
several heuristics that are not of interest to us (e.g.,
matching "diff -" without a three-dash separator or even a
CVS "Index:" line). We're not interested in taking in
whatever random cruft people may send, but rather handling
git-formatted patches.
Note that the existing documentation was written in a loose
way, so technically we are changing the behavior from what
it said. But this should implement the original intent in a
more accurate way.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-23 00:48:21 +00:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2018-08-23 00:49:56 +00:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
trailer: fix comment/cut-line regression with opts->no_divider
Commit 97e9d0b78a (trailer: find the end of the log message, 2023-10-20)
combined two code paths for finding the end of the log message. For the
"no_divider" case, we used to use find_trailer_end(), and that has now
been rolled into find_end_of_log_message(). But there's a regression;
that function returns early when no_divider is set, returning the whole
string.
That's not how find_trailer_end() behaved. Although it did skip the
"---" processing (which is what "no_divider" is meant to do), we should
still respect ignored_log_message_bytes(), which covers things like
comments, "commit -v" cut lines, and so on.
The bug is actually in the interpret-trailers command, but the obvious
way to experience it is by running "commit -v" with a "--trailer"
option. The new trailer will be added at the end of the verbose diff,
rather than before it (and consequently will be ignored entirely, since
everything after the diff's intro scissors line is thrown away).
I've added two tests here: one for interpret-trailers directly, which
shows the bug via the parsing routines, and one for "commit -v".
The fix itself is pretty simple: instead of returning early, no_divider
just skips the "---" handling but still calls ignored_log_message_bytes().
Reported-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-02-20 01:09:36 +00:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
wt-status: don't find scissors line beyond buf len
If
(a) There is a "---" divider in a commit message,
(b) At some point beyond that divider, there is a cut-line (that is,
"# ------------------------ >8 ------------------------") in the
commit message,
(c) the user does not explicitly set the "no-divider" option,
then "git interpret-trailers" will hang indefinitively.
This is because when (a) is true, find_end_of_log_message() will invoke
ignored_log_message_bytes() with a len that is intended to make it
ignore the part of the commit message beyond the divider. However,
ignored_log_message_bytes() calls wt_status_locate_end(), and that
function ignores the length restriction when it tries to locate the cut
line. If it manages to find one, the returned cutoff value is greater
than len. At this point, ignored_log_message_bytes() goes into an
infinite loop, because it won't advance the string parsing beyond len,
but the exit condition expects to reach cutoff.
Make wt_status_locate_end() honor the length parameter passed in, to
fix this issue.
In general, if wt_status_locate_end() is given a piece of the memory
that lacks NUL at all, strstr() may continue across page boundaries
and run into an unmapped page. For our current callers, this is not
a problem, as all of them except one uses a memory owned by a strbuf
(which guarantees an implicit NUL-termination after its payload),
and the one exception in trailer.c:find_end_of_log_message() uses
strlen() to compute the length before calling this function.
Signed-off-by: Florian Schmidt <flosch@nutanix.com>
Reviewed-by: Jonathan Davies <jonathan.davies@nutanix.com>
[jc: tweaked the commit log message and the implementation a bit]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-03-07 18:37:38 +00:00
|
|
|
test_expect_success 'handling of --- lines in conjunction with cut-lines' '
|
|
|
|
echo "my-trailer: here" >expected &&
|
|
|
|
|
|
|
|
git interpret-trailers --parse >actual <<-\EOF &&
|
|
|
|
subject
|
|
|
|
|
|
|
|
my-trailer: here
|
|
|
|
---
|
|
|
|
# ------------------------ >8 ------------------------
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-10-13 18:16:30 +00:00
|
|
|
test_done
|