]> git.ipfire.org Git - thirdparty/git.git/commitdiff
maintenance: use 'git config --fixed-value'
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 25 Nov 2020 22:12:56 +0000 (22:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Nov 2020 23:04:55 +0000 (15:04 -0800)
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>
builtin/gc.c
t/t7900-maintenance.sh

index 3d258b60c2db2c736046f182afc096a45d2556ed..acfd5b9cf6cc9fca00d858db023a5a4104910126 100644 (file)
@@ -1462,7 +1462,8 @@ static int maintenance_register(void)
                git_config_set("maintenance.strategy", "incremental");
 
        config_get.git_cmd = 1;
-       strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
+       strvec_pushl(&config_get.args, "config", "--global", "--get",
+                    "--fixed-value", "maintenance.repo",
                     the_repository->worktree ? the_repository->worktree
                                              : the_repository->gitdir,
                         NULL);
@@ -1493,7 +1494,7 @@ static int maintenance_unregister(void)
 
        config_unset.git_cmd = 1;
        strvec_pushl(&config_unset.args, "config", "--global", "--unset",
-                    "maintenance.repo",
+                    "--fixed-value", "maintenance.repo",
                     the_repository->worktree ? the_repository->worktree
                                              : the_repository->gitdir,
                     NULL);
index d9e68bb2bfae2b59beee05daad72b726d010432d..ee91a714b9325fa021d93f6859cd1c7139e8153f 100755 (executable)
@@ -404,6 +404,18 @@ test_expect_success 'register and unregister' '
        test_cmp before actual
 '
 
+test_expect_success !MINGW 'register and unregister with regex metacharacters' '
+       META="a+b*c" &&
+       git init "$META" &&
+       git -C "$META" maintenance register &&
+       git config --get-all --show-origin maintenance.repo &&
+       git config --get-all --global --fixed-value \
+               maintenance.repo "$(pwd)/$META" &&
+       git -C "$META" maintenance unregister &&
+       test_must_fail git config --get-all --global --fixed-value \
+               maintenance.repo "$(pwd)/$META"
+'
+
 test_expect_success 'start from empty cron table' '
        GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start &&