git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 3/3] status: report when submodule URLs are out of sync

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 29, 2026, 15:42 UTC
Message-ID
<xmqqfqwjod8f.fsf@gitster.g>
In-Reply-To
<619101d5e124115a43faf51c84655b7b99a431dd.1795884822.git.gitgitgadget@gmail.com>
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 9 quoted lines
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 36e47e18ed..577b097aa0 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1636,6 +1636,7 @@ struct repository *repo UNUSED)
>  
>  	s.ignore_submodule_arg = ignore_submodule_arg;
>  	s.status_format = status_format;
> +	s.check_submodule_urls = 1;

The hunk header unfortunately is hard to read but this is inside cmd_status().

Now whichever format wt_status_print() is triggered with, we will show the submodule changes but only when the top-level command is "git status".

Good.
Show 29 quoted lines
> diff --git a/wt-status.c b/wt-status.c
> ...
> +static int submodule_has_custom_remote_url(struct repository *repo,
> +					  const char *path,
> +					  const char *gitmodules_url,
> +					  const char *config_url)
> +{
> +	struct repository subrepo = { 0 };
> +	const struct string_list *remote_urls = NULL;
> +	const char *remote;
> +	const char *remote_url;
> +	char *key, *up_path, *config_remote_url, *gitmodules_remote_url;
> +	int error_code, ret = 0;
> +
> +	if (!is_submodule_populated_gently(path, &error_code))
> +		return 0;
> +
> +	if (repo_submodule_init(&subrepo, repo, path,
> +				null_oid(repo->hash_algo)) < 0) {
> +		repo_clear(&subrepo);
> +		return 0;
> +	}
> +
> +	remote = repo_default_remote(&subrepo);
> +
> +	key = xstrfmt("remote.%s.url", remote);
> +	if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&
> +	    remote_urls->nr == 1 &&
> +	    (remote_url = remote_urls->items[0].string)) {

The third condition being a non-NULL check of the value and not a comparison can easily become confusing. GNU toolchains seem to encourage putting such a "var = value" assignment that is also used for a non-NULL/0 check inside an extra pair of parentheses, which is the convention the above code also uses. Use of the _get_value_ variant and checking the NULL-ness of .string allows us to cope with a valueless truth "[remote "frotz"] url;" cleanly.

Show 20 quoted lines
> +static int submodule_has_custom_remote_url(struct repository *repo,
> +					  const char *path,
> +					  const char *gitmodules_url,
> +					  const char *config_url)
> +{
> +	struct repository subrepo = { 0 };
> +	const struct string_list *remote_urls = NULL;
> +	const char *remote;
> +	const char *remote_url;
> +	char *key, *up_path, *config_remote_url, *gitmodules_remote_url;
> +	int error_code, ret = 0;
> +
> +	if (!is_submodule_populated_gently(path, &error_code))
> +		return 0;
> +
> +	if (repo_submodule_init(&subrepo, repo, path,
> +				null_oid(repo->hash_algo)) < 0) {
> +		repo_clear(&subrepo);
> +		return 0;
> +	}

Do we see a small inconsistency with the repository-aware design from the previous patch here?

This function takes 'repo' and passes it to repo_submodule_init() and resolve_submodule_url(), yet is_submodule_populated_gently() inspects "%s/.git" relative to the current working directory rather than the '.worktree' member of 'repo'.

That may be harmless today because cmd_status() runs with NEED_WORK_TREE and repo == the_repository, so we are always at the worktree root. It might be worth a comment near the call to is_submodule_populated_gently() though.

Show 13 quoted lines
> +static void wt_status_check_submodule_urls(struct wt_status *s)
> +{
> +	int i;
> +
> +	if (s->ignore_submodule_arg &&
> +	    !strcmp(s->ignore_submodule_arg, "all"))
> +		return;
> +
> +	if (is_gitmodules_unmerged(s->repo->index))
> +		return;
> +
> +	for (i = 0; i < s->repo->index->cache_nr; i++) {
> +		struct cache_entry *ce = s->repo->index->cache[i];

Because cmd_status() sets '.command_requires_full_index' to 0, you need to be careful when iterating '.cache' directly like the above loop when sparse-index is in effect.

In sparse-index.c, convert_to_sparse_rec() refuses to collapse any directory containing S_ISGITLINK entries, so I _think_ gitlinks remain visible even in a sparse index, but please double check.

Overall, this iteration was a very pleasant read. Thanks for working on it.

Previous: Alessio Attilio via GitGitGadgetNext: Alessio Attilio via GitGitGadget
Message 21 of 26 in “status: warn about stale submodule URLs”
  1. status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  2. D. Ben KnobleNov 27, 2026
  3. 0/2 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 27, 2026
  4. 1/2 submodule: prepare URL helpers for reuseAlessio Attilio via GitGitGadget, Nov 27, 2026
  5. 2/2 status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  6. Junio C HamanoNov 27, 2026
  7. ATTILIO ALESSIONov 27, 2026
  8. D. Ben KnobleNov 30, 2026
  9. 0/2 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 27, 2026
  10. 1/2 submodule: prepare URL helpers for reuseAlessio Attilio via GitGitGadget, Nov 27, 2026
  11. Junio C HamanoNov 28, 2026
  12. 2/2 status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  13. Junio C HamanoNov 28, 2026
  14. Junio C HamanoNov 28, 2026
  15. 0/3 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 28, 2026
  16. 1/3 submodule: move URL helpers into submodule.cAlessio Attilio via GitGitGadget, Nov 28, 2026
  17. D. Ben KnobleNov 30, 2026
  18. 2/3 submodule: make URL resolution repository-awareAlessio Attilio via GitGitGadget, Nov 28, 2026
  19. D. Ben KnobleNov 30, 2026
  20. 3/3 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 28, 2026
  21. Junio C HamanoNov 29, 2026
  22. 0/4 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Dec 1, 2026
  23. 1/4 submodule: share repository-aware URL resolutionAlessio Attilio via GitGitGadget, Dec 1, 2026
  24. 2/4 status: warn about submodule URL mismatchesAlessio Attilio via GitGitGadget, Dec 1, 2026
  25. 3/4 status: preserve customized submodule remotesAlessio Attilio via GitGitGadget, Dec 1, 2026
  26. 4/4 status: test submodule URL warningsAlessio Attilio via GitGitGadget, Dec 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.