t4205: refactor %(trailers) tests
[gitweb.git] / t / t7513-interpret-trailers.sh
index aee785cffa8d656fa52e6b893921153faf748fe9..baf2feba9858de5591bfd1f7c3ba44bd356dd8ea 100755 (executable)
@@ -126,6 +126,305 @@ test_expect_success 'with multiline title in the message' '
        test_cmp expected actual
 '
 
+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
+'
+
+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
+'
+
+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
+'
+
 test_expect_success 'with config setup' '
        git config trailer.ack.key "Acked-by: " &&
        cat >expected <<-\EOF &&
@@ -959,4 +1258,97 @@ test_expect_success 'with no command and no key' '
        test_cmp expected actual
 '
 
+test_expect_success 'with cut line' '
+       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
+'
+
+test_expect_success 'only trailers' '
+       git config trailer.sign.command "echo config-value" &&
+       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' '
+       git config trailer.sign.command "echo config-value" &&
+       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
+'
+
+test_expect_success 'only input' '
+       git config trailer.sign.command "echo config-value" &&
+       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
+'
+
+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
+'
+
 test_done