Thread (1 message) 1 message, 1 author, 2020-11-19

Re: [PATCH 7/7] maintenance: use 'git config --literal-value'

From: Junio C Hamano <hidden>
Date: 2020-11-19 23:17:37

"Derrick Stolee via GitGitGadget" [off-list ref] writes:
quoted hunk
From: Derrick Stolee <redacted>

When a repository's leading directories contain regex glob characters,
the config calls for 'git maintenance register' and 'git maintenance
unregister' are not careful enough. Use the new --literal-value option
to direct the config machinery to use exact string matches. This is a
more robust option than excaping these arguments in a piecemeal fashion.

Reported-by: Emily Shaffer <redacted>
Reported-by: Jonathan Nieder <redacted>
Signed-off-by: Derrick Stolee <redacted>
---
 builtin/gc.c           |  5 +++--
 t/t7900-maintenance.sh | 12 ++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index e3098ef6a1..0784bbdc6a 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1452,7 +1452,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",
+		     "--literal-value", "maintenance.repo",
 		     the_repository->worktree ? the_repository->worktree
 					      : the_repository->gitdir,
 			 NULL);
@@ -1483,7 +1484,7 @@ static int maintenance_unregister(void)
 
 	config_unset.git_cmd = 1;
 	strvec_pushl(&config_unset.args, "config", "--global", "--unset",
-		     "maintenance.repo",
+		     "--literal-value", "maintenance.repo",
 		     the_repository->worktree ? the_repository->worktree
 					      : the_repository->gitdir,
 		     NULL);
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 20184e96e1..2ee5512158 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -367,6 +367,18 @@ test_expect_success 'register and unregister' '
 	test_cmp before actual
 '
 
+test_expect_success 'register and unregister with glob characters' '
+	GLOB="a+b*c" &&
+	git init "$GLOB" &&
+	git -C "$GLOB" maintenance register &&
+	git config --get-all --show-origin maintenance.repo &&
+	git config --get-all --global --literal-value \
+		maintenance.repo "$(pwd)/$GLOB" &&
+	git -C "$GLOB" maintenance unregister &&
+	test_must_fail git config --get-all --global --literal-value \
+		maintenance.repo "$(pwd)/$GLOB"
+'
+
Makes sense.  Thanks.

As to the topic-branch organization, my plan is for the final shape
(I haven't really reviewed the early 6 yet so I do not know if they
require rerolling at this point) would be to:

 - create ds/config-literal-value topic on somewhere old enough and
   queue [1/7] thru [6/7] on it.

 - merge the above into ds/maintenance-part-3

 - apply [7/7] on top of ds/maintenance-part-3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help