Skip to content

Commit 06ce791

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2aa9425 commit 06ce791

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

Documentation/git-mktag.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ SYNOPSIS
1111
[verse]
1212
'git mktag'
1313

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+
1422
DESCRIPTION
1523
-----------
1624

builtin/mktag.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static char const * const builtin_mktag_usage[] = {
1010
N_("git mktag"),
1111
NULL
1212
};
13+
static int option_strict = 1;
1314

1415
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
1516

@@ -25,6 +26,12 @@ static int mktag_fsck_error_func(struct fsck_options *o,
2526
{
2627
switch (msg_type) {
2728
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 */
2835
case FSCK_ERROR:
2936
/*
3037
* 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)
6774
int cmd_mktag(int argc, const char **argv, const char *prefix)
6875
{
6976
static struct option builtin_mktag_options[] = {
77+
OPT_BOOL(0, "strict", &option_strict,
78+
N_("enable more strict checking")),
7079
OPT_END(),
7180
};
7281
struct strbuf buf = STRBUF_INIT;

t/t3800-mktag.sh

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ test_description='git mktag: tag object verify test'
1212
# given in the expect.pat file.
1313

1414
check_verify_failure () {
15-
expect="$2"
16-
test_expect_success "$1" '
15+
test_expect_success "$1" "
1716
test_must_fail env GIT_TEST_GETTEXT_POISON=false \
1817
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+
"
2126
}
2227

2328
test_expect_mktag_success() {
@@ -65,7 +70,7 @@ too short for a tag
6570
EOF
6671

6772
check_verify_failure 'Tag object length check' \
68-
'^error:.* missingObject:'
73+
'^error:.* missingObject:' 'strict'
6974

7075
############################################################
7176
# 2. object line label check
@@ -240,7 +245,7 @@ tagger . <> 0 +0000
240245
EOF
241246

242247
check_verify_failure 'verify tag-name check' \
243-
'^error:.* badTagName:'
248+
'^error:.* badTagName:' '--no-strict'
244249

245250
############################################################
246251
# 11. tagger line label check #1
@@ -254,7 +259,7 @@ This is filler
254259
EOF
255260

256261
check_verify_failure '"tagger" line label check #1' \
257-
'^error:.* missingTaggerEntry:'
262+
'^error:.* missingTaggerEntry:' '--no-strict'
258263

259264
############################################################
260265
# 12. tagger line label check #2
@@ -269,7 +274,7 @@ This is filler
269274
EOF
270275

271276
check_verify_failure '"tagger" line label check #2' \
272-
'^error:.* missingTaggerEntry:'
277+
'^error:.* missingTaggerEntry:' '--no-strict'
273278

274279
############################################################
275280
# 13. allow missing tag author name like fsck
@@ -298,7 +303,7 @@ tagger T A Gger <
298303
EOF
299304

300305
check_verify_failure 'disallow malformed tagger' \
301-
'^error:.* badEmail:'
306+
'^error:.* badEmail:' '--no-strict'
302307

303308
############################################################
304309
# 15. allow empty tag email
@@ -422,13 +427,21 @@ this line should not be here
422427
EOF
423428

424429
check_verify_failure 'detect invalid header entry' \
425-
'^error:.* extraHeaderEntry:'
430+
'^error:.* extraHeaderEntry:' '--no-strict'
426431

427432
test_expect_success 'invalid header entry config & fsck' '
428433
test_must_fail git mktag <tag.sig &&
434+
git mktag --no-strict <tag.sig &&
435+
429436
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+
430439
test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
440+
git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
441+
431442
git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
443+
git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
444+
432445
git fsck &&
433446
env GIT_TEST_GETTEXT_POISON=false \
434447
git -c fsck.extraHeaderEntry=warn fsck 2>err &&

0 commit comments

Comments
 (0)