mktag: add a --[no-]strict option

Now that mktag has been migrated to use the fsck machinery to check its input, it makes sense to teach it to run in the equivalent of "git fsck"'s default mode. For cases where mktag is used to (re)create a tag object using data from an existing and malformed tag object, the validation may optionally have to be loosened. Teach the command to take the "--[no-]strict" option to do so. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 6, 2021 at 12:47 UTC 06ce79152be8dab44b63faf4486d5c5c171434af
3 files changed +40 -10
Documentation/git-mktag.txt
+8
@@ -11,6 +11,14 @@ SYNOPSIS
11 [verse]
12 'git mktag'
13
14 +OPTIONS
15 +-------
16 +
17 +--strict::
18 + By default mktag turns on the equivalent of
19 + linkgit:git-fsck[1] `--strict` mode. Use `--no-strict` to
20 + disable it.
21 +
22 DESCRIPTION
23 -----------
24
builtin/mktag.c
+9
@@ -10,6 +10,7 @@ static char const * const builtin_mktag_usage[] = {
10 N_("git mktag"),
11 NULL
12 };
13 +static int option_strict = 1;
14
15 static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
16
@@ -25,6 +26,12 @@ static int mktag_fsck_error_func(struct fsck_options *o,
26 {
27 switch (msg_type) {
28 case FSCK_WARN:
29 + if (!option_strict) {
30 + fprintf_ln(stderr, _("warning: tag input does not pass fsck: %s"), message);
31 + return 0;
32 +
33 + }
34 + /* fallthrough */
35 case FSCK_ERROR:
36 /*
37 * We treat both warnings and errors as errors, things
@@ -67,6 +74,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
74 int cmd_mktag(int argc, const char **argv, const char *prefix)
75 {
76 static struct option builtin_mktag_options[] = {
77 + OPT_BOOL(0, "strict", &option_strict,
78 + N_("enable more strict checking")),
79 OPT_END(),
80 };
81 struct strbuf buf = STRBUF_INIT;
t/t3800-mktag.sh
+23 -10
@@ -12,12 +12,17 @@ test_description='git mktag: tag object verify test'
12 # given in the expect.pat file.
13
14 check_verify_failure () {
15 - expect="$2"
16 - test_expect_success "$1" '
15 + test_expect_success "$1" "
16 test_must_fail env GIT_TEST_GETTEXT_POISON=false \
17 git mktag <tag.sig 2>message &&
19 - grep "$expect" message
20 - '
18 + grep '$2' message &&
19 + if test '$3' != '--no-strict'
20 + then
21 + test_must_fail env GIT_TEST_GETTEXT_POISON=false \
22 + git mktag --no-strict <tag.sig 2>message.no-strict &&
23 + grep '$2' message.no-strict
24 + fi
25 + "
26 }
27
28 test_expect_mktag_success() {
@@ -65,7 +70,7 @@ too short for a tag
70 EOF
71
72 check_verify_failure 'Tag object length check' \
68 - '^error:.* missingObject:'
73 + '^error:.* missingObject:' 'strict'
74
75 ############################################################
76 # 2. object line label check
@@ -240,7 +245,7 @@ tagger . <> 0 +0000
245 EOF
246
247 check_verify_failure 'verify tag-name check' \
243 - '^error:.* badTagName:'
248 + '^error:.* badTagName:' '--no-strict'
249
250 ############################################################
251 # 11. tagger line label check #1
@@ -254,7 +259,7 @@ This is filler
259 EOF
260
261 check_verify_failure '"tagger" line label check #1' \
257 - '^error:.* missingTaggerEntry:'
262 + '^error:.* missingTaggerEntry:' '--no-strict'
263
264 ############################################################
265 # 12. tagger line label check #2
@@ -269,7 +274,7 @@ This is filler
274 EOF
275
276 check_verify_failure '"tagger" line label check #2' \
272 - '^error:.* missingTaggerEntry:'
277 + '^error:.* missingTaggerEntry:' '--no-strict'
278
279 ############################################################
280 # 13. allow missing tag author name like fsck
@@ -298,7 +303,7 @@ tagger T A Gger <
303 EOF
304
305 check_verify_failure 'disallow malformed tagger' \
301 - '^error:.* badEmail:'
306 + '^error:.* badEmail:' '--no-strict'
307
308 ############################################################
309 # 15. allow empty tag email
@@ -422,13 +427,21 @@ this line should not be here
427 EOF
428
429 check_verify_failure 'detect invalid header entry' \
425 - '^error:.* extraHeaderEntry:'
430 + '^error:.* extraHeaderEntry:' '--no-strict'
431
432 test_expect_success 'invalid header entry config & fsck' '
433 test_must_fail git mktag <tag.sig &&
434 + git mktag --no-strict <tag.sig &&
435 +
436 test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
437 + test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig &&
438 +
439 test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
440 + git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
441 +
442 git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
443 + git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
444 +
445 git fsck &&
446 env GIT_TEST_GETTEXT_POISON=false \
447 git -c fsck.extraHeaderEntry=warn fsck 2>err &&