trailer: add tests to check defaulting behavior with --no-* flags
While the "--no-where" flag is tested, the "--no-if-exists" and "--no-if-missing" flags are not, so add tests for them. But also add tests for all "--no-*" flags to check their effects, both when (1) there are relevant configuration variables set, and (2) they are not set. Signed-off-by: Linus Arver <linusa@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Arver committed
Sep 7, 2023 at 22:19 UTC
73574f21b4f638cdfef7c9766ddf0aff4990ca8f
2 files changed
+140
-4
Documentation/git-interpret-trailers.txt
+10
-4
@@ -114,8 +114,10 @@ OPTIONS
114
Specify where all new trailers will be added. A setting
115
provided with '--where' overrides all configuration variables
116
and applies to all '--trailer' options until the next occurrence of
117
- '--where' or '--no-where'. Possible values are `after`, `before`,
118
- `end` or `start`.
117
+ '--where' or '--no-where'. Upon encountering '--no-where', clear the
118
+ effect of any previous use of '--where', such that the relevant configuration
119
+ variables are no longer overridden. Possible values are `after`,
120
+ `before`, `end` or `start`.
121
122
--if-exists <action>::
123
--no-if-exists::
@@ -123,7 +125,9 @@ OPTIONS
125
least one trailer with the same <token> in the input. A setting
126
provided with '--if-exists' overrides all configuration variables
127
and applies to all '--trailer' options until the next occurrence of
126
- '--if-exists' or '--no-if-exists'. Possible actions are `addIfDifferent`,
128
+ '--if-exists' or '--no-if-exists'. Upon encountering '--no-if-exists, clear the
129
+ effect of any previous use of '--if-exists, such that the relevant configuration
130
+ variables are no longer overridden. Possible actions are `addIfDifferent`,
131
`addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
132
133
--if-missing <action>::
@@ -132,7 +136,9 @@ OPTIONS
136
trailer with the same <token> in the input. A setting
137
provided with '--if-missing' overrides all configuration variables
138
and applies to all '--trailer' options until the next occurrence of
135
- '--if-missing' or '--no-if-missing'. Possible actions are `doNothing`
139
+ '--if-missing' or '--no-if-missing'. Upon encountering '--no-if-missing,
140
+ clear the effect of any previous use of '--if-missing, such that the relevant
141
+ configuration variables are no longer overridden. Possible actions are `doNothing`
142
or `add`.
143
144
--only-trailers::
t/t7513-interpret-trailers.sh
+130
@@ -812,6 +812,53 @@ test_expect_success 'using "--where after" with "--no-where"' '
812
test_cmp expected actual
813
'
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
+
862
test_expect_success 'using "where = after"' '
863
test_config trailer.ack.key "Acked-by= " &&
864
test_config trailer.ack.where "after" &&
@@ -1176,6 +1223,56 @@ test_expect_success 'overriding configuration with "--if-exists replace"' '
1223
test_cmp expected actual
1224
'
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
+
1276
test_expect_success 'using "ifExists = replace"' '
1277
test_config trailer.fix.key "Fixes: " &&
1278
test_config trailer.fix.ifExists "replace" &&
@@ -1425,6 +1522,39 @@ test_expect_success 'using "ifMissing = doNothing"' '
1522
test_cmp expected actual
1523
'
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
+
1558
test_expect_success 'default "where" is now "after"' '
1559
git config trailer.where "after" &&
1560
test_config trailer.ack.ifExists "add" &&