maintenance: use 'git config --fixed-value'

When a repository's leading directories contain regex metacharacters, the config calls for 'git maintenance register' and 'git maintenance unregister' are not careful enough. Use the new --fixed-value option to direct the config machinery to use exact string matches. This is a more robust option than escaping these arguments in a piecemeal fashion. For the test, require that we are not running on Windows since the '+' and '*' characters are not allowed on that filesystem. Reported-by: Emily Shaffer <emilyshaffer@google.com> Reported-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Nov 25, 2020 at 22:12 UTC 483a6d9b5da6a03d34aceb7bff86b12c7241e17b
2 files changed +15 -2
builtin/gc.c
+3 -2
@@ -1462,7 +1462,8 @@ static int maintenance_register(void)
1462 git_config_set("maintenance.strategy", "incremental");
1463
1464 config_get.git_cmd = 1;
1465 - strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
1465 + strvec_pushl(&config_get.args, "config", "--global", "--get",
1466 + "--fixed-value", "maintenance.repo",
1467 the_repository->worktree ? the_repository->worktree
1468 : the_repository->gitdir,
1469 NULL);
@@ -1493,7 +1494,7 @@ static int maintenance_unregister(void)
1494
1495 config_unset.git_cmd = 1;
1496 strvec_pushl(&config_unset.args, "config", "--global", "--unset",
1496 - "maintenance.repo",
1497 + "--fixed-value", "maintenance.repo",
1498 the_repository->worktree ? the_repository->worktree
1499 : the_repository->gitdir,
1500 NULL);
t/t7900-maintenance.sh
+12
@@ -404,6 +404,18 @@ test_expect_success 'register and unregister' '
404 test_cmp before actual
405 '
406
407 +test_expect_success !MINGW 'register and unregister with regex metacharacters' '
408 + META="a+b*c" &&
409 + git init "$META" &&
410 + git -C "$META" maintenance register &&
411 + git config --get-all --show-origin maintenance.repo &&
412 + git config --get-all --global --fixed-value \
413 + maintenance.repo "$(pwd)/$META" &&
414 + git -C "$META" maintenance unregister &&
415 + test_must_fail git config --get-all --global --fixed-value \
416 + maintenance.repo "$(pwd)/$META"
417 +'
418 +
419 test_expect_success 'start from empty cron table' '
420 GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start &&
421