Skip to content

Commit acfc013

Browse files
avargitster
authored andcommitted
mktag: allow turning off fsck.extraHeaderEntry
In earlier commits mktag learned to use the fsck machinery, at which point we needed to add fsck.extraHeaderEntry so it could be as strict about extra headers as it's been ever since it was implemented. But it's not nice to need to switch away from "mktag" to "hash-object" + manual "fsck" just because you'd like to have an extra header. So let's support turning it off by getting "fsck.*" variables from the config. Pedantically speaking it's still not possible to make "mktag" behave just like "hash-object -t tag" does, since we're unconditionally going to check the referenced object in verify_object_in_tag(), which is our own check, and not one that exists in fsck.c. But the spirit of "this works like fsck" is preserved, in that if you created such a tag with "hash-object" and did a full "fsck" on the repository it would also error out about that invalid object, it just wouldn't emit the same message as fsck does. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f3299f commit acfc013

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Documentation/git-mktag.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ would run by default in that all `fsck.<msg-id>` messages are promoted
3232
from warnings to errors (so e.g. a missing "tagger" line is an error).
3333

3434
Extra headers in the object are also an error under mktag, but ignored
35-
by linkgit:git-fsck[1]
35+
by linkgit:git-fsck[1]. This extra check can be turned off by setting
36+
the appropriate `fsck.<msg-id>` varible:
37+
38+
git -c fsck.extraHeaderEntry=ignore mktag <my-tag-with-headers
3639

3740
Tag Format
3841
----------

builtin/mktag.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
#include "replace-object.h"
44
#include "object-store.h"
55
#include "fsck.h"
6+
#include "config.h"
7+
8+
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
9+
10+
static int mktag_config(const char *var, const char *value, void *cb)
11+
{
12+
return fsck_config_internal(var, value, cb, &fsck_options);
13+
}
614

715
static int mktag_fsck_error_func(struct fsck_options *o,
816
const struct object_id *oid,
@@ -53,7 +61,6 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
5361
int cmd_mktag(int argc, const char **argv, const char *prefix)
5462
{
5563
struct strbuf buf = STRBUF_INIT;
56-
struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
5764
struct object_id tagged_oid;
5865
int tagged_type;
5966
struct object_id result;
@@ -66,6 +73,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
6673

6774
fsck_options.error_func = mktag_fsck_error_func;
6875
fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
76+
/* config might set fsck.extraHeaderEntry=* again */
77+
git_config(mktag_config, NULL);
6978
if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
7079
&tagged_oid, &tagged_type))
7180
die("tag on stdin did not pass our strict fsck check");

t/t3800-mktag.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,20 @@ EOF
412412
check_verify_failure 'detect invalid header entry' \
413413
'^error:.* extraHeaderEntry:'
414414

415+
test_expect_success 'invalid header entry config & fsck' '
416+
test_must_fail git mktag <tag.sig &&
417+
test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
418+
test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
419+
git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
420+
git fsck &&
421+
env GIT_TEST_GETTEXT_POISON=false \
422+
git -c fsck.extraHeaderEntry=warn fsck 2>err &&
423+
grep "warning .*extraHeaderEntry:" err &&
424+
test_must_fail env GIT_TEST_GETTEXT_POISON=false \
425+
git -c fsck.extraHeaderEntry=error 2>err fsck &&
426+
grep "error .* extraHeaderEntry:" err
427+
'
428+
415429
cat >tag.sig <<EOF
416430
object $head
417431
type commit

0 commit comments

Comments
 (0)