Imported Upstream version 2.25.0
[platform/upstream/git.git] / t / t7513-interpret-trailers.sh
index 0c6f91c..6602790 100755 (executable)
@@ -538,33 +538,50 @@ test_expect_success 'with 2 files arguments' '
        test_cmp expected actual
 '
 
-test_expect_success 'with message that has comments' '
-       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
-
-       EOF
-       cat basic_patch >>message_with_comments &&
-       cat basic_message >expected &&
-       cat >>expected <<-\EOF &&
-               # comment
-
-               Reviewed-by: Johan
-               Cc: Peff
-               # last comment
-
-       EOF
-       cat basic_patch >>expected &&
-       git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
-       test_cmp expected actual
-'
+# 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
 
 test_expect_success 'with message that has an old style conflict block' '
        cat basic_message >message_with_comments &&
@@ -681,6 +698,36 @@ test_expect_success 'using "where = before"' '
        test_cmp expected actual
 '
 
+test_expect_success 'overriding configuration with "--where after"' '
+       git config trailer.ack.where "before" &&
+       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
+'
+
+test_expect_success 'using "where = before" with "--no-where"' '
+       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
+'
+
 test_expect_success 'using "where = after"' '
        git config trailer.ack.where "after" &&
        cat complex_message_body >expected &&
@@ -947,6 +994,23 @@ test_expect_success 'using "ifExists = add" with "where = after"' '
        test_cmp expected actual
 '
 
+test_expect_success 'overriding configuration with "--if-exists replace"' '
+       git config trailer.fix.key "Fixes: " &&
+       git config trailer.fix.ifExists "add" &&
+       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
+'
+
 test_expect_success 'using "ifExists = replace"' '
        git config trailer.fix.key "Fixes: " &&
        git config trailer.fix.ifExists "replace" &&
@@ -1026,6 +1090,25 @@ test_expect_success 'the default is "ifMissing = add"' '
        test_cmp expected actual
 '
 
+test_expect_success 'overriding configuration with "--if-missing doNothing"' '
+       git config trailer.ifmissing "add" &&
+       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
+'
+
 test_expect_success 'when default "ifMissing" is "doNothing"' '
        git config trailer.ifmissing "doNothing" &&
        cat complex_message_body >expected &&
@@ -1151,7 +1234,7 @@ test_expect_success 'with simple command' '
        test_cmp expected actual
 '
 
-test_expect_success 'with command using commiter information' '
+test_expect_success 'with command using committer information' '
        git config trailer.sign.ifExists "addIfDifferent" &&
        git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
        cat complex_message_body >expected &&
@@ -1275,4 +1358,122 @@ test_expect_success 'with cut line' '
        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_expect_success 'handling of --- lines in input' '
+       echo "real-trailer: just right" >expected &&
+
+       git interpret-trailers --parse >actual <<-\EOF &&
+       subject
+
+       body
+
+       not-a-trailer: too soon
+       ------ this is just a line in the commit message with a bunch of
+       ------ dashes; it does not have any syntactic meaning.
+
+       real-trailer: just right
+       ---
+       below the dashed line may be a patch, etc.
+
+       not-a-trailer: too late
+       EOF
+
+       test_cmp expected actual
+'
+
+test_expect_success 'suppress --- handling' '
+       echo "real-trailer: just right" >expected &&
+
+       git interpret-trailers --parse --no-divider >actual <<-\EOF &&
+       subject
+
+       This commit message has a "---" in it, but because we tell
+       interpret-trailers not to respect that, it has no effect.
+
+       not-a-trailer: too soon
+       ---
+
+       This is still the commit message body.
+
+       real-trailer: just right
+       EOF
+
+       test_cmp expected actual
+'
+
 test_done