@@ -812,6 +812,53 @@ test_expect_success 'using "--where after" with "--no-where"' '
812
812
test_cmp expected actual
813
813
'
814
814
815
+ # Check whether using "--no-where" clears out only the "--where after", such
816
+ # that we still use the configuration in trailer.where (which is different from
817
+ # the hardcoded default (in WHERE_END) assuming the absence of .gitconfig).
818
+ # Here, the "start" setting of trailer.where is respected, so the new "Acked-by"
819
+ # and "Bug" trailers are placed at the beginning, and not at the end which is
820
+ # the harcoded default.
821
+ test_expect_success ' using "--where after" with "--no-where" defaults to configuration' '
822
+ test_config trailer.ack.key "Acked-by= " &&
823
+ test_config trailer.bug.key "Bug #" &&
824
+ test_config trailer.separators ":=#" &&
825
+ test_config trailer.where "start" &&
826
+ cat complex_message_body >expected &&
827
+ sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
828
+ Bug #42
829
+ Acked-by= Peff
830
+ Fixes: Z
831
+ Acked-by= Z
832
+ Reviewed-by: Z
833
+ Signed-off-by: Z
834
+ EOF
835
+ git interpret-trailers --where after --no-where --trailer "ack: Peff" \
836
+ --trailer "bug: 42" complex_message >actual &&
837
+ test_cmp expected actual
838
+ '
839
+
840
+ # The "--where after" will only get respected for the trailer that came
841
+ # immediately after it. For the next trailer (Bug #42), we default to using the
842
+ # hardcoded WHERE_END because we don't have any "trailer.where" or
843
+ # "trailer.bug.where" configured.
844
+ test_expect_success ' using "--no-where" defaults to harcoded default if nothing configured' '
845
+ test_config trailer.ack.key "Acked-by= " &&
846
+ test_config trailer.bug.key "Bug #" &&
847
+ test_config trailer.separators ":=#" &&
848
+ cat complex_message_body >expected &&
849
+ sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
850
+ Fixes: Z
851
+ Acked-by= Z
852
+ Acked-by= Peff
853
+ Reviewed-by: Z
854
+ Signed-off-by: Z
855
+ Bug #42
856
+ EOF
857
+ git interpret-trailers --where after --trailer "ack: Peff" --no-where \
858
+ --trailer "bug: 42" complex_message >actual &&
859
+ test_cmp expected actual
860
+ '
861
+
815
862
test_expect_success ' using "where = after"' '
816
863
test_config trailer.ack.key "Acked-by= " &&
817
864
test_config trailer.ack.where "after" &&
@@ -1176,6 +1223,56 @@ test_expect_success 'overriding configuration with "--if-exists replace"' '
1176
1223
test_cmp expected actual
1177
1224
'
1178
1225
1226
+ # "trailer.ifexists" is set to "doNothing", so using "--no-if-exists" defaults
1227
+ # to this "doNothing" behavior. So the "Fixes: 53" trailer does not get added.
1228
+ test_expect_success ' using "--if-exists replace" with "--no-if-exists" defaults to configuration' '
1229
+ test_config trailer.ifexists "doNothing" &&
1230
+ cat complex_message_body >expected &&
1231
+ sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1232
+ Fixes: Z
1233
+ Acked-by: Z
1234
+ Reviewed-by: Z
1235
+ Signed-off-by: Z
1236
+ EOF
1237
+ git interpret-trailers --if-exists replace --no-if-exists --trailer "Fixes: 53" \
1238
+ <complex_message >actual &&
1239
+ test_cmp expected actual
1240
+ '
1241
+
1242
+ # No "ifexists" configuration is set, so using "--no-if-exists" makes it default
1243
+ # to addIfDifferentNeighbor. Because we do have a different neighbor "Fixes: 53"
1244
+ # (because it got added by overriding with "--if-exists replace" earlier in the
1245
+ # arguments list), we add "Signed-off-by: addme".
1246
+ test_expect_success ' using "--no-if-exists" defaults to hardcoded default if nothing configured' '
1247
+ cat complex_message_body >expected &&
1248
+ sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1249
+ Acked-by: Z
1250
+ Reviewed-by: Z
1251
+ Signed-off-by: Z
1252
+ Fixes: 53
1253
+ Signed-off-by: addme
1254
+ EOF
1255
+ git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
1256
+ --trailer "Signed-off-by: addme" <complex_message >actual &&
1257
+ test_cmp expected actual
1258
+ '
1259
+
1260
+ # The second "Fixes: 53" trailer is discarded, because the "--no-if-exists" here
1261
+ # makes us default to addIfDifferentNeighbor, and we already added the "Fixes:
1262
+ # 53" trailer earlier in the argument list.
1263
+ test_expect_success ' using "--no-if-exists" defaults to hardcoded default if nothing configured (no addition)' '
1264
+ cat complex_message_body >expected &&
1265
+ sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1266
+ Acked-by: Z
1267
+ Reviewed-by: Z
1268
+ Signed-off-by: Z
1269
+ Fixes: 53
1270
+ EOF
1271
+ git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
1272
+ --trailer "Fixes: 53" <complex_message >actual &&
1273
+ test_cmp expected actual
1274
+ '
1275
+
1179
1276
test_expect_success ' using "ifExists = replace"' '
1180
1277
test_config trailer.fix.key "Fixes: " &&
1181
1278
test_config trailer.fix.ifExists "replace" &&
@@ -1425,6 +1522,39 @@ test_expect_success 'using "ifMissing = doNothing"' '
1425
1522
test_cmp expected actual
1426
1523
'
1427
1524
1525
+ # Ignore the "IgnoredTrailer" because of "--if-missing doNothing", but also
1526
+ # ignore the "StillIgnoredTrailer" because we set "trailer.ifMissing" to
1527
+ # "doNothing" in configuration.
1528
+ test_expect_success ' using "--no-if-missing" defaults to configuration' '
1529
+ test_config trailer.ifMissing "doNothing" &&
1530
+ cat complex_message_body >expected &&
1531
+ sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1532
+ Fixes: Z
1533
+ Acked-by: Z
1534
+ Reviewed-by: Z
1535
+ Signed-off-by: Z
1536
+ EOF
1537
+ git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
1538
+ --trailer "StillIgnoredTrailer: ignoreme" <complex_message >actual &&
1539
+ test_cmp expected actual
1540
+ '
1541
+
1542
+ # Add the "AddedTrailer" because the "--no-if-missing" clears the "--if-missing
1543
+ # doNothing" from earlier in the argument list.
1544
+ test_expect_success ' using "--no-if-missing" defaults to hardcoded default if nothing configured' '
1545
+ cat complex_message_body >expected &&
1546
+ sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1547
+ Fixes: Z
1548
+ Acked-by: Z
1549
+ Reviewed-by: Z
1550
+ Signed-off-by: Z
1551
+ AddedTrailer: addme
1552
+ EOF
1553
+ git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
1554
+ --trailer "AddedTrailer: addme" <complex_message >actual &&
1555
+ test_cmp expected actual
1556
+ '
1557
+
1428
1558
test_expect_success ' default "where" is now "after"' '
1429
1559
git config trailer.where "after" &&
1430
1560
test_config trailer.ack.ifExists "add" &&
0 commit comments