From: Alessio Attilio via GitGitGadget Date: Tue, 01 Dec 2026 21:08:56 GMT Subject: [PATCH v5 2/4] status: warn about submodule URL mismatches Message-ID: <6db7dc9415227488ddf422d35802a7c9569ddfa5.1796159338.git.gitgitgadget@gmail.com> In-Reply-To: From: Alessio Attilio When a user changes a URL in .gitmodules, the cached URL in .git/config can remain stale and status looks clean. Compare active declarations with cached URLs while printing status; honor pathspec and ignore options. Signed-off-by: Alessio Attilio --- builtin/commit.c | 1 + wt-status.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ wt-status.h | 1 + 3 files changed, 56 insertions(+) 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/wt-status.c b/wt-status.c index 238bb48643..bbd0e082dc 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,58 @@ static void wt_porcelain_v2_print(struct wt_status *s) } } +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; + + /* + * Sparse-index directories containing gitlinks are not collapsed, so + * every gitlink remains visible in this cache iteration. + */ + 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)) + 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