* [PATCH] status: warn about stale submodule URLs
@ 2026-11-27 10:21 Alessio Attilio via GitGitGadget
2026-11-27 13:41 ` D. Ben Knoble
` (3 more replies)
0 siblings, 4 replies; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-27 10:21 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
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.
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.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
status: report when submodule URLs are out of sync
Closes gitgitgadget/git#565
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v1
Pull-Request: https://github.com/git/git/pull/2509
builtin/submodule--helper.c | 63 ++++--------------------
submodule.c | 44 +++++++++++++++++
submodule.h | 3 ++
t/t7508-status.sh | 55 +++++++++++++++++++++
wt-status.c | 97 +++++++++++++++++++++++++++++++++++++
5 files changed, 209 insertions(+), 53 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 461b682d0d..5f293d9dfd 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -46,35 +46,6 @@
typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
void *cb_data);
-static char *get_default_remote(void)
-{
- return xstrdup(repo_default_remote(the_repository));
-}
-
-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
-{
- char *remoteurl, *resolved_url;
- char *remote = get_default_remote();
- struct strbuf remotesb = STRBUF_INIT;
-
- strbuf_addf(&remotesb, "remote.%s.url", remote);
- if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
- if (!quiet)
- warning(_("could not look up configuration '%s'. "
- "Assuming this repository is its own "
- "authoritative upstream."),
- remotesb.buf);
- remoteurl = xgetcwd();
- }
- resolved_url = relative_url(remoteurl, rel_url, up_path);
-
- free(remote);
- free(remoteurl);
- strbuf_release(&remotesb);
-
- return resolved_url;
-}
-
static int get_default_remote_submodule(const char *module_path, char **default_remote)
{
const struct submodule *sub;
@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 1);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 1);
free(oldurl);
}
}
@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)
*list = active_modules;
}
-static char *get_up_path(const char *path)
-{
- struct strbuf sb = STRBUF_INIT;
-
- strbuf_addstrings(&sb, "../", count_slashes(path));
-
- /*
- * Check if 'path' ends with slash or not
- * for having the same output for dir/sub_dir
- * and dir/sub_dir/
- */
- if (!is_dir_sep(path[strlen(path) - 1]))
- strbuf_addstr(&sb, "../");
-
- return strbuf_detach(&sb, NULL);
-}
-
static void for_each_listed_submodule(const struct module_list *list,
each_submodule_fn fn, void *cb_data)
{
@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 0);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 0);
free(oldurl);
}
@@ -1453,10 +1407,12 @@ static void sync_submodule(const char *path, const char *prefix,
if (sub && sub->url) {
if (starts_with_dot_dot_slash(sub->url) ||
starts_with_dot_slash(sub->url)) {
- char *up_path = get_up_path(path);
+ char *up_path = get_submodule_up_path(path);
- sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
- super_config_url = resolve_relative_url(sub->url, NULL, 1);
+ sub_origin_url = resolve_submodule_url(the_repository, sub->url,
+ up_path, 1);
+ super_config_url = resolve_submodule_url(the_repository,
+ sub->url, NULL, 1);
free(up_path);
} else {
sub_origin_url = xstrdup(sub->url);
@@ -2334,7 +2290,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
if (sub->url && (starts_with_dot_slash(sub->url) ||
starts_with_dot_dot_slash(sub->url))) {
- url = resolve_relative_url(sub->url, NULL, 0);
+ url = resolve_submodule_url(the_repository, sub->url, NULL, 0);
need_free_url = 1;
} else
url = sub->url;
@@ -3761,7 +3717,8 @@ static int module_add(int argc, const char **argv, const char *prefix,
"of the working tree"));
/* dereference source url relative to parent's url */
- to_free = resolve_relative_url(add_data.repo, NULL, 1);
+ to_free = resolve_submodule_url(the_repository, add_data.repo,
+ NULL, 1);
add_data.realrepo = to_free;
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
add_data.realrepo = add_data.repo;
diff --git a/submodule.c b/submodule.c
index a74d1925aa..5d0018d032 100644
--- a/submodule.c
+++ b/submodule.c
@@ -292,6 +292,50 @@ int is_submodule_active(struct repository *repo, const char *path)
return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
}
+char *resolve_submodule_url(struct repository *repo, const char *url,
+ const char *up_path, int quiet)
+{
+ const char *remote = repo_default_remote(repo);
+ 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)
+ warning(_("could not look up configuration '%s'. "
+ "Assuming this repository is its own "
+ "authoritative upstream."),
+ remotesb.buf);
+ remoteurl = xgetcwd();
+ }
+ resolved_url = relative_url(remoteurl, url, up_path);
+
+ free(remoteurl);
+ strbuf_release(&remotesb);
+
+ return resolved_url;
+}
+
+char *get_submodule_up_path(const char *path)
+{
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_addstrings(&sb, "../", count_slashes(path));
+
+ /*
+ * Check if 'path' ends with slash or not
+ * for having the same output for dir/sub_dir
+ * and dir/sub_dir/
+ */
+ if (!is_dir_sep(path[strlen(path) - 1]))
+ strbuf_addstr(&sb, "../");
+
+ return strbuf_detach(&sb, NULL);
+}
+
int is_submodule_populated_gently(const char *path, int *return_error_code)
{
int ret = 0;
diff --git a/submodule.h b/submodule.h
index 1a465a1208..2028f272c4 100644
--- a/submodule.h
+++ b/submodule.h
@@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,
const struct object_id *treeish_name,
const char *path);
int is_submodule_active(struct repository *repo, const char *path);
+char *resolve_submodule_url(struct repository *repo, const char *url,
+ const char *up_path, int quiet);
+char *get_submodule_up_path(const char *path);
/*
* Determine if a submodule has been populated at a given 'path' by checking if
* the <path>/.git resolves to a valid git repository.
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e10c961268..bf28de1907 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -921,6 +921,61 @@ 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
diff --git a/wt-status.c b/wt-status.c
index 238bb48643..e06c18d8e0 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -3,6 +3,7 @@
#include "git-compat-util.h"
#include "advice.h"
+#include "config.h"
#include "wt-status.h"
#include "object.h"
#include "dir.h"
@@ -23,6 +24,7 @@
#include "remote.h"
#include "refs.h"
#include "submodule.h"
+#include "submodule-config.h"
#include "column.h"
#include "read-cache.h"
#include "setup.h"
@@ -2692,8 +2694,103 @@ 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);
base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH] status: warn about stale submodule URLs
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 ` [PATCH v2 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
` (2 subsequent siblings)
3 siblings, 0 replies; 21+ messages in thread
From: D. Ben Knoble @ 2026-11-27 13:41 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
Hi Alessio,
On Fri, Nov 27, 2026 at 5:28 AM Alessio Attilio via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Alessio Attilio <attilio.alessio@protonmail.com>
>
> 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.
>
> 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.
This sounds like a good problem to solve, as it makes it more obvious
when to run "git submodule sync"---especially if you don't trust one
of the 2 URLs involved anymore!
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> -static char *get_default_remote(void)
> -static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
> -static char *get_up_path(const char *path)
> diff --git a/submodule.c b/submodule.c
> +char *resolve_submodule_url(struct repository *repo, const char *url,
> + const char *up_path, int quiet)
> +char *get_submodule_up_path(const char *path)
I am somewhat surprised to see this refactoring: at a quick glance, it
looks like some static functions needed to be exposed to another
translation unit, but that was not explained in the proposed log
message. (We also teach the URL resolver about a repository, all at
the same time? And I can't see where get_default_remote ended up, but
that's probably my skimming.)
On top of that, our usual style is to first, in a preparatory patch,
move code around (making it easy to see the movement), then in
subsequent patches make the small needed changes for a fix or feature
(making it easy to see the isolated changes).
> diff --git a/t/t7508-status.sh b/t/t7508-status.sh
> index e10c961268..bf28de1907 100755
> --- a/t/t7508-status.sh
> +++ b/t/t7508-status.sh
> @@ -921,6 +921,61 @@ 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" &&
Removing some of these files is a bit unusual, I think.
> + 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
> +'
I did not read the test script closely, but it seems we change some
submodule URLs and assert on status output, which is roughly what I'd
expect.
> diff --git a/wt-status.c b/wt-status.c
> index 238bb48643..e06c18d8e0 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -3,6 +3,7 @@
>
> #include "git-compat-util.h"
> #include "advice.h"
> +#include "config.h"
> #include "wt-status.h"
> #include "object.h"
> #include "dir.h"
> @@ -23,6 +24,7 @@
> #include "remote.h"
> #include "refs.h"
> #include "submodule.h"
> +#include "submodule-config.h"
> #include "column.h"
> #include "read-cache.h"
> #include "setup.h"
> @@ -2692,8 +2694,103 @@ 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;
> + }
I suppose in these cases we don't actually know the answer to the
question "submodule_has_custom_remote_url"… but I'm not sure if the
tri-state + behaving differently is worth it for a new warning yet, so
I'm ok with falling back to the current state of affairs for now.
> + 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;
I'm not sure I follow this strcmp logic:
* remote_url is from the submodule's config, I assume from the .git/modules/…?
* old_url is the resolved configured_url, which reading ahead tells me
is the superproject's config?
* new_url is the resolved url, which reading ahead tells me is also
from a pre-resolved submodule's config (aka "expected_url")?
So, I guess I'm actually confused about a few things:
* the terminology between caller (expected/configured) and callee
doesn't match; consistency might help
* the double-resolution of new_url seems odd?
* what are the 3 URLs involved? I suppose I was expecting a comparison
of 2, since that's what the log message describes (.gitmodules +
cached URL in .git/config).
> + 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);
> + }
> +}
> +
Thanks
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 0/2] status: report when submodule URLs are out of sync
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
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 21:27 ` [PATCH v3 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-11-28 16:53 ` [PATCH v4 0/3] " Alessio Attilio via GitGitGadget
3 siblings, 2 replies; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-27 16:16 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio
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
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 1/2] submodule: prepare URL helpers for reuse
2026-11-27 16:16 ` [PATCH v2 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
@ 2026-11-27 16:16 ` Alessio Attilio via GitGitGadget
2026-11-27 16:16 ` [PATCH v2 2/2] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
1 sibling, 0 replies; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-27 16:16 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
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.
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>
---
builtin/submodule--helper.c | 63 ++++++-------------------------------
submodule.c | 41 ++++++++++++++++++++++++
submodule.h | 3 ++
3 files changed, 54 insertions(+), 53 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 461b682d0d..5f293d9dfd 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -46,35 +46,6 @@
typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
void *cb_data);
-static char *get_default_remote(void)
-{
- return xstrdup(repo_default_remote(the_repository));
-}
-
-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
-{
- char *remoteurl, *resolved_url;
- char *remote = get_default_remote();
- struct strbuf remotesb = STRBUF_INIT;
-
- strbuf_addf(&remotesb, "remote.%s.url", remote);
- if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
- if (!quiet)
- warning(_("could not look up configuration '%s'. "
- "Assuming this repository is its own "
- "authoritative upstream."),
- remotesb.buf);
- remoteurl = xgetcwd();
- }
- resolved_url = relative_url(remoteurl, rel_url, up_path);
-
- free(remote);
- free(remoteurl);
- strbuf_release(&remotesb);
-
- return resolved_url;
-}
-
static int get_default_remote_submodule(const char *module_path, char **default_remote)
{
const struct submodule *sub;
@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 1);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 1);
free(oldurl);
}
}
@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)
*list = active_modules;
}
-static char *get_up_path(const char *path)
-{
- struct strbuf sb = STRBUF_INIT;
-
- strbuf_addstrings(&sb, "../", count_slashes(path));
-
- /*
- * Check if 'path' ends with slash or not
- * for having the same output for dir/sub_dir
- * and dir/sub_dir/
- */
- if (!is_dir_sep(path[strlen(path) - 1]))
- strbuf_addstr(&sb, "../");
-
- return strbuf_detach(&sb, NULL);
-}
-
static void for_each_listed_submodule(const struct module_list *list,
each_submodule_fn fn, void *cb_data)
{
@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 0);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 0);
free(oldurl);
}
@@ -1453,10 +1407,12 @@ static void sync_submodule(const char *path, const char *prefix,
if (sub && sub->url) {
if (starts_with_dot_dot_slash(sub->url) ||
starts_with_dot_slash(sub->url)) {
- char *up_path = get_up_path(path);
+ char *up_path = get_submodule_up_path(path);
- sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
- super_config_url = resolve_relative_url(sub->url, NULL, 1);
+ sub_origin_url = resolve_submodule_url(the_repository, sub->url,
+ up_path, 1);
+ super_config_url = resolve_submodule_url(the_repository,
+ sub->url, NULL, 1);
free(up_path);
} else {
sub_origin_url = xstrdup(sub->url);
@@ -2334,7 +2290,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
if (sub->url && (starts_with_dot_slash(sub->url) ||
starts_with_dot_dot_slash(sub->url))) {
- url = resolve_relative_url(sub->url, NULL, 0);
+ url = resolve_submodule_url(the_repository, sub->url, NULL, 0);
need_free_url = 1;
} else
url = sub->url;
@@ -3761,7 +3717,8 @@ static int module_add(int argc, const char **argv, const char *prefix,
"of the working tree"));
/* dereference source url relative to parent's url */
- to_free = resolve_relative_url(add_data.repo, NULL, 1);
+ to_free = resolve_submodule_url(the_repository, add_data.repo,
+ NULL, 1);
add_data.realrepo = to_free;
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
add_data.realrepo = add_data.repo;
diff --git a/submodule.c b/submodule.c
index a74d1925aa..f9ca99c5c8 100644
--- a/submodule.c
+++ b/submodule.c
@@ -292,6 +292,47 @@ int is_submodule_active(struct repository *repo, const char *path)
return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
}
+char *resolve_submodule_url(struct repository *repo, const char *url,
+ const char *up_path, int quiet)
+{
+ const char *remote = repo_default_remote(repo);
+ char *remoteurl, *resolved_url;
+ struct strbuf remotesb = STRBUF_INIT;
+
+ strbuf_addf(&remotesb, "remote.%s.url", remote);
+ if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
+ if (!quiet)
+ warning(_("could not look up configuration '%s'. "
+ "Assuming this repository is its own "
+ "authoritative upstream."),
+ remotesb.buf);
+ remoteurl = xgetcwd();
+ }
+ resolved_url = relative_url(remoteurl, url, up_path);
+
+ free(remoteurl);
+ strbuf_release(&remotesb);
+
+ return resolved_url;
+}
+
+char *get_submodule_up_path(const char *path)
+{
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_addstrings(&sb, "../", count_slashes(path));
+
+ /*
+ * Check if 'path' ends with slash or not
+ * for having the same output for dir/sub_dir
+ * and dir/sub_dir/
+ */
+ if (!is_dir_sep(path[strlen(path) - 1]))
+ strbuf_addstr(&sb, "../");
+
+ return strbuf_detach(&sb, NULL);
+}
+
int is_submodule_populated_gently(const char *path, int *return_error_code)
{
int ret = 0;
diff --git a/submodule.h b/submodule.h
index 1a465a1208..2028f272c4 100644
--- a/submodule.h
+++ b/submodule.h
@@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,
const struct object_id *treeish_name,
const char *path);
int is_submodule_active(struct repository *repo, const char *path);
+char *resolve_submodule_url(struct repository *repo, const char *url,
+ const char *up_path, int quiet);
+char *get_submodule_up_path(const char *path);
/*
* Determine if a submodule has been populated at a given 'path' by checking if
* the <path>/.git resolves to a valid git repository.
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 2/2] status: warn about stale submodule URLs
2026-11-27 16:16 ` [PATCH v2 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-11-27 16:16 ` [PATCH v2 1/2] submodule: prepare URL helpers for reuse Alessio Attilio via GitGitGadget
@ 2026-11-27 16:16 ` Alessio Attilio via GitGitGadget
2026-11-27 18:11 ` Junio C Hamano
1 sibling, 1 reply; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-27 16:16 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
When a submodule URL changes in .gitmodules, the cached
submodule.<name>.url in the superproject config can stay stale. Warn
in git status so users can run git submodule sync before a later
submodule operation uses the outdated URL.
Resolve relative URLs using the same paths as git submodule sync.
Avoid warning when the submodule remote indicates a local
customization that sync would overwrite.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
submodule.c | 3 ++
t/t7508-status.sh | 54 ++++++++++++++++++++++++
wt-status.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 161 insertions(+)
diff --git a/submodule.c b/submodule.c
index f9ca99c5c8..5d0018d032 100644
--- a/submodule.c
+++ b/submodule.c
@@ -299,6 +299,9 @@ char *resolve_submodule_url(struct repository *repo, const char *url,
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)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e10c961268..76a2e96dd7 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -921,6 +921,60 @@ 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_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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super config -f .gitmodules submodule.module.url \
+ "$PWD/url-test/updated-source" &&
+ git -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ test_grep "git submodule sync" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super config -f .gitmodules submodule.module.url \
+ ../another-relative-source &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err
+'
+
test_expect_success 'status submodule summary is disabled by default' '
cat >expect <<EOF &&
On branch main
diff --git a/wt-status.c b/wt-status.c
index 238bb48643..be6902c9dd 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -3,6 +3,7 @@
#include "git-compat-util.h"
#include "advice.h"
+#include "config.h"
#include "wt-status.h"
#include "object.h"
#include "dir.h"
@@ -23,6 +24,7 @@
#include "remote.h"
#include "refs.h"
#include "submodule.h"
+#include "submodule-config.h"
#include "column.h"
#include "read-cache.h"
#include "setup.h"
@@ -2692,8 +2694,110 @@ 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 *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;
+ up_path = get_submodule_up_path(path);
+ config_remote_url = resolve_submodule_url(repo, config_url,
+ up_path, 1);
+ gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
+ up_path, 1);
+ /*
+ * The submodule's remote URL may be a local fork. If it matches
+ * neither the old cached URL nor the new .gitmodules URL, leave it
+ * alone; syncing would overwrite that customization.
+ */
+ ret = strcmp(remote_url, config_remote_url) != 0 &&
+ strcmp(remote_url, gitmodules_remote_url) != 0;
+ free(gitmodules_remote_url);
+ free(config_remote_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 *config_url;
+ char *key, *gitmodules_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, &config_url)) {
+ free(key);
+ continue;
+ }
+ free(key);
+
+ gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);
+ if (strcmp(config_url, gitmodules_url) &&
+ !submodule_has_custom_remote_url(s->repo, ce->name,
+ sub->url,
+ config_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(gitmodules_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);
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/2] status: warn about stale submodule URLs
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
0 siblings, 2 replies; 21+ messages in thread
From: Junio C Hamano @ 2026-11-27 18:11 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Alessio Attilio <attilio.alessio@protonmail.com>
>
> When a submodule URL changes in .gitmodules, the cached
> submodule.<name>.url in the superproject config can stay stale. Warn
> in git status so users can run git submodule sync before a later
> submodule operation uses the outdated URL.
>
> Resolve relative URLs using the same paths as git submodule sync.
> Avoid warning when the submodule remote indicates a local
> customization that sync would overwrite.
>
> Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
> ---
Surfacing stale submodule configuration in "git status" is a very useful
improvement. Like Ben noted, splitting the helper extraction out into a
preparatory commit made the series easier to follow.
It would help to explain in the proposed log message why three URLs are
compared and under what condition, and which status formats emit the
warning.
> diff --git a/submodule.c b/submodule.c
> index f9ca99c5c8..5d0018d032 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -299,6 +299,9 @@ char *resolve_submodule_url(struct repository *repo, const char *url,
> 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)
The split made it harder to spot, but this addition forces the helper
function to return if 'url' is not relative, yet we have already spent
cycles calling repo_default_remote() to compute 'remote', paying the
cost to call repo_config() and to look up the HEAD branch. Perhaps move
the unnecessary call to repo_default_remote() after this early return,
before the first use of 'remote'?
> diff --git a/wt-status.c b/wt-status.c
> index 238bb48643..be6902c9dd 100644
> --- 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;
Can the '.string' member be NULL here, either by mistake or by malice?
We have two strcmp() calls below to compare this with two other URLs,
and either would segfault.
Perhaps use repo_config_get_string_multi() instead? I do not know what
error behavior you are aiming for here, but the 'string' variant would
barf on an entry like '[remote "origin"] url' (valueless true), which
would give you NULL in the '.string' member.
> + up_path = get_submodule_up_path(path);
> + config_remote_url = resolve_submodule_url(repo, config_url,
> + up_path, 1);
> + gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
> + up_path, 1);
> + /*
> + * The submodule's remote URL may be a local fork. If it matches
> + * neither the old cached URL nor the new .gitmodules URL, leave it
> + * alone; syncing would overwrite that customization.
> + */
> + ret = strcmp(remote_url, config_remote_url) != 0 &&
> + strcmp(remote_url, gitmodules_remote_url) != 0;
Renaming of new/old may address one of the points of confusion Ben had.
When the superproject's own default remote URL is relative, doesn't
this logic break?
In wt_status_check_submodule_urls() we see below, 'gitmodules_url' was
already computed by resolving sub->url against the superproject's
default remote with 'up_path' set to NULL. Likewise, 'config_url' from
submodule.<name>.url in .git/config was already resolved once with
'up_path' set to NULL when init_submodule() or sync_submodule() wrote
it.
Passing already-resolved URLs into resolve_submodule_url() again smells
fishy. There are a few ways I can think of that this can break. I may
be misreading the code flow, and these may be no issue, or there may be
other issues.
* When the superproject has "remote.origin.url = a/b" (relative without
"./" or "../") and .gitmodules has "../mod1", sync_submodule() stores
"a/mod1" in submodule.module.url and "../a/mod1" in the submodule's
remote.origin.url.
submodule_has_custom_remote_url() calls resolve_submodule_url() on
"a/mod1". It hits the early return without prepending 'up_path', so
'config_remote_url' is "a/mod1" instead of "../a/mod1" and fails to
match.
* When the superproject has "remote.origin.url = ../a/b", .gitmodules
initially has "submodule.module.url = ../mod1", and the user runs
"git submodule sync". In sync_submodule(), relative_url() stores
"../a/mod1" in submodule.module.url and "../../a/mod1" in the
submodule's remote.origin.url.
If submodule.module.url in .gitmodules then changes to "../mod2",
wt_status_check_submodule_urls() sets 'gitmodules_remote_url' to
"../a/mod2". Inside submodule_has_custom_remote_url(), both
"../a/mod1" and "../a/mod2" still start with "../", so
resolve_submodule_url() resolves them a second time against "../a/b".
Wouldn't the result be "../../a/a/mod1" and "../../a/a/mod2" in such
a case?
Neither matches "../../a/mod1", so submodule_has_custom_remote_url()
returns 1 and suppresses the warning even though the submodule remote
was never customized. The new test in t7508 used "../source-parent"
with only one path component after "..", where the second resolution
happened to be a no-op, so it may not have noticed the breakage.
In order to match what sync_submodule() does, 'gitmodules_remote_url'
should be computed from the raw 'sub->url', not from 'gitmodules_url',
no? For 'config_remote_url', we do not want to run relative_url() again
on 'config_url', I think. You only need to prepend 'up_path', or
something, no? I didn't think this one through, so take it with a huge
grain of salt.
> +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;
Mental note. Restricting this only to the "long" and "none" formats
somehow feels arbitrary. Perhaps the callers ought to have more direct
and finer control, and tell the callchain leading to wt_status_print()
to refrain from calling this helper at all when the callers do not want
the warnings (like "git commit" preparing the commit template). That
would allow us to free this helper from making this arbitrary choice.
> + key = xstrfmt("submodule.%s.url", sub->name);
> + if (repo_config_get_value(s->repo, key, &config_url)) {
> + free(key);
> + continue;
> + }
> + free(key);
> +
> + gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);
> + if (strcmp(config_url, gitmodules_url) &&
This is another potential NULL dereference due to the use of
repo_config_get_value() instead of _get_string(), no? The same
mechanism, the same segfault.
> 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);
wt_status_print() is not just for "git status", but is also used to
generate commit templates. Checking only '.status_format' at the
beginning of wt_status_check_submodule_urls() means that these extra
checks are done and warnings are leaked into unrelated commands.
In builtin/commit.c, cmd_commit() sets '.commit_template' to 1 and
'status_format' to STATUS_FORMAT_NONE, and prepare_to_commit() calls
run_status() with 'nowarn' set to 1 when populating COMMIT_EDITMSG.
Similarly, fill_commit_message() in builtin/history.c leaves
'.status_format' at STATUS_FORMAT_NONE, sets '.commit_template' to 1,
and calls wt_status_print() after collecting a diff between two trees.
As a result, running "git commit" with an editor or "git history" emits
this status warning to stderr.
Instead of excluding individual cases (like "commit or history can call
and .commit_template or .nowarn may be set by them"), can we make sure
we call the extra check only when "git status" is calling the wt-status
machinery to prevent it?
There are also a few design questions.
* Should "git status <pathspec>" limit its check to submodules under
the given directory?
* Should "git status --ignore-submodules" bypass the new check
altogether?
* Should "git status -s" and "git status --porcelain" detect the
misconfiguration like the normal "git status"?
My tentative answers to the above are all "yes", but the design needs to
be discussed, the choices justified, and the result documented in both
the proposed commit log message and in the "git status --help"
documentation.
Thanks.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/2] status: warn about stale submodule URLs
2026-11-27 18:11 ` Junio C Hamano
@ 2026-11-27 20:35 ` ATTILIO ALESSIO
2026-11-30 15:46 ` D. Ben Knoble
1 sibling, 0 replies; 21+ messages in thread
From: ATTILIO ALESSIO @ 2026-11-27 20:35 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Alessio Attilio via GitGitGadget, git
[-- Attachment #1.1: Type: text/plain, Size: 3143 bytes --]
"Junio C Hamano" <gitster@pobox.com> writes:
> It would help to explain in the proposed log message why three URLs are
> compared and under what condition, and which status formats emit the
> warning.
Will do. I will explain in the commit message why the three URLs are
compared, under what condition the warning triggers, and which status
formats emit it.
> Perhaps move the unnecessary call to repo_default_remote() after this
> early return, before the first use of 'remote'?
Good catch. I will move repo_default_remote() below the early return
for non-relative URLs.
> Perhaps use repo_config_get_string_multi() instead? I do not know what
> error behavior you are aiming for here, but the 'string' variant would
> barf on an entry like '[remote "origin"] url' (valueless true), which
> would give you NULL in the '.string' member.
Agreed. I will switch to the *_get_string*() helpers (or guard against
valueless entries) so we never pass NULL to strcmp().
> In order to match what sync_submodule() does, 'gitmodules_remote_url'
> should be computed from the raw 'sub->url', not from 'gitmodules_url',
> no? For 'config_remote_url', we do not want to run relative_url() again
> on 'config_url', I think. You only need to prepend 'up_path', or
> something, no?
You are right: the values passed to submodule_has_custom_remote_url()
have already been resolved once, so resolving them again produces wrong
paths when the superproject's own remote URL is relative. I will
rework this to resolve the raw .gitmodules URL and prepend up_path to
the cached config URL, matching git submodule sync.
> Instead of excluding individual cases (like "commit or history can call
> and .commit_template or .nowarn may be set by them"), can we make sure
> we call the extra check only when "git status" is calling the wt-status
> machinery to prevent it?
Yes, gating the check so it runs only when invoked from git status is
much cleaner and avoids leaking warnings into commit templates.
> - Should "git status <pathspec>" limit its check to submodules under
> the given directory?
>
> - Should "git status --ignore-submodules" bypass the new check
> altogether?
>
> - Should "git status -s" and "git status --porcelain" detect the
> misconfiguration like the normal "git status"?
>
> My tentative answers to the above are all "yes", but the design needs to
> be discussed, the choices justified, and the result documented in both
> the proposed commit log message and in the "git status --help"
> documentation.
I agree with "yes" on all three:
- Respecting <pathspec> keeps the warning scoped to the paths the user
asked about.
- Respecting --ignore-submodules matches user expectations when they
explicitly ask status to ignore submodule state.
- Emitting the warning on stderr in -s and --porcelain modes ensures
users and scripts still get the diagnostic without affecting machine-
readable stdout output.
I will update the implementation, tests, commit message, and git-status
documentation accordingly for the next reroll.
Thanks,
Alessio
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 323 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v3 0/2] status: report when submodule URLs are out of sync
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 ` [PATCH v2 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
@ 2026-11-27 21:27 ` Alessio Attilio via GitGitGadget
2026-11-27 21:27 ` [PATCH v3 1/2] submodule: prepare URL helpers for reuse Alessio Attilio via GitGitGadget
` (2 more replies)
2026-11-28 16:53 ` [PATCH v4 0/3] " Alessio Attilio via GitGitGadget
3 siblings, 3 replies; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-27 21:27 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio
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: move URL helpers to submodule.c
2. submodule: make URL resolution repository-aware
3. status: warn about stale submodule URLs
Changes since v2:
* Keep the helper relocation in a preparatory commit.
* Move repository-aware URL resolution into its own commit.
* 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
Documentation/git-status.adoc | 6 ++
builtin/commit.c | 1 +
builtin/submodule--helper.c | 63 +++---------------
submodule.c | 45 +++++++++++++
submodule.h | 3 +
t/t7508-status.sh | 84 ++++++++++++++++++++++++
wt-status.c | 120 ++++++++++++++++++++++++++++++++++
wt-status.h | 1 +
8 files changed, 270 insertions(+), 53 deletions(-)
base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v3
Pull-Request: https://github.com/git/git/pull/2509
Range-diff vs v2:
1: 4cd0ab7e9b ! 1: fc300295ff submodule: prepare URL helpers for reuse
@@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
}
-+char *resolve_submodule_url(struct repository *repo, const char *url,
++char *resolve_submodule_url(struct repository *repo, const char *rel_url,
+ const char *up_path, int quiet)
+{
-+ const char *remote = repo_default_remote(repo);
+ char *remoteurl, *resolved_url;
++ const char *remote = repo_default_remote(repo);
+ struct strbuf remotesb = STRBUF_INIT;
+
+ strbuf_addf(&remotesb, "remote.%s.url", remote);
@@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
+ remotesb.buf);
+ remoteurl = xgetcwd();
+ }
-+ resolved_url = relative_url(remoteurl, url, up_path);
++ resolved_url = relative_url(remoteurl, rel_url, up_path);
+
+ free(remoteurl);
+ strbuf_release(&remotesb);
2: b0dd21100c ! 2: 9dc6283075 status: warn about stale submodule URLs
@@ Commit message
in git status so users can run git submodule sync before a later
submodule operation uses the outdated URL.
- Resolve relative URLs using the same paths as git submodule sync.
- Avoid warning when the submodule remote indicates a local
- customization that sync would overwrite.
+ The check considers three URLs: the .gitmodules URL resolved against
+ the superproject's default remote, the cached submodule.<name>.url, and
+ the submodule's default remote URL. The first two determine whether the
+ cached URL is stale. If they differ, compare the submodule remote with
+ the old and new URLs as sync would write them. Warn only when that
+ remote matches either URL; a different URL or multiple URLs indicate a
+ local customization that sync would otherwise overwrite.
+
+ Resolve relative URLs using the same paths as git submodule sync, and
+ do not resolve the already-resolved cached URL a second time. Emit the
+ warning on standard error for long, short, and porcelain status output,
+ limited to submodules matched by the pathspec. Do not emit it when
+ --ignore-submodules is given or when the wt-status machinery is used by
+ another command.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
+ ## Documentation/git-status.adoc ##
+@@ Documentation/git-status.adoc: are what you _would_ commit by running `git commit`; the second and
+ third are what you _could_ commit by running `git add` before running
+ `git commit`.
+
++When a submodule's URL in `.gitmodules` differs from the URL cached in
++`.git/config`, `git status` warns that `git submodule sync` can update the
++cached URL. The warning is written to standard error in all output formats.
++It is limited to submodules matched by the pathspec, and is suppressed when
++`--ignore-submodules` is specified.
++
+ OPTIONS
+ -------
+
+
+ ## builtin/commit.c ##
+@@ builtin/commit.c: struct repository *repo UNUSED)
+
+ s.ignore_submodule_arg = ignore_submodule_arg;
+ s.status_format = status_format;
++ s.check_submodule_urls = 1;
+ s.verbose = verbose;
+ if (no_renames != -1)
+ s.detect_rename = !no_renames;
+
## submodule.c ##
-@@ submodule.c: char *resolve_submodule_url(struct repository *repo, const char *url,
+@@ submodule.c: char *resolve_submodule_url(struct repository *repo, const char *rel_url,
+ const char *up_path, int quiet)
+ {
char *remoteurl, *resolved_url;
+- const char *remote = repo_default_remote(repo);
++ const char *remote;
struct strbuf remotesb = STRBUF_INIT;
-+ if (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))
-+ return xstrdup(url);
++ if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
++ return xstrdup(rel_url);
+
++ remote = repo_default_remote(repo);
strbuf_addf(&remotesb, "remote.%s.url", remote);
if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
if (!quiet)
@@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
+ git -C url-test/super config -f .gitmodules submodule.module.url \
+ "$PWD/url-test/updated-source" &&
+ git -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&
++ test_grep "module.*different URL" url-test/err &&
++ git -C url-test/super status --short >url-test/actual 2>url-test/err &&
++ test_grep "module.*different URL" url-test/err &&
++ git -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&
++ test_grep "module.*different URL" url-test/err &&
++ git -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
++ git -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&
++ test_must_be_empty url-test/err &&
++ git -C url-test/super status -- module >url-test/actual 2>url-test/err &&
++ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ test_grep "git submodule sync" url-test/err &&
@@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err
+'
++
++test_expect_success 'status compares relative submodule URLs only once' '
++ test_when_finished "rm -rf url-test" &&
++ test_create_repo url-test/relative-source &&
++ test_commit -C url-test/relative-source initial &&
++ test_create_repo url-test/relative-super &&
++ git -C url-test/relative-super -c protocol.file.allow=always \
++ submodule add "$PWD/url-test/relative-source" module &&
++ git -C url-test/relative-super commit -m "add submodule" &&
++ git -C url-test/relative-super remote add origin ../a/b &&
++ git -C url-test/relative-super config -f .gitmodules \
++ submodule.module.url ../mod1 &&
++ git -C url-test/relative-super submodule sync &&
++ git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
++ test_must_be_empty url-test/err &&
++ git -C url-test/relative-super config -f .gitmodules \
++ submodule.module.url ../mod2 &&
++ git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
++ test_grep "module.*different URL" url-test/err
++'
+
test_expect_success 'status submodule summary is disabled by default' '
cat >expect <<EOF &&
@@ wt-status.c
#include "git-compat-util.h"
#include "advice.h"
++#include "abspath.h"
+#include "config.h"
#include "wt-status.h"
#include "object.h"
@@ wt-status.c
#include "remote.h"
#include "refs.h"
#include "submodule.h"
++#include "url.h"
+#include "submodule-config.h"
#include "column.h"
#include "read-cache.h"
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ remote = repo_default_remote(&subrepo);
+
+ key = xstrfmt("remote.%s.url", remote);
-+ if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&
++ if (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&
+ remote_urls->nr == 1) {
+ remote_url = remote_urls->items[0].string;
+ up_path = get_submodule_up_path(path);
-+ config_remote_url = resolve_submodule_url(repo, config_url,
-+ up_path, 1);
++ /*
++ * sync_submodule() stores a relative URL in the superproject's
++ * config without the submodule path prefix, but adds that prefix
++ * when storing the URL in the submodule's remote configuration.
++ */
++ if (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {
++ struct strbuf sb = STRBUF_INIT;
++
++ strbuf_addstr(&sb, up_path);
++ strbuf_addstr(&sb, config_url);
++ config_remote_url = strbuf_detach(&sb, NULL);
++ } else {
++ config_remote_url = xstrdup(config_url);
++ }
+ gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
+ up_path, 1);
+ /*
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+{
+ int i;
+
-+ if (s->status_format != STATUS_FORMAT_LONG &&
-+ s->status_format != STATUS_FORMAT_NONE)
++ if (!s->check_submodule_urls || s->ignore_submodule_arg)
+ return;
+
+ if (is_gitmodules_unmerged(s->repo->index))
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ 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 *config_url;
++ char *config_url;
+ char *key, *gitmodules_url;
+
-+ if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))
++ if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||
++ !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))
+ continue;
+
+ sub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ continue;
+
+ key = xstrfmt("submodule.%s.url", sub->name);
-+ if (repo_config_get_value(s->repo, key, &config_url)) {
++ if (repo_config_get_string(s->repo, key, &config_url)) {
+ free(key);
+ continue;
+ }
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ "than in .gitmodules\n"
+ " run 'git submodule sync' to update it"), ce->name);
+
++ free(config_url);
+ free(gitmodules_url);
+ }
+}
+
void wt_status_print(struct wt_status *s)
{
-+ wt_status_check_submodule_urls(s);
++ if (s->check_submodule_urls)
++ 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);
+
+ ## wt-status.h ##
+@@ wt-status.h: struct wt_status {
+ unsigned colopts;
+ int null_termination;
+ int commit_template;
++ int check_submodule_urls;
+ int show_branch;
+ int show_stash;
+ int hints;
--
gitgitgadget
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v3 1/2] submodule: prepare URL helpers for reuse
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 ` 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:19 ` [PATCH v3 0/2] status: report when submodule URLs are out of sync Junio C Hamano
2 siblings, 1 reply; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-27 21:27 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
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.
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>
---
builtin/submodule--helper.c | 63 ++++++-------------------------------
submodule.c | 41 ++++++++++++++++++++++++
submodule.h | 3 ++
3 files changed, 54 insertions(+), 53 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 461b682d0d..5f293d9dfd 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -46,35 +46,6 @@
typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
void *cb_data);
-static char *get_default_remote(void)
-{
- return xstrdup(repo_default_remote(the_repository));
-}
-
-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
-{
- char *remoteurl, *resolved_url;
- char *remote = get_default_remote();
- struct strbuf remotesb = STRBUF_INIT;
-
- strbuf_addf(&remotesb, "remote.%s.url", remote);
- if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
- if (!quiet)
- warning(_("could not look up configuration '%s'. "
- "Assuming this repository is its own "
- "authoritative upstream."),
- remotesb.buf);
- remoteurl = xgetcwd();
- }
- resolved_url = relative_url(remoteurl, rel_url, up_path);
-
- free(remote);
- free(remoteurl);
- strbuf_release(&remotesb);
-
- return resolved_url;
-}
-
static int get_default_remote_submodule(const char *module_path, char **default_remote)
{
const struct submodule *sub;
@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 1);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 1);
free(oldurl);
}
}
@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)
*list = active_modules;
}
-static char *get_up_path(const char *path)
-{
- struct strbuf sb = STRBUF_INIT;
-
- strbuf_addstrings(&sb, "../", count_slashes(path));
-
- /*
- * Check if 'path' ends with slash or not
- * for having the same output for dir/sub_dir
- * and dir/sub_dir/
- */
- if (!is_dir_sep(path[strlen(path) - 1]))
- strbuf_addstr(&sb, "../");
-
- return strbuf_detach(&sb, NULL);
-}
-
static void for_each_listed_submodule(const struct module_list *list,
each_submodule_fn fn, void *cb_data)
{
@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 0);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 0);
free(oldurl);
}
@@ -1453,10 +1407,12 @@ static void sync_submodule(const char *path, const char *prefix,
if (sub && sub->url) {
if (starts_with_dot_dot_slash(sub->url) ||
starts_with_dot_slash(sub->url)) {
- char *up_path = get_up_path(path);
+ char *up_path = get_submodule_up_path(path);
- sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
- super_config_url = resolve_relative_url(sub->url, NULL, 1);
+ sub_origin_url = resolve_submodule_url(the_repository, sub->url,
+ up_path, 1);
+ super_config_url = resolve_submodule_url(the_repository,
+ sub->url, NULL, 1);
free(up_path);
} else {
sub_origin_url = xstrdup(sub->url);
@@ -2334,7 +2290,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
if (sub->url && (starts_with_dot_slash(sub->url) ||
starts_with_dot_dot_slash(sub->url))) {
- url = resolve_relative_url(sub->url, NULL, 0);
+ url = resolve_submodule_url(the_repository, sub->url, NULL, 0);
need_free_url = 1;
} else
url = sub->url;
@@ -3761,7 +3717,8 @@ static int module_add(int argc, const char **argv, const char *prefix,
"of the working tree"));
/* dereference source url relative to parent's url */
- to_free = resolve_relative_url(add_data.repo, NULL, 1);
+ to_free = resolve_submodule_url(the_repository, add_data.repo,
+ NULL, 1);
add_data.realrepo = to_free;
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
add_data.realrepo = add_data.repo;
diff --git a/submodule.c b/submodule.c
index a74d1925aa..3eab799f1f 100644
--- a/submodule.c
+++ b/submodule.c
@@ -292,6 +292,47 @@ int is_submodule_active(struct repository *repo, const char *path)
return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
}
+char *resolve_submodule_url(struct repository *repo, const char *rel_url,
+ const char *up_path, int quiet)
+{
+ char *remoteurl, *resolved_url;
+ const char *remote = repo_default_remote(repo);
+ struct strbuf remotesb = STRBUF_INIT;
+
+ strbuf_addf(&remotesb, "remote.%s.url", remote);
+ if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
+ if (!quiet)
+ warning(_("could not look up configuration '%s'. "
+ "Assuming this repository is its own "
+ "authoritative upstream."),
+ remotesb.buf);
+ remoteurl = xgetcwd();
+ }
+ resolved_url = relative_url(remoteurl, rel_url, up_path);
+
+ free(remoteurl);
+ strbuf_release(&remotesb);
+
+ return resolved_url;
+}
+
+char *get_submodule_up_path(const char *path)
+{
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_addstrings(&sb, "../", count_slashes(path));
+
+ /*
+ * Check if 'path' ends with slash or not
+ * for having the same output for dir/sub_dir
+ * and dir/sub_dir/
+ */
+ if (!is_dir_sep(path[strlen(path) - 1]))
+ strbuf_addstr(&sb, "../");
+
+ return strbuf_detach(&sb, NULL);
+}
+
int is_submodule_populated_gently(const char *path, int *return_error_code)
{
int ret = 0;
diff --git a/submodule.h b/submodule.h
index 1a465a1208..2028f272c4 100644
--- a/submodule.h
+++ b/submodule.h
@@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,
const struct object_id *treeish_name,
const char *path);
int is_submodule_active(struct repository *repo, const char *path);
+char *resolve_submodule_url(struct repository *repo, const char *url,
+ const char *up_path, int quiet);
+char *get_submodule_up_path(const char *path);
/*
* Determine if a submodule has been populated at a given 'path' by checking if
* the <path>/.git resolves to a valid git repository.
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v3 2/2] status: warn about stale submodule URLs
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-27 21:27 ` 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
2 siblings, 1 reply; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-27 21:27 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
When a submodule URL changes in .gitmodules, the cached
submodule.<name>.url in the superproject config can stay stale. Warn
in git status so users can run git submodule sync before a later
submodule operation uses the outdated URL.
The check considers three URLs: the .gitmodules URL resolved against
the superproject's default remote, the cached submodule.<name>.url, and
the submodule's default remote URL. The first two determine whether the
cached URL is stale. If they differ, compare the submodule remote with
the old and new URLs as sync would write them. Warn only when that
remote matches either URL; a different URL or multiple URLs indicate a
local customization that sync would otherwise overwrite.
Resolve relative URLs using the same paths as git submodule sync, and
do not resolve the already-resolved cached URL a second time. Emit the
warning on standard error for long, short, and porcelain status output,
limited to submodules matched by the pathspec. Do not emit it when
--ignore-submodules is given or when the wt-status machinery is used by
another command.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
Documentation/git-status.adoc | 6 ++
builtin/commit.c | 1 +
submodule.c | 6 +-
t/t7508-status.sh | 84 ++++++++++++++++++++++++
wt-status.c | 120 ++++++++++++++++++++++++++++++++++
wt-status.h | 1 +
6 files changed, 217 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-status.adoc b/Documentation/git-status.adoc
index 9acca52bfb..1e0831a98e 100644
--- a/Documentation/git-status.adoc
+++ b/Documentation/git-status.adoc
@@ -22,6 +22,12 @@ are what you _would_ commit by running `git commit`; the second and
third are what you _could_ commit by running `git add` before running
`git commit`.
+When a submodule's URL in `.gitmodules` differs from the URL cached in
+`.git/config`, `git status` warns that `git submodule sync` can update the
+cached URL. The warning is written to standard error in all output formats.
+It is limited to submodules matched by the pathspec, and is suppressed when
+`--ignore-submodules` is specified.
+
OPTIONS
-------
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;
s.verbose = verbose;
if (no_renames != -1)
s.detect_rename = !no_renames;
diff --git a/submodule.c b/submodule.c
index 3eab799f1f..24775b21b7 100644
--- a/submodule.c
+++ b/submodule.c
@@ -296,9 +296,13 @@ char *resolve_submodule_url(struct repository *repo, const char *rel_url,
const char *up_path, int quiet)
{
char *remoteurl, *resolved_url;
- const char *remote = repo_default_remote(repo);
+ const char *remote;
struct strbuf remotesb = STRBUF_INIT;
+ if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
+ return xstrdup(rel_url);
+
+ remote = repo_default_remote(repo);
strbuf_addf(&remotesb, "remote.%s.url", remote);
if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
if (!quiet)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e10c961268..830217b4a5 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -921,6 +921,90 @@ 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_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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super config -f .gitmodules submodule.module.url \
+ "$PWD/url-test/updated-source" &&
+ git -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --short >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status -- module >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ test_grep "git submodule sync" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super config -f .gitmodules submodule.module.url \
+ ../another-relative-source &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err
+'
+
+test_expect_success 'status compares relative submodule URLs only once' '
+ test_when_finished "rm -rf url-test" &&
+ test_create_repo url-test/relative-source &&
+ test_commit -C url-test/relative-source initial &&
+ test_create_repo url-test/relative-super &&
+ git -C url-test/relative-super -c protocol.file.allow=always \
+ submodule add "$PWD/url-test/relative-source" module &&
+ git -C url-test/relative-super commit -m "add submodule" &&
+ git -C url-test/relative-super remote add origin ../a/b &&
+ git -C url-test/relative-super config -f .gitmodules \
+ submodule.module.url ../mod1 &&
+ git -C url-test/relative-super submodule sync &&
+ git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/relative-super config -f .gitmodules \
+ submodule.module.url ../mod2 &&
+ git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err
+'
+
test_expect_success 'status submodule summary is disabled by default' '
cat >expect <<EOF &&
On branch main
diff --git a/wt-status.c b/wt-status.c
index 238bb48643..5bcbe634df 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -3,6 +3,8 @@
#include "git-compat-util.h"
#include "advice.h"
+#include "abspath.h"
+#include "config.h"
#include "wt-status.h"
#include "object.h"
#include "dir.h"
@@ -23,6 +25,8 @@
#include "remote.h"
#include "refs.h"
#include "submodule.h"
+#include "url.h"
+#include "submodule-config.h"
#include "column.h"
#include "read-cache.h"
#include "setup.h"
@@ -2692,8 +2696,124 @@ 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 *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_string_multi(&subrepo, key, &remote_urls) &&
+ remote_urls->nr == 1) {
+ remote_url = remote_urls->items[0].string;
+ up_path = get_submodule_up_path(path);
+ /*
+ * sync_submodule() stores a relative URL in the superproject's
+ * config without the submodule path prefix, but adds that prefix
+ * when storing the URL in the submodule's remote configuration.
+ */
+ if (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_addstr(&sb, up_path);
+ strbuf_addstr(&sb, config_url);
+ config_remote_url = strbuf_detach(&sb, NULL);
+ } else {
+ config_remote_url = xstrdup(config_url);
+ }
+ gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
+ up_path, 1);
+ /*
+ * The submodule's remote URL may be a local fork. If it matches
+ * neither the old cached URL nor the new .gitmodules URL, leave it
+ * alone; syncing would overwrite that customization.
+ */
+ ret = strcmp(remote_url, config_remote_url) != 0 &&
+ strcmp(remote_url, gitmodules_remote_url) != 0;
+ free(gitmodules_remote_url);
+ free(config_remote_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->check_submodule_urls || s->ignore_submodule_arg)
+ 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;
+ char *config_url;
+ char *key, *gitmodules_url;
+
+ if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||
+ !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))
+ 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_string(s->repo, key, &config_url)) {
+ free(key);
+ continue;
+ }
+ free(key);
+
+ gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);
+ if (strcmp(config_url, gitmodules_url) &&
+ !submodule_has_custom_remote_url(s->repo, ce->name,
+ sub->url,
+ config_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(config_url);
+ free(gitmodules_url);
+ }
+}
+
void wt_status_print(struct wt_status *s)
{
+ if (s->check_submodule_urls)
+ 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);
diff --git a/wt-status.h b/wt-status.h
index e9fe32e98c..45eeb8b558 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -123,6 +123,7 @@ struct wt_status {
unsigned colopts;
int null_termination;
int commit_template;
+ int check_submodule_urls;
int show_branch;
int show_stash;
int hints;
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v3 1/2] submodule: prepare URL helpers for reuse
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
0 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2026-11-28 3:38 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Alessio Attilio <attilio.alessio@protonmail.com>
>
> 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.
>
> Pass the repository explicitly to the resolver instead of relying on
> the_repository, and update existing callers to use the shared helpers.
This preparatory extraction may make the next patch easier to read.
Removing the get_default_remote() wrapper that has only one caller, and
calling repo_default_remote(repo) directly is safe too, because
repo_default_remote() returns a pointer owned by repo->remote_state (or
a static "origin" string) and repo_config_get_string() does not
invalidate remote_state before relative_url() runs.
> Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
> ---
> builtin/submodule--helper.c | 63 ++++++-------------------------------
> submodule.c | 41 ++++++++++++++++++++++++
> submodule.h | 3 ++
> 3 files changed, 54 insertions(+), 53 deletions(-)
While this takes 'repo', the fallback when remote.<remote>.url is unset
still calls xgetcwd(). For current callers ('submodule--helper' and
'git status' under RUN_SETUP | NEED_WORK_TREE), the working directory is
already the superproject worktree root, so behavior is preserved.
Still, if a future caller passes a 'struct repository *' for another
worktree or subrepository, xgetcwd() will resolve relative URLs against
the process working directory instead of repo->worktree.
Using
remoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd();
may make the helper genuinely repository-aware, perhaps?
In any case, the "repository-aware" change should be a separate step,
outside the "move code around" step, right?
> diff --git a/submodule.h b/submodule.h
> index 1a465a1208..2028f272c4 100644
> --- a/submodule.h
> +++ b/submodule.h
> @@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,
> const struct object_id *treeish_name,
> const char *path);
> int is_submodule_active(struct repository *repo, const char *path);
> +char *resolve_submodule_url(struct repository *repo, const char *url,
> + const char *up_path, int quiet);
> +char *get_submodule_up_path(const char *path);
The header names the second parameter 'url', while the definition in
submodule.c names it 'rel_url'.
It would help to add comments above the declarations of these two
functions and to document that callers free the returned string, that
'up_path' may be NULL, and that get_submodule_up_path() expects a
non-empty 'path' (because it indexes path[strlen(path) - 1]). It would
match the surrounding declarations in this header file.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v3 2/2] status: warn about stale submodule URLs
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
0 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2026-11-28 4:08 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
> Resolve relative URLs using the same paths as git submodule sync, and
> do not resolve the already-resolved cached URL a second time. Emit the
> warning on standard error for long, short, and porcelain status output,
> limited to submodules matched by the pathspec. Do not emit it when
> --ignore-submodules is given or when the wt-status machinery is used by
> another command.
The three-URL check now avoids double-resolving config_url and
gitmodules_url when the superproject remote URL is relative, and
switches from the get_value() config readers to the get_string()
family.
The check at the beginning of wt_status_check_submodule_urls() has
been replaced with different logic, but I thought that we agreed to
move the check to the caller, wt_status_print(), to avoid calling
this new helper? There also is a glaring bug in the updated logic
for the "--ignore-submodules" check.
Other than these, the issues in the remainder of the patch I saw in
an earlier round got much better.
> diff --git a/submodule.c b/submodule.c
> index 3eab799f1f..24775b21b7 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -296,9 +296,13 @@ char *resolve_submodule_url(struct repository *repo, const char *rel_url,
> const char *up_path, int quiet)
> {
> char *remoteurl, *resolved_url;
> - const char *remote = repo_default_remote(repo);
> + const char *remote;
> struct strbuf remotesb = STRBUF_INIT;
>
> + if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
> + return xstrdup(rel_url);
It would make resolve_submodule_url() self-contained if you moved this
early return into the preparatory patch (the one you will split out of
[1/2] for the "repository aware" step). It would allow callers in
builtin/submodule--helper.c to drop duplicate checks if desired, too.
Also, starts_with_dot_dot_slash() assumes 'rel_url' is non-NULL;
wt_status_check_submodule_urls() checks sub->url first, so current
callers are safe, though an explicit NULL guard or doc comment in
submodule.h may be worth considering to prevent future surprises.
> diff --git a/wt-status.c b/wt-status.c
> index 238bb48643..5bcbe634df 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -2692,8 +2696,124 @@ 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 *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);
In builtin/submodule--helper.c, sync_submodule() picks which submodule
remote to update by calling get_default_remote_submodule().
That helper checks repo_remote_from_url() against the resolved
.gitmodules URL first and falls back to repo_default_remote(&subrepo)
only if no remote matches. If a submodule has both a customized
'origin' remote and an 'upstream' remote that matches what .gitmodules
has, sync_submodule() updates 'upstream' without touching 'origin',
whereas submodule_has_custom_remote_url() checks only 'origin' and
suppresses the warning.
Checking only the default remote is reasonable for the common
single-remote case, though it is worth keeping this subtle difference in
mind.
> +static void wt_status_check_submodule_urls(struct wt_status *s)
> +{
> + int i;
> +
> + if (!s->check_submodule_urls || s->ignore_submodule_arg)
> + return;
I do not think checking .ignore_submodule_arg like this helps. It is of
type "const char *", so I assume it holds string values like "none" that
you will get when
git status --ignore-submodules=none
is run, right? You do not want to punt in such a case.
Comparing against wt_longstatus_print() in wt-status.c shows how other
status checks handle this:
if (s->submodule_summary &&
(!s->ignore_submodule_arg ||
strcmp(s->ignore_submodule_arg, "all"))) {
Using
if (!s->check_submodule_urls ||
(s->ignore_submodule_arg &&
!strcmp(s->ignore_submodule_arg, "all")))
return;
here keeps '--ignore-submodules=none' (and =dirty/=untracked) warning as
expected, and matches "suppressed when '--ignore-submodules=all' (or
bare '--ignore-submodules') is specified" in the docs and commit log.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v3 0/2] status: report when submodule URLs are out of sync
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-27 21:27 ` [PATCH v3 2/2] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
@ 2026-11-28 4:19 ` Junio C Hamano
2 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2026-11-28 4:19 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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: move URL helpers to submodule.c
> 2. submodule: make URL resolution repository-aware
> 3. status: warn about stale submodule URLs
The cover letter describes a three-patch split, and the changelog notes
moving repository-aware URL resolution into its own commit, yet this v3
series contains two patches where patch 1/2 both relocates the helpers
and takes 'struct repository *repo' (matching the two-patch range-diff
against v2). Sent before finishing the work and checking if the result
matches the cover letter description, perhaps?
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v4 0/3] status: report when submodule URLs are out of sync
2026-11-27 10:21 [PATCH] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
` (2 preceding siblings ...)
2026-11-27 21:27 ` [PATCH v3 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
@ 2026-11-28 16:53 ` Alessio Attilio via GitGitGadget
2026-11-28 16:53 ` [PATCH v4 1/3] submodule: move URL helpers into submodule.c Alessio Attilio via GitGitGadget
` (2 more replies)
3 siblings, 3 replies; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-28 16:53 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio
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: move URL helpers to submodule.c
2. submodule: make URL resolution repository-aware
3. status: warn about stale submodule URLs
Changes since v2:
* Keep the helper relocation in a preparatory commit.
* Move repository-aware URL resolution into its own commit.
* Keep test output inside its fixture directory.
Closes gitgitgadget/git#565
Alessio Attilio (3):
submodule: move URL helpers into submodule.c
submodule: make URL resolution repository-aware
status: report when submodule URLs are out of sync
Documentation/git-status.adoc | 12 ++++
builtin/commit.c | 1 +
builtin/submodule--helper.c | 60 ++---------------
submodule.c | 45 +++++++++++++
submodule.h | 12 ++++
t/t7508-status.sh | 100 ++++++++++++++++++++++++++++
wt-status.c | 120 ++++++++++++++++++++++++++++++++++
wt-status.h | 1 +
8 files changed, 298 insertions(+), 53 deletions(-)
base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v4
Pull-Request: https://github.com/git/git/pull/2509
Range-diff vs v3:
1: fc300295ff ! 1: b09e8501ed submodule: prepare URL helpers for reuse
@@ Metadata
Author: Alessio Attilio <attilio.alessio@protonmail.com>
## Commit message ##
- submodule: prepare URL helpers for reuse
+ submodule: move URL helpers into submodule.c
- 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.
+ 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. This lets other
+ callers reuse the helpers.
- Pass the repository explicitly to the resolver instead of relying on
- the_repository, and update existing callers to use the shared helpers.
+ Return non-relative URLs unchanged before consulting remote
+ configuration, so the resolver handles every URL form itself.
+ Keep the repository parameter change for the next patch.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
@@ builtin/submodule--helper.c: static int get_default_remote_submodule(const char
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 1);
-+ url = resolve_submodule_url(the_repository, oldurl, NULL, 1);
++ url = resolve_submodule_url(oldurl, NULL, 1);
free(oldurl);
}
}
@@ builtin/submodule--helper.c: static void init_submodule(const char *path, const
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 0);
-+ url = resolve_submodule_url(the_repository, oldurl, NULL, 0);
++ url = resolve_submodule_url(oldurl, NULL, 0);
free(oldurl);
}
@@ builtin/submodule--helper.c: static void sync_submodule(const char *path, const
- sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
- super_config_url = resolve_relative_url(sub->url, NULL, 1);
-+ sub_origin_url = resolve_submodule_url(the_repository, sub->url,
-+ up_path, 1);
-+ super_config_url = resolve_submodule_url(the_repository,
-+ sub->url, NULL, 1);
++ sub_origin_url = resolve_submodule_url(sub->url, up_path, 1);
++ super_config_url = resolve_submodule_url(sub->url, NULL, 1);
free(up_path);
} else {
sub_origin_url = xstrdup(sub->url);
@@ builtin/submodule--helper.c: static int prepare_to_clone_next_submodule(const st
if (sub->url && (starts_with_dot_slash(sub->url) ||
starts_with_dot_dot_slash(sub->url))) {
- url = resolve_relative_url(sub->url, NULL, 0);
-+ url = resolve_submodule_url(the_repository, sub->url, NULL, 0);
++ url = resolve_submodule_url(sub->url, NULL, 0);
need_free_url = 1;
} else
url = sub->url;
@@ builtin/submodule--helper.c: static int module_add(int argc, const char **argv,
/* dereference source url relative to parent's url */
- to_free = resolve_relative_url(add_data.repo, NULL, 1);
-+ to_free = resolve_submodule_url(the_repository, add_data.repo,
-+ NULL, 1);
++ to_free = resolve_submodule_url(add_data.repo, NULL, 1);
add_data.realrepo = to_free;
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
add_data.realrepo = add_data.repo;
@@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
}
-+char *resolve_submodule_url(struct repository *repo, const char *rel_url,
-+ const char *up_path, int quiet)
++static char *get_default_remote(void)
++{
++ return xstrdup(repo_default_remote(the_repository));
++}
++
++char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)
+{
+ char *remoteurl, *resolved_url;
-+ const char *remote = repo_default_remote(repo);
++ char *remote;
+ struct strbuf remotesb = STRBUF_INIT;
+
++ if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
++ return xstrdup(rel_url);
++
++ remote = get_default_remote();
+ strbuf_addf(&remotesb, "remote.%s.url", remote);
-+ if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
++ if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
+ if (!quiet)
+ warning(_("could not look up configuration '%s'. "
+ "Assuming this repository is its own "
@@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
+ }
+ resolved_url = relative_url(remoteurl, rel_url, up_path);
+
++ free(remote);
+ free(remoteurl);
+ strbuf_release(&remotesb);
+
@@ submodule.h: int is_tree_submodule_active(struct repository *repo,
const struct object_id *treeish_name,
const char *path);
int is_submodule_active(struct repository *repo, const char *path);
-+char *resolve_submodule_url(struct repository *repo, const char *url,
-+ const char *up_path, int quiet);
++char *resolve_submodule_url(const char *url, const char *up_path, int quiet);
+char *get_submodule_up_path(const char *path);
/*
* Determine if a submodule has been populated at a given 'path' by checking if
-: ---------- > 2: ad4dafd82b submodule: make URL resolution repository-aware
2: 9dc6283075 ! 3: 619101d5e1 status: warn about stale submodule URLs
@@ Metadata
Author: Alessio Attilio <attilio.alessio@protonmail.com>
## Commit message ##
- status: warn about stale submodule URLs
+ status: report when submodule URLs are out of sync
- When a submodule URL changes in .gitmodules, the cached
- submodule.<name>.url in the superproject config can stay stale. Warn
- in git status so users can run git submodule sync before a later
- submodule operation uses the outdated URL.
+ When the URL in .gitmodules differs from the cached URL in the
+ superproject config, git status can help users discover that
+ submodule operations may use a stale location. Resolve relative
+ URLs the same way as git submodule sync does.
- The check considers three URLs: the .gitmodules URL resolved against
- the superproject's default remote, the cached submodule.<name>.url, and
- the submodule's default remote URL. The first two determine whether the
- cached URL is stale. If they differ, compare the submodule remote with
- the old and new URLs as sync would write them. Warn only when that
- remote matches either URL; a different URL or multiple URLs indicate a
- local customization that sync would otherwise overwrite.
+ For populated submodules, compare the default remote URL as well.
+ If it matches neither the cached URL nor the newly declared URL,
+ treat it as a local customization and do not suggest a sync that
+ would overwrite it. Multiple remote URLs are also treated as a
+ customization.
- Resolve relative URLs using the same paths as git submodule sync, and
- do not resolve the already-resolved cached URL a second time. Emit the
- warning on standard error for long, short, and porcelain status output,
- limited to submodules matched by the pathspec. Do not emit it when
- --ignore-submodules is given or when the wt-status machinery is used by
- another command.
+ Emit the warning on standard error for long, short, and porcelain
+ formats. Respect pathspecs and suppress the check only when
+ --ignore-submodules=all (or its bare form) is given. Run the check
+ only for git status, not other users of the wt-status machinery.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
@@ Documentation/git-status.adoc: are what you _would_ commit by running `git commi
+When a submodule's URL in `.gitmodules` differs from the URL cached in
+`.git/config`, `git status` warns that `git submodule sync` can update the
-+cached URL. The warning is written to standard error in all output formats.
-+It is limited to submodules matched by the pathspec, and is suppressed when
-+`--ignore-submodules` is specified.
++cached URL. For a populated submodule, the warning is suppressed when its
++default remote URL differs from both URLs, since syncing would overwrite a
++customized remote. Relative URLs are resolved as `git submodule sync`
++resolves them.
++
++The warning is written to standard error in long, short, and porcelain
++formats, and is limited to submodules matched by the pathspec. It is
++suppressed when `--ignore-submodules` or `--ignore-submodules=all` is
++specified.
+
OPTIONS
-------
@@ builtin/commit.c: struct repository *repo UNUSED)
if (no_renames != -1)
s.detect_rename = !no_renames;
- ## submodule.c ##
-@@ submodule.c: char *resolve_submodule_url(struct repository *repo, const char *rel_url,
- const char *up_path, int quiet)
- {
- char *remoteurl, *resolved_url;
-- const char *remote = repo_default_remote(repo);
-+ const char *remote;
- struct strbuf remotesb = STRBUF_INIT;
-
-+ if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
-+ return xstrdup(rel_url);
-+
-+ remote = repo_default_remote(repo);
- strbuf_addf(&remotesb, "remote.%s.url", remote);
- if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
- if (!quiet)
-
## t/t7508-status.sh ##
@@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
git add sm
@@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
+ "$PWD/url-test/updated-source" &&
+ git -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
++ cat >url-test/editor <<\EOF &&
++#!/bin/sh
++echo "status test commit" >"$1"
++EOF
++ chmod +x url-test/editor &&
++ echo staged >url-test/super/staged &&
++ git -C url-test/super add staged &&
++ test_set_editor "$PWD/url-test/editor" &&
++ git -C url-test/super commit >url-test/actual 2>url-test/err &&
++ test_must_be_empty url-test/err &&
+ git -C url-test/super status --short >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
++ git -C url-test/super status --ignore-submodules=none >url-test/actual 2>url-test/err &&
++ test_grep "module.*different URL" url-test/err &&
++ git -C url-test/super status --ignore-submodules=dirty >url-test/actual 2>url-test/err &&
++ test_grep "module.*different URL" url-test/err &&
++ git -C url-test/super status --ignore-submodules=all >url-test/actual 2>url-test/err &&
++ test_must_be_empty url-test/err &&
+ git -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ remote = repo_default_remote(&subrepo);
+
+ key = xstrfmt("remote.%s.url", remote);
-+ if (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&
-+ remote_urls->nr == 1) {
-+ remote_url = remote_urls->items[0].string;
++ 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);
+ /*
+ * sync_submodule() stores a relative URL in the superproject's
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+{
+ int i;
+
-+ if (!s->check_submodule_urls || s->ignore_submodule_arg)
++ if (s->ignore_submodule_arg &&
++ !strcmp(s->ignore_submodule_arg, "all"))
+ return;
+
+ if (is_gitmodules_unmerged(s->repo->index))
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ for (i = 0; i < s->repo->index->cache_nr; i++) {
+ struct cache_entry *ce = s->repo->index->cache[i];
+ const struct submodule *sub;
-+ char *config_url;
++ const char *config_url;
+ char *key, *gitmodules_url;
+
+ if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ continue;
+
+ key = xstrfmt("submodule.%s.url", sub->name);
-+ if (repo_config_get_string(s->repo, key, &config_url)) {
++ if (repo_config_get_value(s->repo, key, &config_url) || !config_url) {
+ free(key);
+ continue;
+ }
@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
+ "than in .gitmodules\n"
+ " run 'git submodule sync' to update it"), ce->name);
+
-+ free(config_url);
+ free(gitmodules_url);
+ }
+}
--
gitgitgadget
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v4 1/3] submodule: move URL helpers into submodule.c
2026-11-28 16:53 ` [PATCH v4 0/3] " Alessio Attilio via GitGitGadget
@ 2026-11-28 16:53 ` 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-28 16:53 ` [PATCH v4 3/3] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2 siblings, 1 reply; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-28 16:53 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
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. This lets other
callers reuse the helpers.
Return non-relative URLs unchanged before consulting remote
configuration, so the resolver handles every URL form itself.
Keep the repository parameter change for the next patch.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
builtin/submodule--helper.c | 60 +++++--------------------------------
submodule.c | 50 +++++++++++++++++++++++++++++++
submodule.h | 2 ++
3 files changed, 59 insertions(+), 53 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 461b682d0d..cc84968bd3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -46,35 +46,6 @@
typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
void *cb_data);
-static char *get_default_remote(void)
-{
- return xstrdup(repo_default_remote(the_repository));
-}
-
-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
-{
- char *remoteurl, *resolved_url;
- char *remote = get_default_remote();
- struct strbuf remotesb = STRBUF_INIT;
-
- strbuf_addf(&remotesb, "remote.%s.url", remote);
- if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
- if (!quiet)
- warning(_("could not look up configuration '%s'. "
- "Assuming this repository is its own "
- "authoritative upstream."),
- remotesb.buf);
- remoteurl = xgetcwd();
- }
- resolved_url = relative_url(remoteurl, rel_url, up_path);
-
- free(remote);
- free(remoteurl);
- strbuf_release(&remotesb);
-
- return resolved_url;
-}
-
static int get_default_remote_submodule(const char *module_path, char **default_remote)
{
const struct submodule *sub;
@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 1);
+ url = resolve_submodule_url(oldurl, NULL, 1);
free(oldurl);
}
}
@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)
*list = active_modules;
}
-static char *get_up_path(const char *path)
-{
- struct strbuf sb = STRBUF_INIT;
-
- strbuf_addstrings(&sb, "../", count_slashes(path));
-
- /*
- * Check if 'path' ends with slash or not
- * for having the same output for dir/sub_dir
- * and dir/sub_dir/
- */
- if (!is_dir_sep(path[strlen(path) - 1]))
- strbuf_addstr(&sb, "../");
-
- return strbuf_detach(&sb, NULL);
-}
-
static void for_each_listed_submodule(const struct module_list *list,
each_submodule_fn fn, void *cb_data)
{
@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_relative_url(oldurl, NULL, 0);
+ url = resolve_submodule_url(oldurl, NULL, 0);
free(oldurl);
}
@@ -1453,10 +1407,10 @@ static void sync_submodule(const char *path, const char *prefix,
if (sub && sub->url) {
if (starts_with_dot_dot_slash(sub->url) ||
starts_with_dot_slash(sub->url)) {
- char *up_path = get_up_path(path);
+ char *up_path = get_submodule_up_path(path);
- sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
- super_config_url = resolve_relative_url(sub->url, NULL, 1);
+ sub_origin_url = resolve_submodule_url(sub->url, up_path, 1);
+ super_config_url = resolve_submodule_url(sub->url, NULL, 1);
free(up_path);
} else {
sub_origin_url = xstrdup(sub->url);
@@ -2334,7 +2288,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
if (sub->url && (starts_with_dot_slash(sub->url) ||
starts_with_dot_dot_slash(sub->url))) {
- url = resolve_relative_url(sub->url, NULL, 0);
+ url = resolve_submodule_url(sub->url, NULL, 0);
need_free_url = 1;
} else
url = sub->url;
@@ -3761,7 +3715,7 @@ static int module_add(int argc, const char **argv, const char *prefix,
"of the working tree"));
/* dereference source url relative to parent's url */
- to_free = resolve_relative_url(add_data.repo, NULL, 1);
+ to_free = resolve_submodule_url(add_data.repo, NULL, 1);
add_data.realrepo = to_free;
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
add_data.realrepo = add_data.repo;
diff --git a/submodule.c b/submodule.c
index a74d1925aa..9b7bb5c2f3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -292,6 +292,56 @@ int is_submodule_active(struct repository *repo, const char *path)
return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
}
+static char *get_default_remote(void)
+{
+ return xstrdup(repo_default_remote(the_repository));
+}
+
+char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)
+{
+ char *remoteurl, *resolved_url;
+ char *remote;
+ struct strbuf remotesb = STRBUF_INIT;
+
+ if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
+ return xstrdup(rel_url);
+
+ remote = get_default_remote();
+ strbuf_addf(&remotesb, "remote.%s.url", remote);
+ if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
+ if (!quiet)
+ warning(_("could not look up configuration '%s'. "
+ "Assuming this repository is its own "
+ "authoritative upstream."),
+ remotesb.buf);
+ remoteurl = xgetcwd();
+ }
+ resolved_url = relative_url(remoteurl, rel_url, up_path);
+
+ free(remote);
+ free(remoteurl);
+ strbuf_release(&remotesb);
+
+ return resolved_url;
+}
+
+char *get_submodule_up_path(const char *path)
+{
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_addstrings(&sb, "../", count_slashes(path));
+
+ /*
+ * Check if 'path' ends with slash or not
+ * for having the same output for dir/sub_dir
+ * and dir/sub_dir/
+ */
+ if (!is_dir_sep(path[strlen(path) - 1]))
+ strbuf_addstr(&sb, "../");
+
+ return strbuf_detach(&sb, NULL);
+}
+
int is_submodule_populated_gently(const char *path, int *return_error_code)
{
int ret = 0;
diff --git a/submodule.h b/submodule.h
index 1a465a1208..82972781b4 100644
--- a/submodule.h
+++ b/submodule.h
@@ -62,6 +62,8 @@ int is_tree_submodule_active(struct repository *repo,
const struct object_id *treeish_name,
const char *path);
int is_submodule_active(struct repository *repo, const char *path);
+char *resolve_submodule_url(const char *url, const char *up_path, int quiet);
+char *get_submodule_up_path(const char *path);
/*
* Determine if a submodule has been populated at a given 'path' by checking if
* the <path>/.git resolves to a valid git repository.
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v4 2/3] submodule: make URL resolution repository-aware
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-28 16:53 ` 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
2 siblings, 1 reply; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-28 16:53 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
Pass the repository explicitly to resolve_submodule_url() instead
of relying on the_repository, and update existing callers. Resolve
relative URLs against the repository worktree when no default
remote URL is configured.
Keep this API change separate from moving the helpers. The
non-relative URL fast path is established in the preparatory
patch and remains independent of repository lookup.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
builtin/submodule--helper.c | 12 ++++++------
submodule.c | 23 +++++++++--------------
submodule.h | 12 +++++++++++-
3 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index cc84968bd3..a05372bae8 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -63,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_submodule_url(oldurl, NULL, 1);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 1);
free(oldurl);
}
}
@@ -577,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,
starts_with_dot_slash(url)) {
char *oldurl = url;
- url = resolve_submodule_url(oldurl, NULL, 0);
+ url = resolve_submodule_url(the_repository, oldurl, NULL, 0);
free(oldurl);
}
@@ -1409,8 +1409,8 @@ static void sync_submodule(const char *path, const char *prefix,
starts_with_dot_slash(sub->url)) {
char *up_path = get_submodule_up_path(path);
- sub_origin_url = resolve_submodule_url(sub->url, up_path, 1);
- super_config_url = resolve_submodule_url(sub->url, NULL, 1);
+ sub_origin_url = resolve_submodule_url(the_repository, sub->url, up_path, 1);
+ super_config_url = resolve_submodule_url(the_repository, sub->url, NULL, 1);
free(up_path);
} else {
sub_origin_url = xstrdup(sub->url);
@@ -2288,7 +2288,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
if (sub->url && (starts_with_dot_slash(sub->url) ||
starts_with_dot_dot_slash(sub->url))) {
- url = resolve_submodule_url(sub->url, NULL, 0);
+ url = resolve_submodule_url(the_repository, sub->url, NULL, 0);
need_free_url = 1;
} else
url = sub->url;
@@ -3715,7 +3715,7 @@ static int module_add(int argc, const char **argv, const char *prefix,
"of the working tree"));
/* dereference source url relative to parent's url */
- to_free = resolve_submodule_url(add_data.repo, NULL, 1);
+ to_free = resolve_submodule_url(the_repository, add_data.repo, NULL, 1);
add_data.realrepo = to_free;
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
add_data.realrepo = add_data.repo;
diff --git a/submodule.c b/submodule.c
index 9b7bb5c2f3..c8d95538d0 100644
--- a/submodule.c
+++ b/submodule.c
@@ -292,33 +292,28 @@ int is_submodule_active(struct repository *repo, const char *path)
return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
}
-static char *get_default_remote(void)
-{
- return xstrdup(repo_default_remote(the_repository));
-}
-
-char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)
+char *resolve_submodule_url(struct repository *repo, const char *url,
+ const char *up_path, int quiet)
{
char *remoteurl, *resolved_url;
- char *remote;
+ const char *remote;
struct strbuf remotesb = STRBUF_INIT;
- if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
- return xstrdup(rel_url);
+ if (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))
+ return xstrdup(url);
- remote = get_default_remote();
+ remote = repo_default_remote(repo);
strbuf_addf(&remotesb, "remote.%s.url", remote);
- if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
+ if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
if (!quiet)
warning(_("could not look up configuration '%s'. "
"Assuming this repository is its own "
"authoritative upstream."),
remotesb.buf);
- remoteurl = xgetcwd();
+ remoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd();
}
- resolved_url = relative_url(remoteurl, rel_url, up_path);
+ resolved_url = relative_url(remoteurl, url, up_path);
- free(remote);
free(remoteurl);
strbuf_release(&remotesb);
diff --git a/submodule.h b/submodule.h
index 82972781b4..477091cd3c 100644
--- a/submodule.h
+++ b/submodule.h
@@ -62,7 +62,17 @@ int is_tree_submodule_active(struct repository *repo,
const struct object_id *treeish_name,
const char *path);
int is_submodule_active(struct repository *repo, const char *path);
-char *resolve_submodule_url(const char *url, const char *up_path, int quiet);
+/*
+ * Resolve a relative submodule URL against the superproject's default remote.
+ * 'url' must be non-NULL; 'up_path' may be NULL. The caller must free the
+ * returned string.
+ */
+char *resolve_submodule_url(struct repository *repo, const char *url,
+ const char *up_path, int quiet);
+/*
+ * Return the path prefix from a submodule back to its superproject. 'path'
+ * must be non-NULL and non-empty. The caller must free the returned string.
+ */
char *get_submodule_up_path(const char *path);
/*
* Determine if a submodule has been populated at a given 'path' by checking if
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v4 3/3] status: report when submodule URLs are out of sync
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-28 16:53 ` [PATCH v4 2/3] submodule: make URL resolution repository-aware Alessio Attilio via GitGitGadget
@ 2026-11-28 16:53 ` Alessio Attilio via GitGitGadget
2026-11-29 15:42 ` Junio C Hamano
2 siblings, 1 reply; 21+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-28 16:53 UTC (permalink / raw)
To: git; +Cc: Alessio Attilio, Alessio Attilio
From: Alessio Attilio <attilio.alessio@protonmail.com>
When the URL in .gitmodules differs from the cached URL in the
superproject config, git status can help users discover that
submodule operations may use a stale location. Resolve relative
URLs the same way as git submodule sync does.
For populated submodules, compare the default remote URL as well.
If it matches neither the cached URL nor the newly declared URL,
treat it as a local customization and do not suggest a sync that
would overwrite it. Multiple remote URLs are also treated as a
customization.
Emit the warning on standard error for long, short, and porcelain
formats. Respect pathspecs and suppress the check only when
--ignore-submodules=all (or its bare form) is given. Run the check
only for git status, not other users of the wt-status machinery.
Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
Documentation/git-status.adoc | 12 ++++
builtin/commit.c | 1 +
t/t7508-status.sh | 100 ++++++++++++++++++++++++++++
wt-status.c | 120 ++++++++++++++++++++++++++++++++++
wt-status.h | 1 +
5 files changed, 234 insertions(+)
diff --git a/Documentation/git-status.adoc b/Documentation/git-status.adoc
index 9acca52bfb..6e997fbef0 100644
--- a/Documentation/git-status.adoc
+++ b/Documentation/git-status.adoc
@@ -22,6 +22,18 @@ are what you _would_ commit by running `git commit`; the second and
third are what you _could_ commit by running `git add` before running
`git commit`.
+When a submodule's URL in `.gitmodules` differs from the URL cached in
+`.git/config`, `git status` warns that `git submodule sync` can update the
+cached URL. For a populated submodule, the warning is suppressed when its
+default remote URL differs from both URLs, since syncing would overwrite a
+customized remote. Relative URLs are resolved as `git submodule sync`
+resolves them.
+
+The warning is written to standard error in long, short, and porcelain
+formats, and is limited to submodules matched by the pathspec. It is
+suppressed when `--ignore-submodules` or `--ignore-submodules=all` is
+specified.
+
OPTIONS
-------
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;
s.verbose = verbose;
if (no_renames != -1)
s.detect_rename = !no_renames;
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e10c961268..ce85920380 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -921,6 +921,106 @@ 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_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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super config -f .gitmodules submodule.module.url \
+ "$PWD/url-test/updated-source" &&
+ git -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ cat >url-test/editor <<\EOF &&
+#!/bin/sh
+echo "status test commit" >"$1"
+EOF
+ chmod +x url-test/editor &&
+ echo staged >url-test/super/staged &&
+ git -C url-test/super add staged &&
+ test_set_editor "$PWD/url-test/editor" &&
+ git -C url-test/super commit >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status --short >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --ignore-submodules=none >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --ignore-submodules=dirty >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status --ignore-submodules=all >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super status -- module >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ test_grep "git submodule sync" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/super config -f .gitmodules submodule.module.url \
+ ../another-relative-source &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err &&
+ git -C url-test/super submodule sync &&
+ git -C url-test/super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/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 >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err
+'
+
+test_expect_success 'status compares relative submodule URLs only once' '
+ test_when_finished "rm -rf url-test" &&
+ test_create_repo url-test/relative-source &&
+ test_commit -C url-test/relative-source initial &&
+ test_create_repo url-test/relative-super &&
+ git -C url-test/relative-super -c protocol.file.allow=always \
+ submodule add "$PWD/url-test/relative-source" module &&
+ git -C url-test/relative-super commit -m "add submodule" &&
+ git -C url-test/relative-super remote add origin ../a/b &&
+ git -C url-test/relative-super config -f .gitmodules \
+ submodule.module.url ../mod1 &&
+ git -C url-test/relative-super submodule sync &&
+ git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
+ test_must_be_empty url-test/err &&
+ git -C url-test/relative-super config -f .gitmodules \
+ submodule.module.url ../mod2 &&
+ git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
+ test_grep "module.*different URL" url-test/err
+'
+
test_expect_success 'status submodule summary is disabled by default' '
cat >expect <<EOF &&
On branch main
diff --git a/wt-status.c b/wt-status.c
index 238bb48643..84fb985a4e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -3,6 +3,8 @@
#include "git-compat-util.h"
#include "advice.h"
+#include "abspath.h"
+#include "config.h"
#include "wt-status.h"
#include "object.h"
#include "dir.h"
@@ -23,6 +25,8 @@
#include "remote.h"
#include "refs.h"
#include "submodule.h"
+#include "url.h"
+#include "submodule-config.h"
#include "column.h"
#include "read-cache.h"
#include "setup.h"
@@ -2692,8 +2696,124 @@ 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 *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)) {
+ up_path = get_submodule_up_path(path);
+ /*
+ * sync_submodule() stores a relative URL in the superproject's
+ * config without the submodule path prefix, but adds that prefix
+ * when storing the URL in the submodule's remote configuration.
+ */
+ if (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {
+ struct strbuf sb = STRBUF_INIT;
+
+ strbuf_addstr(&sb, up_path);
+ strbuf_addstr(&sb, config_url);
+ config_remote_url = strbuf_detach(&sb, NULL);
+ } else {
+ config_remote_url = xstrdup(config_url);
+ }
+ gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
+ up_path, 1);
+ /*
+ * The submodule's remote URL may be a local fork. If it matches
+ * neither the old cached URL nor the new .gitmodules URL, leave it
+ * alone; syncing would overwrite that customization.
+ */
+ ret = strcmp(remote_url, config_remote_url) != 0 &&
+ strcmp(remote_url, gitmodules_remote_url) != 0;
+ free(gitmodules_remote_url);
+ free(config_remote_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->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];
+ const struct submodule *sub;
+ const char *config_url;
+ char *key, *gitmodules_url;
+
+ if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||
+ !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))
+ 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, &config_url) || !config_url) {
+ free(key);
+ continue;
+ }
+ free(key);
+
+ gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);
+ if (strcmp(config_url, gitmodules_url) &&
+ !submodule_has_custom_remote_url(s->repo, ce->name,
+ sub->url,
+ config_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(gitmodules_url);
+ }
+}
+
void wt_status_print(struct wt_status *s)
{
+ if (s->check_submodule_urls)
+ 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);
diff --git a/wt-status.h b/wt-status.h
index e9fe32e98c..45eeb8b558 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -123,6 +123,7 @@ struct wt_status {
unsigned colopts;
int null_termination;
int commit_template;
+ int check_submodule_urls;
int show_branch;
int show_stash;
int hints;
--
gitgitgadget
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v4 3/3] status: report when submodule URLs are out of sync
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
0 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2026-11-29 15:42 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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.
> 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.
> +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.
> +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.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/2] status: warn about stale submodule URLs
2026-11-27 18:11 ` Junio C Hamano
2026-11-27 20:35 ` ATTILIO ALESSIO
@ 2026-11-30 15:46 ` D. Ben Knoble
1 sibling, 0 replies; 21+ messages in thread
From: D. Ben Knoble @ 2026-11-30 15:46 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Alessio Attilio via GitGitGadget, git, Alessio Attilio
On Fri, Nov 27, 2026 at 1:12 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Alessio Attilio <attilio.alessio@protonmail.com>
> >
> > When a submodule URL changes in .gitmodules, the cached
> > submodule.<name>.url in the superproject config can stay stale. Warn
> > in git status so users can run git submodule sync before a later
> > submodule operation uses the outdated URL.
> >
> > Resolve relative URLs using the same paths as git submodule sync.
> > Avoid warning when the submodule remote indicates a local
> > customization that sync would overwrite.
> >
> > Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
> > ---
>
> Surfacing stale submodule configuration in "git status" is a very useful
> improvement. Like Ben noted, splitting the helper extraction out into a
> preparatory commit made the series easier to follow.
>
> It would help to explain in the proposed log message why three URLs are
> compared and under what condition, and which status formats emit the
> warning.
Indeed, I was minded of "reviewing is a discussion"
(https://lore.kernel.org/git/20261022211404.380904-3-gitster@pobox.com/)
and "good manners" being to discuss before sending off v2
(https://lore.kernel.org/git/xmqqmrquetqq.fsf@gitster.g/).
> > + up_path = get_submodule_up_path(path);
> > + config_remote_url = resolve_submodule_url(repo, config_url,
> > + up_path, 1);
> > + gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
> > + up_path, 1);
> > + /*
> > + * The submodule's remote URL may be a local fork. If it matches
> > + * neither the old cached URL nor the new .gitmodules URL, leave it
> > + * alone; syncing would overwrite that customization.
> > + */
> > + ret = strcmp(remote_url, config_remote_url) != 0 &&
> > + strcmp(remote_url, gitmodules_remote_url) != 0;
>
> Renaming of new/old may address one of the points of confusion Ben had.
I think so: it now seems that "remote_url" is the one from the
submodule (e.g., git -C sub remote -v), config_*url is the cached URL,
and gitmodules_*url is, well, the .gitmodules URL.
> When the superproject's own default remote URL is relative, doesn't
> this logic break?
>
> In wt_status_check_submodule_urls() we see below, 'gitmodules_url' was
> already computed by resolving sub->url against the superproject's
> default remote with 'up_path' set to NULL. Likewise, 'config_url' from
> submodule.<name>.url in .git/config was already resolved once with
> 'up_path' set to NULL when init_submodule() or sync_submodule() wrote
> it.
>
> Passing already-resolved URLs into resolve_submodule_url() again smells
> fishy. There are a few ways I can think of that this can break. I may
> be misreading the code flow, and these may be no issue, or there may be
> other issues.
I mentioned the double-resolution in passing before, thanks for making
the potential issues (which I only thought of for performance) more
explicit.
> * When the superproject has "remote.origin.url = a/b" (relative without
> "./" or "../") and .gitmodules has "../mod1", sync_submodule() stores
> "a/mod1" in submodule.module.url and "../a/mod1" in the submodule's
> remote.origin.url.
>
> submodule_has_custom_remote_url() calls resolve_submodule_url() on
> "a/mod1". It hits the early return without prepending 'up_path', so
> 'config_remote_url' is "a/mod1" instead of "../a/mod1" and fails to
> match.
>
> * When the superproject has "remote.origin.url = ../a/b", .gitmodules
> initially has "submodule.module.url = ../mod1", and the user runs
> "git submodule sync". In sync_submodule(), relative_url() stores
> "../a/mod1" in submodule.module.url and "../../a/mod1" in the
> submodule's remote.origin.url.
>
> If submodule.module.url in .gitmodules then changes to "../mod2",
> wt_status_check_submodule_urls() sets 'gitmodules_remote_url' to
> "../a/mod2". Inside submodule_has_custom_remote_url(), both
> "../a/mod1" and "../a/mod2" still start with "../", so
> resolve_submodule_url() resolves them a second time against "../a/b".
>
> Wouldn't the result be "../../a/a/mod1" and "../../a/a/mod2" in such
> a case?
>
> Neither matches "../../a/mod1", so submodule_has_custom_remote_url()
> returns 1 and suppresses the warning even though the submodule remote
> was never customized. The new test in t7508 used "../source-parent"
> with only one path component after "..", where the second resolution
> happened to be a no-op, so it may not have noticed the breakage.
>
> In order to match what sync_submodule() does, 'gitmodules_remote_url'
> should be computed from the raw 'sub->url', not from 'gitmodules_url',
> no? For 'config_remote_url', we do not want to run relative_url() again
> on 'config_url', I think. You only need to prepend 'up_path', or
> something, no? I didn't think this one through, so take it with a huge
> grain of salt.
Thanks,
Ben
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 1/3] submodule: move URL helpers into submodule.c
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
0 siblings, 0 replies; 21+ messages in thread
From: D. Ben Knoble @ 2026-11-30 15:54 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
Hi Alessio,
On Sat, Nov 28, 2026 at 11:53 AM Alessio Attilio via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Alessio Attilio <attilio.alessio@protonmail.com>
>
> 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. This lets other
> callers reuse the helpers.
>
> Return non-relative URLs unchanged before consulting remote
> configuration, so the resolver handles every URL form itself.
> Keep the repository parameter change for the next patch.
This comment applies to [2/3] also: it is normal to explain a
preparatory commit by discussing what it prepares for ("lets other
callers reuse the helpers"), but I find the sentence "Keep the
repository parameter change for the next patch" very unusual.
A future reader must wonder: what change? (And why "the change"?) The
answers only make sense in context of prior iterations, not
necessarily in context of the final commits upstream.
I would rephrase (or drop that line altogether):
We also want to make these helpers repository-aware, but do that
in a later step to make it easy to see the code movement.
perhaps?
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v4 2/3] submodule: make URL resolution repository-aware
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
0 siblings, 0 replies; 21+ messages in thread
From: D. Ben Knoble @ 2026-11-30 15:56 UTC (permalink / raw)
To: Alessio Attilio via GitGitGadget; +Cc: git, Alessio Attilio
On Sat, Nov 28, 2026 at 11:54 AM Alessio Attilio via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Alessio Attilio <attilio.alessio@protonmail.com>
>
> Pass the repository explicitly to resolve_submodule_url() instead
> of relying on the_repository, and update existing callers. Resolve
> relative URLs against the repository worktree when no default
> remote URL is configured.
>
> Keep this API change separate from moving the helpers. The
> non-relative URL fast path is established in the preparatory
> patch and remains independent of repository lookup.
This is the paragraph in [2/3] that corresponds to the unusual
sentence in [1/3]. These would make fine "changes" notes on the commit
or cover letter, but this paragraph especially doesn't belong in the
proposed log message.
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2026-11-30 15:56 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox