From: "Linus Arver via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Christian Couder <chriscool@tuxfamily.org>,
Linus Arver <linusa@google.com>, Linus Arver <linusa@google.com>
Subject: [PATCH v2 03/13] trailer: add tests to check defaulting behavior with --no-* flags
Date: Thu, 10 Aug 2023 21:17:53 +0000 [thread overview]
Message-ID: <4b5c458ef436c2d208e6d6d0a1f99c65e9a11125.1691702283.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1564.v2.git.1691702283.gitgitgadget@gmail.com>
From: Linus Arver <linusa@google.com>
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>
---
Documentation/git-interpret-trailers.txt | 14 ++-
t/t7513-interpret-trailers.sh | 130 +++++++++++++++++++++++
2 files changed, 140 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt
index 55d89614661..91a4dbc9a72 100644
--- a/Documentation/git-interpret-trailers.txt
+++ b/Documentation/git-interpret-trailers.txt
@@ -114,8 +114,10 @@ OPTIONS
Specify where all new trailers will be added. A setting
provided with '--where' overrides all configuration variables
and applies to all '--trailer' options until the next occurrence of
- '--where' or '--no-where'. Possible values are `after`, `before`,
- `end` or `start`.
+ '--where' or '--no-where'. Upon encountering '--no-where', clear the
+ effect of any previous use of '--where', such that the relevant configuration
+ variables are no longer overridden. Possible values are `after`,
+ `before`, `end` or `start`.
--if-exists <action>::
--no-if-exists::
@@ -123,7 +125,9 @@ OPTIONS
least one trailer with the same <token> in the input. A setting
provided with '--if-exists' overrides all configuration variables
and applies to all '--trailer' options until the next occurrence of
- '--if-exists' or '--no-if-exists'. Possible actions are `addIfDifferent`,
+ '--if-exists' or '--no-if-exists'. Upon encountering '--no-if-exists, clear the
+ effect of any previous use of '--if-exists, such that the relevant configuration
+ variables are no longer overridden. Possible actions are `addIfDifferent`,
`addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
--if-missing <action>::
@@ -132,7 +136,9 @@ OPTIONS
trailer with the same <token> in the input. A setting
provided with '--if-missing' overrides all configuration variables
and applies to all '--trailer' options until the next occurrence of
- '--if-missing' or '--no-if-missing'. Possible actions are `doNothing`
+ '--if-missing' or '--no-if-missing'. Upon encountering '--no-if-missing,
+ clear the effect of any previous use of '--if-missing, such that the relevant
+ configuration variables are no longer overridden. Possible actions are `doNothing`
or `add`.
--only-trailers::
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index ed0fc04bd95..832aff06167 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -812,6 +812,53 @@ test_expect_success 'using "--where after" with "--no-where"' '
test_cmp expected actual
'
+# 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
+'
+
test_expect_success 'using "where = after"' '
test_config trailer.ack.key "Acked-by= " &&
test_config trailer.ack.where "after" &&
@@ -1176,6 +1223,56 @@ test_expect_success 'overriding configuration with "--if-exists replace"' '
test_cmp expected actual
'
+# "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
+'
+
test_expect_success 'using "ifExists = replace"' '
test_config trailer.fix.key "Fixes: " &&
test_config trailer.fix.ifExists "replace" &&
@@ -1425,6 +1522,39 @@ test_expect_success 'using "ifMissing = doNothing"' '
test_cmp expected actual
'
+# 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
+'
+
test_expect_success 'default "where" is now "after"' '
git config trailer.where "after" &&
test_config trailer.ack.ifExists "add" &&
--
gitgitgadget
next prev parent reply other threads:[~2023-08-10 21:18 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-05 4:45 [PATCH 0/5] Fixes to trailer test script, help text, and documentation Linus Arver via GitGitGadget
2023-08-05 4:45 ` [PATCH 1/5] trailer tests: make test cases self-contained Linus Arver via GitGitGadget
2023-08-07 5:50 ` Linus Arver
2023-08-05 4:45 ` [PATCH 2/5] trailer test description: this tests --where=after, not --where=before Linus Arver via GitGitGadget
2023-08-05 4:45 ` [PATCH 3/5] trailer: add tests to check defaulting behavior with --no-* flags Linus Arver via GitGitGadget
2023-08-07 1:13 ` Junio C Hamano
2023-08-07 5:28 ` Linus Arver
2023-08-07 5:37 ` Linus Arver
2023-08-07 6:35 ` Linus Arver
2023-08-07 15:53 ` Junio C Hamano
2023-08-05 4:45 ` [PATCH 4/5] trailer: trailer location is a place, not an action Linus Arver via GitGitGadget
2023-08-05 4:45 ` [PATCH 5/5] trailer --no-divider help: describe usual "---" meaning Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 00/13] Fixes to trailer test script, help text, and documentation Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 01/13] trailer tests: make test cases self-contained Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 02/13] trailer test description: this tests --where=after, not --where=before Linus Arver via GitGitGadget
2023-08-10 21:17 ` Linus Arver via GitGitGadget [this message]
2023-08-10 21:17 ` [PATCH v2 04/13] trailer doc: narrow down scope of --where and related flags Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 05/13] trailer: trailer location is a place, not an action Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 06/13] trailer --no-divider help: describe usual "---" meaning Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 07/13] trailer --parse help: expose aliased options Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 08/13] trailer --only-input: prefer "configuration variables" over "rules" Linus Arver via GitGitGadget
2023-08-10 21:17 ` [PATCH v2 09/13] trailer --parse docs: add explanation for its usefulness Linus Arver via GitGitGadget
2023-08-10 21:18 ` [PATCH v2 10/13] trailer --unfold help: prefer "reformat" over "join" Linus Arver via GitGitGadget
2023-08-10 21:18 ` [PATCH v2 11/13] trailer doc: emphasize the effect of configuration variables Linus Arver via GitGitGadget
2023-08-10 21:18 ` [PATCH v2 12/13] trailer doc: separator within key suppresses default separator Linus Arver via GitGitGadget
2023-08-10 21:18 ` [PATCH v2 13/13] trailer doc: <token> is a <key> or <keyAlias>, not both Linus Arver via GitGitGadget
2023-08-11 1:41 ` [PATCH v2 00/13] Fixes to trailer test script, help text, and documentation Junio C Hamano
2023-08-11 17:38 ` Linus Arver
2023-09-07 22:19 ` [PATCH v3 " Linus Arver via GitGitGadget
2023-09-07 22:19 ` [PATCH v3 01/13] trailer tests: make test cases self-contained Linus Arver via GitGitGadget
2023-09-07 22:19 ` [PATCH v3 02/13] trailer test description: this tests --where=after, not --where=before Linus Arver via GitGitGadget
2023-09-07 22:19 ` [PATCH v3 03/13] trailer: add tests to check defaulting behavior with --no-* flags Linus Arver via GitGitGadget
2023-09-08 21:52 ` Junio C Hamano
2023-09-07 22:20 ` [PATCH v3 04/13] trailer doc: narrow down scope of --where and related flags Linus Arver via GitGitGadget
2023-09-07 22:20 ` [PATCH v3 05/13] trailer: trailer location is a place, not an action Linus Arver via GitGitGadget
2023-09-19 22:13 ` Jonathan Tan
2023-09-07 22:20 ` [PATCH v3 06/13] trailer --no-divider help: describe usual "---" meaning Linus Arver via GitGitGadget
2023-09-08 21:53 ` Junio C Hamano
2023-09-07 22:20 ` [PATCH v3 07/13] trailer --parse help: expose aliased options Linus Arver via GitGitGadget
2023-09-19 22:16 ` Jonathan Tan
2023-09-07 22:20 ` [PATCH v3 08/13] trailer --only-input: prefer "configuration variables" over "rules" Linus Arver via GitGitGadget
2023-09-07 22:20 ` [PATCH v3 09/13] trailer --parse docs: add explanation for its usefulness Linus Arver via GitGitGadget
2023-09-08 21:57 ` Junio C Hamano
2023-09-07 22:20 ` [PATCH v3 10/13] trailer --unfold help: prefer "reformat" over "join" Linus Arver via GitGitGadget
2023-09-07 22:20 ` [PATCH v3 11/13] trailer doc: emphasize the effect of configuration variables Linus Arver via GitGitGadget
2023-09-07 22:20 ` [PATCH v3 12/13] trailer doc: separator within key suppresses default separator Linus Arver via GitGitGadget
2023-09-07 22:20 ` [PATCH v3 13/13] trailer doc: <token> is a <key> or <keyAlias>, not both Linus Arver via GitGitGadget
2023-09-19 22:59 ` Jonathan Tan
2023-09-20 6:48 ` Linus Arver
2023-09-20 15:01 ` Junio C Hamano
2023-09-22 18:26 ` Linus Arver
2023-11-10 6:33 ` Teng Long
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4b5c458ef436c2d208e6d6d0a1f99c65e9a11125.1691702283.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=linusa@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).