Skip to content

Commit 483a6d9

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Reported-by: Jonathan Nieder <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8717937 commit 483a6d9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

builtin/gc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,8 @@ static int maintenance_register(void)
14621462
git_config_set("maintenance.strategy", "incremental");
14631463

14641464
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",
14661467
the_repository->worktree ? the_repository->worktree
14671468
: the_repository->gitdir,
14681469
NULL);
@@ -1493,7 +1494,7 @@ static int maintenance_unregister(void)
14931494

14941495
config_unset.git_cmd = 1;
14951496
strvec_pushl(&config_unset.args, "config", "--global", "--unset",
1496-
"maintenance.repo",
1497+
"--fixed-value", "maintenance.repo",
14971498
the_repository->worktree ? the_repository->worktree
14981499
: the_repository->gitdir,
14991500
NULL);

t/t7900-maintenance.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,18 @@ test_expect_success 'register and unregister' '
404404
test_cmp before actual
405405
'
406406

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+
407419
test_expect_success 'start from empty cron table' '
408420
GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start &&
409421

0 commit comments

Comments
 (0)