fsck: reject misconfigured fsck.skipList

In Git, fsck operations can ignore known broken objects via the `fsck.skipList` configuration. This option expects a path to a file with the list of object names. When the configuration is specified without a path, an error message is printed, but the command continues as if the configuration was not set. Configuring `fsck.skipList` without a value is a misconfiguration so config parsing should be more strict and reject it. Update `git_fsck_config()` to no longer ignore misconfiguration of `fsck.skipList`. The same behavior is also present for `fetch.fsck.skipList` and `receive.fsck.skipList` so the configuration parsers for these are updated to ensure the related operations remain consistent. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Jan 7, 2025 at 10:29 UTC ca7158076f9f6e0ee1c84595aaf44194a9880a72
4 files changed +13 -3
builtin/receive-pack.c
+1 -1
@@ -174,7 +174,7 @@ static int receive_pack_config(const char *var, const char *value,
174 char *path;
175
176 if (git_config_pathname(&path, var, value))
177 - return 1;
177 + return -1;
178 strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
179 fsck_msg_types.len ? ',' : '=', path);
180 free(path);
fetch-pack.c
+1 -1
@@ -1867,7 +1867,7 @@ int fetch_pack_fsck_config(const char *var, const char *value,
1867 char *path ;
1868
1869 if (git_config_pathname(&path, var, value))
1870 - return 0;
1870 + return -1;
1871 strbuf_addf(msg_types, "%cskiplist=%s",
1872 msg_types->len ? ',' : '=', path);
1873 free(path);
fsck.c
+1 -1
@@ -1353,7 +1353,7 @@ int git_fsck_config(const char *var, const char *value,
1353 struct strbuf sb = STRBUF_INIT;
1354
1355 if (git_config_pathname(&path, var, value))
1356 - return 1;
1356 + return -1;
1357 strbuf_addf(&sb, "skiplist=%s", path);
1358 free(path);
1359 fsck_set_msg_types(options, sb.buf);
t/t5504-fetch-receive-strict.sh
+10
@@ -167,6 +167,8 @@ test_expect_success 'fsck with unsorted skipList' '
167
168 test_expect_success 'fsck with invalid or bogus skipList input' '
169 git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
170 + test_must_fail git -c fsck.skipList -c fsck.missingEmail=ignore fsck 2>err &&
171 + test_grep "unable to parse '\'fsck.skiplist\'' from command-line config" err &&
172 test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
173 test_grep "could not open.*: does-not-exist" err &&
174 test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
@@ -213,6 +215,11 @@ test_expect_success 'fsck with exhaustive accepted skipList input (various types
215 test_must_be_empty err
216 '
217
218 +test_expect_success 'receive-pack with missing receive.fsck.skipList path' '
219 + test_must_fail git -c receive.fsck.skipList receive-pack dst 2>err &&
220 + test_grep "unable to parse '\'receive.fsck.skiplist\'' from command-line config" err
221 +'
222 +
223 test_expect_success 'push with receive.fsck.skipList' '
224 git push . $commit:refs/heads/bogus &&
225 rm -rf dst &&
@@ -255,6 +262,9 @@ test_expect_success 'fetch with fetch.fsck.skipList' '
262 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
263
264 # Invalid and/or bogus skipList input
265 + test_must_fail git --git-dir=dst/.git -c fetch.fsck.skipList fetch \
266 + "file://$(pwd)" $refspec 2>err &&
267 + test_grep "unable to parse '\'fetch.fsck.skiplist\'' from command-line config" err &&
268 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
269 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
270 git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&