Skip to content

Commit de6bd9e

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4574f1a commit de6bd9e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

fsck.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ static int fsck_blob(struct blob *blob, const char *buf,
992992
unsigned long size, struct fsck_options *options)
993993
{
994994
struct fsck_gitmodules_data data;
995+
struct config_options config_opts = { 0 };
995996

996997
if (!oidset_contains(&gitmodules_found, &blob->object.oid))
997998
return 0;
@@ -1011,8 +1012,9 @@ static int fsck_blob(struct blob *blob, const char *buf,
10111012
data.obj = &blob->object;
10121013
data.options = options;
10131014
data.ret = 0;
1015+
config_opts.error_action = CONFIG_ERROR_SILENT;
10141016
if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
1015-
".gitmodules", buf, size, &data, NULL))
1017+
".gitmodules", buf, size, &data, &config_opts))
10161018
data.ret |= report(options, &blob->object,
10171019
FSCK_MSG_GITMODULES_PARSE,
10181020
"could not parse gitmodules blob");

t/t7415-submodule-names.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,19 @@ test_expect_success 'fsck detects non-blob .gitmodules' '
176176
)
177177
'
178178

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+
179194
test_done

0 commit comments

Comments
 (0)