fsck: silence stderr when parsing .gitmodules

If there's a parsing error we'll already report it via the usual fsck report() function (or not, if the user has asked to skip this object or warning type). The error message from the config parser just adds confusion. Let's suppress it. Note that we didn't test this case at all, so I've added coverage in t7415. We may end up toning down or removing this fsck check in the future. So take this test as checking what happens now with a focus on stderr, and not any ironclad guarantee that we must detect and report parse failures in the future. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 28, 2018 at 18:06 UTC de6bd9e3eab3077d49d8486f990ed2b80af7c2c9
2 files changed +18 -1
fsck.c
+3 -1
@@ -992,6 +992,7 @@ static int fsck_blob(struct blob *blob, const char *buf,
992 unsigned long size, struct fsck_options *options)
993 {
994 struct fsck_gitmodules_data data;
995 + struct config_options config_opts = { 0 };
996
997 if (!oidset_contains(&gitmodules_found, &blob->object.oid))
998 return 0;
@@ -1011,8 +1012,9 @@ static int fsck_blob(struct blob *blob, const char *buf,
1012 data.obj = &blob->object;
1013 data.options = options;
1014 data.ret = 0;
1015 + config_opts.error_action = CONFIG_ERROR_SILENT;
1016 if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
1015 - ".gitmodules", buf, size, &data, NULL))
1017 + ".gitmodules", buf, size, &data, &config_opts))
1018 data.ret |= report(options, &blob->object,
1019 FSCK_MSG_GITMODULES_PARSE,
1020 "could not parse gitmodules blob");
t/t7415-submodule-names.sh
+15
@@ -176,4 +176,19 @@ test_expect_success 'fsck detects non-blob .gitmodules' '
176 )
177 '
178
179 +test_expect_success 'fsck detects corrupt .gitmodules' '
180 + git init corrupt &&
181 + (
182 + cd corrupt &&
183 +
184 + echo "[broken" >.gitmodules &&
185 + git add .gitmodules &&
186 + git commit -m "broken gitmodules" &&
187 +
188 + test_must_fail git fsck 2>output &&
189 + grep gitmodulesParse output &&
190 + test_i18ngrep ! "bad config" output
191 + )
192 +'
193 +
194 test_done