Volume XXII, number 279Tuesday, October 6, 2026Latest message 12 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

v3submodule: warn on valueless active config

3 messages between Aug 15, 2026 and Aug 17, 2026, from tilak-raaz, Junio C Hamano.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

tilak-raazAug 15, 2026, 07:00 UTC on lore

The config parser previously threw a hard error if 'submodule.active' was provided without a value, causing commands to abort.

Swap repo_config_get_string_multi() to repo_config_get_value_multi() to parse valueless keys safely. Use the standard config_error_nonbool() helper to emit a warning to the user rather than crashing.

This resolves a NEEDSWORK comment in submodule.c.
Signed-off-by: tilak-raaz <raaztilak07@gmail.com>
---
Junio, thank you for the review and guidance on the terminology and tense.
Regarding causing the command to fail on a malformed config: I investigated returning an error code here, but is_tree_submodule_active() is evaluated as a boolean predicate by its callers (for example, if (!is_tree_submodule_active(...))). Since -1 is truthy in C, returning -1 would cause callers to treat the broken submodule as active.
To avoid changing the existing caller semantics or introducing process termination from this helper, I kept the continue behavior so the malformed entry is skipped after being reported with config_error_nonbool(), while valid entries continue to be processed.
Please let me know if you would prefer a different error-propagation approach.
Changes in v3:
-Updated the commit message to use present tense.
-Updated the commit message to use "valueless true".
-Fixed the whitespace and indentation in the t7400 test script.
 submodule.c                | 12 ++++++------
 t/t7400-submodule-basic.sh | 11 +++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)
Show changes to 2 files +17 −6

submodule.c, t/t7400-submodule-basic.sh

diff --git a/submodule.c b/submodule.c
index 5c92575888..07d1fc63e9 100644
--- a/submodule.c
+++ b/submodule.c
@@ -231,11 +231,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
 /*
  * Determine if a submodule has been initialized at a given 'path'
  */
-/*
- * NEEDSWORK: Emit a warning if submodule.active exists, but is valueless,
- * ie, the config looks like: "[submodule] active\n".
- * Since that is an invalid pathspec, we should inform the user.
- */
+
 int is_tree_submodule_active(struct repository *repo,
 			     const struct object_id *treeish_name,
 			     const char *path)
@@ -261,12 +257,16 @@ int is_tree_submodule_active(struct repository *repo,
 	free(key);
 
 	/* submodule.active is set */
-	if (!repo_config_get_string_multi(repo, "submodule.active", &sl)) {
+	if (!repo_config_get_value_multi(repo, "submodule.active", &sl)) {
 		struct pathspec ps;
 		struct strvec args = STRVEC_INIT;
 		const struct string_list_item *item;
 
 		for_each_string_list_item(item, sl) {
+			 if (!item->string) {
+				config_error_nonbool("submodule.active");
+				continue;
+			}
 			strvec_push(&args, item->string);
 		}
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index eefdecb0bd..62b2537174 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1549,4 +1549,15 @@ test_expect_success 'submodule add fails when name is reused' '
 	)
 '
 
+
+test_expect_success 'warn on valueless submodule.active' '
+	test_when_finished "rm -rf empty-active" &&
+	git init empty-active &&
+	test_commit -C empty-active initial &&
+	git -c protocol.file.allow=always -C empty-active submodule add ../empty-active sub &&
+	git -C empty-active config --unset submodule.sub.active &&
+	printf "[submodule]\n\tactive\n" >>empty-active/.git/config &&
+	git -C empty-active submodule status 2>err &&
+	grep "missing value for .submodule.active." err
+'
 test_done
-- 
2.50.1 (Apple Git-155)
tilak-raazAug 15, 2026, 07:18 UTC on lore

[PATCH v4] submodule: warn on valueless active config

The config parser throws a hard error if 'submodule.active' is provided without a value, causing commands to abort.

Swap repo_config_get_string_multi() to repo_config_get_value_multi() to parse valueless true safely. Use the standard config_error_nonbool() helper to emit a warning to the user rather than crashing.

This resolves a NEEDSWORK comment in submodule.c.
Signed-off-by: tilak-raaz <raaztilak07@gmail.com>
---
Junio, thank you for the review and guidance on the terminology and tense.
(Apologies for the noisy v3; I botched my --amend and accidentally left the commit message in the past tense. This v4 corrects the commit message.)
Regarding causing the command to fail on a malformed config: I investigated returning an error code here, but is_tree_submodule_active() is evaluated as a boolean predicate by its callers (for example, if (!is_tree_submodule_active(...))). Since -1 is truthy in C, returning -1 would cause callers to treat the broken submodule as active.
To avoid changing the existing caller semantics or introducing process termination from this helper, I kept the continue behavior so the malformed entry is skipped after being reported with config_error_nonbool(), while valid entries continue to be processed.
Please let me know if you would prefer a different error-propagation approach.
Changes in v4:
- Updated the commit message to use present tense (fixing the omission in v3).
- Updated the commit message to use "valueless true".
- Fixed the whitespace and indentation in the t7400 test script.
 submodule.c                | 12 ++++++------
 t/t7400-submodule-basic.sh | 11 +++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)
Show changes to 2 files +17 −6

submodule.c, t/t7400-submodule-basic.sh

diff --git a/submodule.c b/submodule.c
index 5c92575888..07d1fc63e9 100644
--- a/submodule.c
+++ b/submodule.c
@@ -231,11 +231,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
 /*
  * Determine if a submodule has been initialized at a given 'path'
  */
-/*
- * NEEDSWORK: Emit a warning if submodule.active exists, but is valueless,
- * ie, the config looks like: "[submodule] active\n".
- * Since that is an invalid pathspec, we should inform the user.
- */
+
 int is_tree_submodule_active(struct repository *repo,
 			     const struct object_id *treeish_name,
 			     const char *path)
@@ -261,12 +257,16 @@ int is_tree_submodule_active(struct repository *repo,
 	free(key);
 
 	/* submodule.active is set */
-	if (!repo_config_get_string_multi(repo, "submodule.active", &sl)) {
+	if (!repo_config_get_value_multi(repo, "submodule.active", &sl)) {
 		struct pathspec ps;
 		struct strvec args = STRVEC_INIT;
 		const struct string_list_item *item;
 
 		for_each_string_list_item(item, sl) {
+			 if (!item->string) {
+				config_error_nonbool("submodule.active");
+				continue;
+			}
 			strvec_push(&args, item->string);
 		}
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index eefdecb0bd..62b2537174 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1549,4 +1549,15 @@ test_expect_success 'submodule add fails when name is reused' '
 	)
 '
 
+
+test_expect_success 'warn on valueless submodule.active' '
+	test_when_finished "rm -rf empty-active" &&
+	git init empty-active &&
+	test_commit -C empty-active initial &&
+	git -c protocol.file.allow=always -C empty-active submodule add ../empty-active sub &&
+	git -C empty-active config --unset submodule.sub.active &&
+	printf "[submodule]\n\tactive\n" >>empty-active/.git/config &&
+	git -C empty-active submodule status 2>err &&
+	grep "missing value for .submodule.active." err
+'
 test_done
-- 
2.50.1 (Apple Git-155)
Junio C HamanoAug 17, 2026, 17:43 UTC in reply to tilak-raaz on lore

Re: [PATCH v4] submodule: warn on valueless active config

tilak-raaz <raaztilak07@gmail.com> writes:
> The config parser throws a hard error if 'submodule.active'
> is provided without a value, causing commands to abort.
Why is it a bad thing in the first place?
    $ echo "[submodule] config" >>.git/config
    $ git submodule
    error: missing value for 'submodule.active'

Is this error message not sufficient for users to go on finding where their configuration file is broken and fixing it?

Show 12 quoted lines
>  	/* submodule.active is set */
> -	if (!repo_config_get_string_multi(repo, "submodule.active", &sl)) {
> +	if (!repo_config_get_value_multi(repo, "submodule.active", &sl)) {
>  		struct pathspec ps;
>  		struct strvec args = STRVEC_INIT;
>  		const struct string_list_item *item;
>  
>  		for_each_string_list_item(item, sl) {
> +			 if (!item->string) {
> +				config_error_nonbool("submodule.active");
> +				continue;
> +			}

Warning and continuing as if no misconfigured variable existed? I do not think it is an improvement. Without stopping the process, the early error messages will just scroll away without giving the chance for the user to notice.

tilak-raaz <raaztilak07@gmail.com> writes:
Show 8 quoted lines
> The config parser throws a hard error if 'submodule.active'
> is provided without a value, causing commands to abort.
>
> Swap repo_config_get_string_multi() to repo_config_get_value_multi()
> to parse valueless true safely. Use the standard config_error_nonbool()
> helper to emit a warning to the user rather than crashing.
>
> This resolves a NEEDSWORK comment in submodule.c.

NEEDSWORK is different from TODO in that whoever addresses it must think if what the comment suggests to do is sensible in the first place. I do not think it is in this case. IOW, unlike TODO, there are two valid ways to resolve NEEDSWORK, (1) analyze the issue and validate that the suggested change is sensible, and then adjust the code to match, or (2) analyze the issue and determine that the suggested change is not a good idea, and then remove (or update) the comment.

> Signed-off-by: tilak-raaz <raaztilak07@gmail.com>
Documentation/SubmittingPatches::[real-name]???
Show 5 quoted lines
> (Apologies for the noisy v3; I botched my --amend and accidentally left the commit message in the past tense. This v4 corrects the commit message.)
>
> Regarding causing the command to fail on a malformed config: I investigated returning an error code here, but is_tree_submodule_active() is evaluated as a boolean predicate by its callers (for example, if (!is_tree_submodule_active(...))). Since -1 is truthy in C, returning -1 would cause callers to treat the broken submodule as active.
>
> To avoid changing the existing caller semantics or introducing process termination from this helper, I kept the continue behavior so the malformed entry is skipped after being reported with config_error_nonbool(), while valid entries continue to be processed.
All overly long lines.  Wrap them ~70 columns.
Thanks.

Back to recent threads