Git development
 help / color / mirror / Atom feed
From: "Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Alessio Attilio <attilio.alessio@protonmail.com>
Subject: [PATCH v2 0/2] status: report when submodule URLs are out of sync
Date: Fri, 27 Nov 2026 16:16:00 +0000	[thread overview]
Message-ID: <pull.2509.v2.git.git.1795796162.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2509.git.git.1795774880142.gitgitgadget@gmail.com>

When a submodule URL changes in .gitmodules, the corresponding URL in the
superproject's .git/config may keep pointing at the old location. This
series makes git status warn about that mismatch and suggest git submodule
sync.

The warning resolves relative URLs as git submodule sync does. It also
suppresses the warning when the populated submodule has a custom remote URL
that a sync would overwrite.

The series is split into:

 1. submodule: prepare URL helpers for reuse
 2. status: warn about stale submodule URLs

Changes since v1:

 * Move the URL helper extraction into a preparatory commit.
 * Clarify the comparison between the cached URL, .gitmodules, and the
   populated submodule's remote URL.
 * Keep test output inside its fixture directory.

Closes gitgitgadget/git#565

Alessio Attilio (2):
  submodule: prepare URL helpers for reuse
  status: warn about stale submodule URLs

 builtin/submodule--helper.c |  63 ++++------------------
 submodule.c                 |  44 +++++++++++++++
 submodule.h                 |   3 ++
 t/t7508-status.sh           |  54 +++++++++++++++++++
 wt-status.c                 | 104 ++++++++++++++++++++++++++++++++++++
 5 files changed, 215 insertions(+), 53 deletions(-)


base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v2
Pull-Request: https://github.com/git/git/pull/2509

Range-diff vs v1:

 1:  528258ee95 ! 1:  4cd0ab7e9b status: warn about stale submodule URLs
     @@ Metadata
      Author: Alessio Attilio <attilio.alessio@protonmail.com>
      
       ## Commit message ##
     -    status: warn about stale submodule URLs
     +    submodule: prepare URL helpers for reuse
      
     -    When a submodule URL changes in .gitmodules, the URL cached in
     -    .git/config can keep pointing at the old remote. That leaves users
     -    with no indication that later submodule operations may use a
     -    repository different from the one the project declares.
     +    Move the relative submodule URL resolver and the helper that computes
     +    the path back to the superproject from builtin/submodule--helper.c to
     +    submodule.c so they can be shared with git status.
      
     -    Warn in git status so users can find and sync stale configuration
     -    before it causes a confusing fetch or update. Resolve relative URLs
     -    like git submodule sync does, and leave customized submodule remotes
     -    alone.
     +    Pass the repository explicitly to the resolver instead of relying on
     +    the_repository, and update existing callers to use the shared helpers.
      
          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
      
     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
      +	char *remoteurl, *resolved_url;
      +	struct strbuf remotesb = STRBUF_INIT;
      +
     -+	if (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))
     -+		return xstrdup(url);
     -+
      +	strbuf_addf(&remotesb, "remote.%s.url", remote);
      +	if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
      +		if (!quiet)
     @@ submodule.h: int is_tree_submodule_active(struct repository *repo,
       /*
        * Determine if a submodule has been populated at a given 'path' by checking if
        * the <path>/.git resolves to a valid git repository.
     -
     - ## t/t7508-status.sh ##
     -@@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
     - 	git add sm
     - '
     - 
     -+test_expect_success 'status reports submodule URL mismatch' '
     -+	test_when_finished "rm -rf url-test" &&
     -+	test_when_finished "rm -f actual err" &&
     -+	test_create_repo url-test/source &&
     -+	test_commit -C url-test/source initial &&
     -+	test_create_repo url-test/super &&
     -+	git -C url-test/super -c protocol.file.allow=always \
     -+		submodule add "$PWD/url-test/source" module &&
     -+	git -C url-test/super commit -m "add submodule" &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_must_be_empty err &&
     -+	git -C url-test/super config -f .gitmodules submodule.module.url \
     -+		"$PWD/url-test/updated-source" &&
     -+	git -C url-test/super status --porcelain >actual 2>err &&
     -+	test_must_be_empty err &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_grep "module.*different URL" err &&
     -+	test_grep "git submodule sync" err &&
     -+	git -C url-test/super submodule sync &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_must_be_empty err &&
     -+	git -C url-test/super remote add origin ../source-parent &&
     -+	git -C url-test/super config -f .gitmodules submodule.module.url \
     -+		../relative-source &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_grep "module.*different URL" err &&
     -+	git -C url-test/super submodule sync &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_must_be_empty err &&
     -+	git -C url-test/super config -f .gitmodules submodule.module.url \
     -+		../another-relative-source &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_grep "module.*different URL" err &&
     -+	git -C url-test/super submodule sync &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_must_be_empty err &&
     -+	git -C url-test/super/module config remote.origin.url \
     -+		"$PWD/url-test/fork" &&
     -+	git -C url-test/super config -f .gitmodules submodule.module.url \
     -+		../fork-source &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_must_be_empty err &&
     -+	git -C url-test/super/module config --add remote.origin.url \
     -+		"$PWD/url-test/another-fork" &&
     -+	git -C url-test/super config -f .gitmodules submodule.module.url \
     -+		../another-fork-source &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_must_be_empty err &&
     -+	git -C url-test/super/module config --unset-all remote.origin.url &&
     -+	git -C url-test/super config --add submodule.module.url \
     -+		"$PWD/url-test/another-configured-source" &&
     -+	git -C url-test/super status >actual 2>err &&
     -+	test_grep "module.*different URL" err
     -+'
     -+
     - test_expect_success 'status submodule summary is disabled by default' '
     - 	cat >expect <<EOF &&
     - On branch main
     -
     - ## wt-status.c ##
     -@@
     - 
     - #include "git-compat-util.h"
     - #include "advice.h"
     -+#include "config.h"
     - #include "wt-status.h"
     - #include "object.h"
     - #include "dir.h"
     -@@
     - #include "remote.h"
     - #include "refs.h"
     - #include "submodule.h"
     -+#include "submodule-config.h"
     - #include "column.h"
     - #include "read-cache.h"
     - #include "setup.h"
     -@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
     - 	}
     - }
     - 
     -+static int submodule_has_custom_remote_url(struct repository *repo,
     -+					  const char *path,
     -+					  const char *url,
     -+					  const char *configured_url)
     -+{
     -+	struct repository subrepo = { 0 };
     -+	const struct string_list *remote_urls = NULL;
     -+	const char *remote;
     -+	const char *remote_url;
     -+	char *key, *up_path, *old_url, *new_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;
     -+		up_path = get_submodule_up_path(path);
     -+		old_url = resolve_submodule_url(repo, configured_url, up_path, 1);
     -+		new_url = resolve_submodule_url(repo, url, up_path, 1);
     -+		ret = strcmp(remote_url, old_url) != 0 &&
     -+			strcmp(remote_url, new_url) != 0;
     -+		free(new_url);
     -+		free(old_url);
     -+		free(up_path);
     -+	} else {
     -+		/*
     -+		 * Multiple URLs are a local customization; sync would replace
     -+		 * them all with a single URL.
     -+		 */
     -+		ret = remote_urls && remote_urls->nr > 1;
     -+	}
     -+	free(key);
     -+	repo_clear(&subrepo);
     -+
     -+	return ret;
     -+}
     -+
     -+static void wt_status_check_submodule_urls(struct wt_status *s)
     -+{
     -+	int i;
     -+
     -+	if (s->status_format != STATUS_FORMAT_LONG &&
     -+	    s->status_format != STATUS_FORMAT_NONE)
     -+		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];
     -+		const struct submodule *sub;
     -+		const char *configured_url;
     -+		char *key, *expected_url;
     -+
     -+		if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))
     -+			continue;
     -+
     -+		sub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),
     -+					  ce->name);
     -+		if (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))
     -+			continue;
     -+
     -+		key = xstrfmt("submodule.%s.url", sub->name);
     -+		if (repo_config_get_value(s->repo, key, &configured_url)) {
     -+			free(key);
     -+			continue;
     -+		}
     -+		free(key);
     -+
     -+		expected_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);
     -+		if (strcmp(configured_url, expected_url) &&
     -+		    !submodule_has_custom_remote_url(s->repo, ce->name,
     -+						     expected_url,
     -+						     configured_url))
     -+			warning(_("submodule '%s' has a different URL in .git/config "
     -+				  "than in .gitmodules\n"
     -+				  "  run 'git submodule sync' to update it"), ce->name);
     -+
     -+		free(expected_url);
     -+	}
     -+}
     -+
     - void wt_status_print(struct wt_status *s)
     - {
     -+	wt_status_check_submodule_urls(s);
     -+
     - 	trace2_data_intmax("status", s->repo, "count/changed", s->change.nr);
     - 	trace2_data_intmax("status", s->repo, "count/untracked",
     - 			   s->untracked.nr);
 -:  ---------- > 2:  b0dd21100c status: warn about stale submodule URLs

-- 
gitgitgadget

  parent reply	other threads:[~2026-11-27 16:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 10:21 [PATCH] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
2026-11-27 13:41 ` D. Ben Knoble
2026-11-27 16:16 ` Alessio Attilio via GitGitGadget [this message]
2026-11-27 16:16   ` [PATCH v2 1/2] submodule: prepare URL helpers for reuse Alessio Attilio via GitGitGadget
2026-11-27 16:16   ` [PATCH v2 2/2] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
2026-11-27 18:11     ` Junio C Hamano
2026-11-27 20:35       ` ATTILIO ALESSIO
2026-11-30 15:46       ` D. Ben Knoble
2026-11-27 21:27 ` [PATCH v3 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-11-27 21:27   ` [PATCH v3 1/2] submodule: prepare URL helpers for reuse Alessio Attilio via GitGitGadget
2026-11-28  3:38     ` Junio C Hamano
2026-11-27 21:27   ` [PATCH v3 2/2] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
2026-11-28  4:08     ` Junio C Hamano
2026-11-28  4:19   ` [PATCH v3 0/2] status: report when submodule URLs are out of sync Junio C Hamano
2026-11-28 16:53 ` [PATCH v4 0/3] " Alessio Attilio via GitGitGadget
2026-11-28 16:53   ` [PATCH v4 1/3] submodule: move URL helpers into submodule.c Alessio Attilio via GitGitGadget
2026-11-30 15:54     ` D. Ben Knoble
2026-11-28 16:53   ` [PATCH v4 2/3] submodule: make URL resolution repository-aware Alessio Attilio via GitGitGadget
2026-11-30 15:56     ` D. Ben Knoble
2026-11-28 16:53   ` [PATCH v4 3/3] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-11-29 15:42     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.2509.v2.git.git.1795796162.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=attilio.alessio@protonmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox