{"thread":{"id":"66944","subject":"[PATCH] status: warn about stale submodule URLs","startedAt":"2026-11-27T10:21:20Z","lastAt":"2026-12-01T21:08:58Z","messageCount":26,"participants":["Alessio Attilio via GitGitGadget","D. Ben Knoble","Junio C Hamano","ATTILIO ALESSIO"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559519","messageId":"pull.2509.git.git.1795774880142.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":null,"subject":"[PATCH] status: warn about stale submodule URLs","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-27T10:21:20Z","receivedAt":"2026-11-27T10:21:20Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nWhen a submodule URL changes in .gitmodules, the URL cached in\n.git/config can keep pointing at the old remote. That leaves users\nwith no indication that later submodule operations may use a\nrepository different from the one the project declares.\n\nWarn in git status so users can find and sync stale configuration\nbefore it causes a confusing fetch or update. Resolve relative URLs\nlike git submodule sync does, and leave customized submodule remotes\nalone.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n    status: report when submodule URLs are out of sync\n    \n    Closes gitgitgadget/git#565\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v1\nPull-Request: https://github.com/git/git/pull/2509\n\n builtin/submodule--helper.c | 63 ++++--------------------\n submodule.c                 | 44 +++++++++++++++++\n submodule.h                 |  3 ++\n t/t7508-status.sh           | 55 +++++++++++++++++++++\n wt-status.c                 | 97 +++++++++++++++++++++++++++++++++++++\n 5 files changed, 209 insertions(+), 53 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 461b682d0d..5f293d9dfd 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -46,35 +46,6 @@\n typedef void (*each_submodule_fn)(const struct cache_entry *list_item,\n \t\t\t\t  void *cb_data);\n \n-static char *get_default_remote(void)\n-{\n-\treturn xstrdup(repo_default_remote(the_repository));\n-}\n-\n-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)\n-{\n-\tchar *remoteurl, *resolved_url;\n-\tchar *remote = get_default_remote();\n-\tstruct strbuf remotesb = STRBUF_INIT;\n-\n-\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n-\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n-\t\tif (!quiet)\n-\t\t\twarning(_(\"could not look up configuration '%s'. \"\n-\t\t\t\t  \"Assuming this repository is its own \"\n-\t\t\t\t  \"authoritative upstream.\"),\n-\t\t\t\tremotesb.buf);\n-\t\tremoteurl = xgetcwd();\n-\t}\n-\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n-\n-\tfree(remote);\n-\tfree(remoteurl);\n-\tstrbuf_release(&remotesb);\n-\n-\treturn resolved_url;\n-}\n-\n static int get_default_remote_submodule(const char *module_path, char **default_remote)\n {\n \tconst struct submodule *sub;\n@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 1);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 1);\n \t\t\tfree(oldurl);\n \t\t}\n \t}\n@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)\n \t*list = active_modules;\n }\n \n-static char *get_up_path(const char *path)\n-{\n-\tstruct strbuf sb = STRBUF_INIT;\n-\n-\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n-\n-\t/*\n-\t * Check if 'path' ends with slash or not\n-\t * for having the same output for dir/sub_dir\n-\t * and dir/sub_dir/\n-\t */\n-\tif (!is_dir_sep(path[strlen(path) - 1]))\n-\t\tstrbuf_addstr(&sb, \"../\");\n-\n-\treturn strbuf_detach(&sb, NULL);\n-}\n-\n static void for_each_listed_submodule(const struct module_list *list,\n \t\t\t\t      each_submodule_fn fn, void *cb_data)\n {\n@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 0);\n \t\t\tfree(oldurl);\n \t\t}\n \n@@ -1453,10 +1407,12 @@ static void sync_submodule(const char *path, const char *prefix,\n \tif (sub && sub->url) {\n \t\tif (starts_with_dot_dot_slash(sub->url) ||\n \t\t    starts_with_dot_slash(sub->url)) {\n-\t\t\tchar *up_path = get_up_path(path);\n+\t\t\tchar *up_path = get_submodule_up_path(path);\n \n-\t\t\tsub_origin_url = resolve_relative_url(sub->url, up_path, 1);\n-\t\t\tsuper_config_url = resolve_relative_url(sub->url, NULL, 1);\n+\t\t\tsub_origin_url = resolve_submodule_url(the_repository, sub->url,\n+\t\t\t\t\t\t\t      up_path, 1);\n+\t\t\tsuper_config_url = resolve_submodule_url(the_repository,\n+\t\t\t\t\t\t\t\t sub->url, NULL, 1);\n \t\t\tfree(up_path);\n \t\t} else {\n \t\t\tsub_origin_url = xstrdup(sub->url);\n@@ -2334,7 +2290,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \tif (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {\n \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n-\t\t\turl = resolve_relative_url(sub->url, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, sub->url, NULL, 0);\n \t\t\tneed_free_url = 1;\n \t\t} else\n \t\t\turl = sub->url;\n@@ -3761,7 +3717,8 @@ static int module_add(int argc, const char **argv, const char *prefix,\n \t\t\t      \"of the working tree\"));\n \n \t\t/* dereference source url relative to parent's url */\n-\t\tto_free = resolve_relative_url(add_data.repo, NULL, 1);\n+\t\tto_free = resolve_submodule_url(the_repository, add_data.repo,\n+\t\t\t\t\t\tNULL, 1);\n \t\tadd_data.realrepo = to_free;\n \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n \t\tadd_data.realrepo = add_data.repo;\ndiff --git a/submodule.c b/submodule.c\nindex a74d1925aa..5d0018d032 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -292,6 +292,50 @@ int is_submodule_active(struct repository *repo, const char *path)\n \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n }\n \n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet)\n+{\n+\tconst char *remote = repo_default_remote(repo);\n+\tchar *remoteurl, *resolved_url;\n+\tstruct strbuf remotesb = STRBUF_INIT;\n+\n+\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n+\t\treturn xstrdup(url);\n+\n+\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n+\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n+\t\tif (!quiet)\n+\t\t\twarning(_(\"could not look up configuration '%s'. \"\n+\t\t\t\t  \"Assuming this repository is its own \"\n+\t\t\t\t  \"authoritative upstream.\"),\n+\t\t\t\tremotesb.buf);\n+\t\tremoteurl = xgetcwd();\n+\t}\n+\tresolved_url = relative_url(remoteurl, url, up_path);\n+\n+\tfree(remoteurl);\n+\tstrbuf_release(&remotesb);\n+\n+\treturn resolved_url;\n+}\n+\n+char *get_submodule_up_path(const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n+\n+\t/*\n+\t * Check if 'path' ends with slash or not\n+\t * for having the same output for dir/sub_dir\n+\t * and dir/sub_dir/\n+\t */\n+\tif (!is_dir_sep(path[strlen(path) - 1]))\n+\t\tstrbuf_addstr(&sb, \"../\");\n+\n+\treturn strbuf_detach(&sb, NULL);\n+}\n+\n int is_submodule_populated_gently(const char *path, int *return_error_code)\n {\n \tint ret = 0;\ndiff --git a/submodule.h b/submodule.h\nindex 1a465a1208..2028f272c4 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,\n \t\t\t     const struct object_id *treeish_name,\n \t\t\t     const char *path);\n int is_submodule_active(struct repository *repo, const char *path);\n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet);\n+char *get_submodule_up_path(const char *path);\n /*\n  * Determine if a submodule has been populated at a given 'path' by checking if\n  * the <path>/.git resolves to a valid git repository.\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..bf28de1907 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -921,6 +921,61 @@ test_expect_success 'setup status submodule summary' '\n \tgit add sm\n '\n \n+test_expect_success 'status reports submodule URL mismatch' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_when_finished \"rm -f actual err\" &&\n+\ttest_create_repo url-test/source &&\n+\ttest_commit -C url-test/source initial &&\n+\ttest_create_repo url-test/super &&\n+\tgit -C url-test/super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/source\" module &&\n+\tgit -C url-test/super commit -m \"add submodule\" &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t\"$PWD/url-test/updated-source\" &&\n+\tgit -C url-test/super status --porcelain >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_grep \"module.*different URL\" err &&\n+\ttest_grep \"git submodule sync\" err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\tgit -C url-test/super remote add origin ../source-parent &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../relative-source &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_grep \"module.*different URL\" err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-relative-source &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_grep \"module.*different URL\" err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\tgit -C url-test/super/module config remote.origin.url \\\n+\t\t\"$PWD/url-test/fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../fork-source &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\tgit -C url-test/super/module config --add remote.origin.url \\\n+\t\t\"$PWD/url-test/another-fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-fork-source &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_must_be_empty err &&\n+\tgit -C url-test/super/module config --unset-all remote.origin.url &&\n+\tgit -C url-test/super config --add submodule.module.url \\\n+\t\t\"$PWD/url-test/another-configured-source\" &&\n+\tgit -C url-test/super status >actual 2>err &&\n+\ttest_grep \"module.*different URL\" err\n+'\n+\n test_expect_success 'status submodule summary is disabled by default' '\n \tcat >expect <<EOF &&\n On branch main\ndiff --git a/wt-status.c b/wt-status.c\nindex 238bb48643..e06c18d8e0 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -3,6 +3,7 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n+#include \"config.h\"\n #include \"wt-status.h\"\n #include \"object.h\"\n #include \"dir.h\"\n@@ -23,6 +24,7 @@\n #include \"remote.h\"\n #include \"refs.h\"\n #include \"submodule.h\"\n+#include \"submodule-config.h\"\n #include \"column.h\"\n #include \"read-cache.h\"\n #include \"setup.h\"\n@@ -2692,8 +2694,103 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n \t}\n }\n \n+static int submodule_has_custom_remote_url(struct repository *repo,\n+\t\t\t\t\t  const char *path,\n+\t\t\t\t\t  const char *url,\n+\t\t\t\t\t  const char *configured_url)\n+{\n+\tstruct repository subrepo = { 0 };\n+\tconst struct string_list *remote_urls = NULL;\n+\tconst char *remote;\n+\tconst char *remote_url;\n+\tchar *key, *up_path, *old_url, *new_url;\n+\tint error_code, ret = 0;\n+\n+\tif (!is_submodule_populated_gently(path, &error_code))\n+\t\treturn 0;\n+\n+\tif (repo_submodule_init(&subrepo, repo, path,\n+\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n+\t\trepo_clear(&subrepo);\n+\t\treturn 0;\n+\t}\n+\n+\tremote = repo_default_remote(&subrepo);\n+\n+\tkey = xstrfmt(\"remote.%s.url\", remote);\n+\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n+\t    remote_urls->nr == 1) {\n+\t\tremote_url = remote_urls->items[0].string;\n+\t\tup_path = get_submodule_up_path(path);\n+\t\told_url = resolve_submodule_url(repo, configured_url, up_path, 1);\n+\t\tnew_url = resolve_submodule_url(repo, url, up_path, 1);\n+\t\tret = strcmp(remote_url, old_url) != 0 &&\n+\t\t\tstrcmp(remote_url, new_url) != 0;\n+\t\tfree(new_url);\n+\t\tfree(old_url);\n+\t\tfree(up_path);\n+\t} else {\n+\t\t/*\n+\t\t * Multiple URLs are a local customization; sync would replace\n+\t\t * them all with a single URL.\n+\t\t */\n+\t\tret = remote_urls && remote_urls->nr > 1;\n+\t}\n+\tfree(key);\n+\trepo_clear(&subrepo);\n+\n+\treturn ret;\n+}\n+\n+static void wt_status_check_submodule_urls(struct wt_status *s)\n+{\n+\tint i;\n+\n+\tif (s->status_format != STATUS_FORMAT_LONG &&\n+\t    s->status_format != STATUS_FORMAT_NONE)\n+\t\treturn;\n+\n+\tif (is_gitmodules_unmerged(s->repo->index))\n+\t\treturn;\n+\n+\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n+\t\tconst struct submodule *sub;\n+\t\tconst char *configured_url;\n+\t\tchar *key, *expected_url;\n+\n+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))\n+\t\t\tcontinue;\n+\n+\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n+\t\t\t\t\t  ce->name);\n+\t\tif (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n+\t\t\tcontinue;\n+\n+\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n+\t\tif (repo_config_get_value(s->repo, key, &configured_url)) {\n+\t\t\tfree(key);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfree(key);\n+\n+\t\texpected_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n+\t\tif (strcmp(configured_url, expected_url) &&\n+\t\t    !submodule_has_custom_remote_url(s->repo, ce->name,\n+\t\t\t\t\t\t     expected_url,\n+\t\t\t\t\t\t     configured_url))\n+\t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n+\t\t\t\t  \"than in .gitmodules\\n\"\n+\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n+\n+\t\tfree(expected_url);\n+\t}\n+}\n+\n void wt_status_print(struct wt_status *s)\n {\n+\twt_status_check_submodule_urls(s);\n+\n \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n \t\t\t   s->untracked.nr);\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\n-- \ngitgitgadget\n\n"},{"id":"559526","messageId":"CALnO6CCftBcJ_QwF5UEnjYqW=fLYYjQNccUEoGXKJEX9wCG54A@mail.gmail.com","threadId":"66944","inReplyTo":"pull.2509.git.git.1795774880142.gitgitgadget@gmail.com","subject":"Re: [PATCH] status: warn about stale submodule URLs","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-11-27T13:41:32Z","receivedAt":"2026-11-27T13:41:32Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"Hi Alessio,\n\nOn Fri, Nov 27, 2026 at 5:28 AM Alessio Attilio via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Alessio Attilio <attilio.alessio@protonmail.com>\n>\n> When a submodule URL changes in .gitmodules, the URL cached in\n> .git/config can keep pointing at the old remote. That leaves users\n> with no indication that later submodule operations may use a\n> repository different from the one the project declares.\n>\n> Warn in git status so users can find and sync stale configuration\n> before it causes a confusing fetch or update. Resolve relative URLs\n> like git submodule sync does, and leave customized submodule remotes\n> alone.\n\nThis sounds like a good problem to solve, as it makes it more obvious\nwhen to run \"git submodule sync\"---especially if you don't trust one\nof the 2 URLs involved anymore!\n\n> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\n> -static char *get_default_remote(void)\n> -static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)\n> -static char *get_up_path(const char *path)\n\n> diff --git a/submodule.c b/submodule.c\n> +char *resolve_submodule_url(struct repository *repo, const char *url,\n> +                           const char *up_path, int quiet)\n> +char *get_submodule_up_path(const char *path)\n\nI am somewhat surprised to see this refactoring: at a quick glance, it\nlooks like some static functions needed to be exposed to another\ntranslation unit, but that was not explained in the proposed log\nmessage. (We also teach the URL resolver about a repository, all at\nthe same time? And I can't see where get_default_remote ended up, but\nthat's probably my skimming.)\n\nOn top of that, our usual style is to first, in a preparatory patch,\nmove code around (making it easy to see the movement), then in\nsubsequent patches make the small needed changes for a fix or feature\n(making it easy to see the isolated changes).\n\n> diff --git a/t/t7508-status.sh b/t/t7508-status.sh\n> index e10c961268..bf28de1907 100755\n> --- a/t/t7508-status.sh\n> +++ b/t/t7508-status.sh\n> @@ -921,6 +921,61 @@ test_expect_success 'setup status submodule summary' '\n>         git add sm\n>  '\n>\n> +test_expect_success 'status reports submodule URL mismatch' '\n> +       test_when_finished \"rm -rf url-test\" &&\n> +       test_when_finished \"rm -f actual err\" &&\n\nRemoving some of these files is a bit unusual, I think.\n\n> +       test_create_repo url-test/source &&\n> +       test_commit -C url-test/source initial &&\n> +       test_create_repo url-test/super &&\n> +       git -C url-test/super -c protocol.file.allow=always \\\n> +               submodule add \"$PWD/url-test/source\" module &&\n> +       git -C url-test/super commit -m \"add submodule\" &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       git -C url-test/super config -f .gitmodules submodule.module.url \\\n> +               \"$PWD/url-test/updated-source\" &&\n> +       git -C url-test/super status --porcelain >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_grep \"module.*different URL\" err &&\n> +       test_grep \"git submodule sync\" err &&\n> +       git -C url-test/super submodule sync &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       git -C url-test/super remote add origin ../source-parent &&\n> +       git -C url-test/super config -f .gitmodules submodule.module.url \\\n> +               ../relative-source &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_grep \"module.*different URL\" err &&\n> +       git -C url-test/super submodule sync &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       git -C url-test/super config -f .gitmodules submodule.module.url \\\n> +               ../another-relative-source &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_grep \"module.*different URL\" err &&\n> +       git -C url-test/super submodule sync &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       git -C url-test/super/module config remote.origin.url \\\n> +               \"$PWD/url-test/fork\" &&\n> +       git -C url-test/super config -f .gitmodules submodule.module.url \\\n> +               ../fork-source &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       git -C url-test/super/module config --add remote.origin.url \\\n> +               \"$PWD/url-test/another-fork\" &&\n> +       git -C url-test/super config -f .gitmodules submodule.module.url \\\n> +               ../another-fork-source &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_must_be_empty err &&\n> +       git -C url-test/super/module config --unset-all remote.origin.url &&\n> +       git -C url-test/super config --add submodule.module.url \\\n> +               \"$PWD/url-test/another-configured-source\" &&\n> +       git -C url-test/super status >actual 2>err &&\n> +       test_grep \"module.*different URL\" err\n> +'\n\nI did not read the test script closely, but it seems we change some\nsubmodule URLs and assert on status output, which is roughly what I'd\nexpect.\n\n> diff --git a/wt-status.c b/wt-status.c\n> index 238bb48643..e06c18d8e0 100644\n> --- a/wt-status.c\n> +++ b/wt-status.c\n> @@ -3,6 +3,7 @@\n>\n>  #include \"git-compat-util.h\"\n>  #include \"advice.h\"\n> +#include \"config.h\"\n>  #include \"wt-status.h\"\n>  #include \"object.h\"\n>  #include \"dir.h\"\n> @@ -23,6 +24,7 @@\n>  #include \"remote.h\"\n>  #include \"refs.h\"\n>  #include \"submodule.h\"\n> +#include \"submodule-config.h\"\n>  #include \"column.h\"\n>  #include \"read-cache.h\"\n>  #include \"setup.h\"\n> @@ -2692,8 +2694,103 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n>         }\n>  }\n>\n> +static int submodule_has_custom_remote_url(struct repository *repo,\n> +                                         const char *path,\n> +                                         const char *url,\n> +                                         const char *configured_url)\n> +{\n> +       struct repository subrepo = { 0 };\n> +       const struct string_list *remote_urls = NULL;\n> +       const char *remote;\n> +       const char *remote_url;\n> +       char *key, *up_path, *old_url, *new_url;\n> +       int error_code, ret = 0;\n> +\n> +       if (!is_submodule_populated_gently(path, &error_code))\n> +               return 0;\n> +\n> +       if (repo_submodule_init(&subrepo, repo, path,\n> +                               null_oid(repo->hash_algo)) < 0) {\n> +               repo_clear(&subrepo);\n> +               return 0;\n> +       }\n\nI suppose in these cases we don't actually know the answer to the\nquestion \"submodule_has_custom_remote_url\"… but I'm not sure if the\ntri-state + behaving differently is worth it for a new warning yet, so\nI'm ok with falling back to the current state of affairs for now.\n\n> +       remote = repo_default_remote(&subrepo);\n> +\n> +       key = xstrfmt(\"remote.%s.url\", remote);\n> +       if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n> +           remote_urls->nr == 1) {\n> +               remote_url = remote_urls->items[0].string;\n> +               up_path = get_submodule_up_path(path);\n> +               old_url = resolve_submodule_url(repo, configured_url, up_path, 1);\n> +               new_url = resolve_submodule_url(repo, url, up_path, 1);\n> +               ret = strcmp(remote_url, old_url) != 0 &&\n> +                       strcmp(remote_url, new_url) != 0;\n\nI'm not sure I follow this strcmp logic:\n\n* remote_url is from the submodule's config, I assume from the .git/modules/…?\n* old_url is the resolved configured_url, which reading ahead tells me\nis the superproject's config?\n* new_url is the resolved url, which reading ahead tells me is also\nfrom a pre-resolved submodule's config (aka \"expected_url\")?\n\nSo, I guess I'm actually confused about a few things:\n\n* the terminology between caller (expected/configured) and callee\ndoesn't match; consistency might help\n* the double-resolution of new_url seems odd?\n* what are the 3 URLs involved? I suppose I was expecting a comparison\nof 2, since that's what the log message describes (.gitmodules +\ncached URL in .git/config).\n\n> +               free(new_url);\n> +               free(old_url);\n> +               free(up_path);\n> +       } else {\n> +               /*\n> +                * Multiple URLs are a local customization; sync would replace\n> +                * them all with a single URL.\n> +                */\n> +               ret = remote_urls && remote_urls->nr > 1;\n> +       }\n> +       free(key);\n> +       repo_clear(&subrepo);\n> +\n> +       return ret;\n> +}\n> +\n> +static void wt_status_check_submodule_urls(struct wt_status *s)\n> +{\n> +       int i;\n> +\n> +       if (s->status_format != STATUS_FORMAT_LONG &&\n> +           s->status_format != STATUS_FORMAT_NONE)\n> +               return;\n> +\n> +       if (is_gitmodules_unmerged(s->repo->index))\n> +               return;\n> +\n> +       for (i = 0; i < s->repo->index->cache_nr; i++) {\n> +               struct cache_entry *ce = s->repo->index->cache[i];\n> +               const struct submodule *sub;\n> +               const char *configured_url;\n> +               char *key, *expected_url;\n> +\n> +               if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))\n> +                       continue;\n> +\n> +               sub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n> +                                         ce->name);\n> +               if (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n> +                       continue;\n> +\n> +               key = xstrfmt(\"submodule.%s.url\", sub->name);\n> +               if (repo_config_get_value(s->repo, key, &configured_url)) {\n> +                       free(key);\n> +                       continue;\n> +               }\n> +               free(key);\n> +\n> +               expected_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n> +               if (strcmp(configured_url, expected_url) &&\n> +                   !submodule_has_custom_remote_url(s->repo, ce->name,\n> +                                                    expected_url,\n> +                                                    configured_url))\n> +                       warning(_(\"submodule '%s' has a different URL in .git/config \"\n> +                                 \"than in .gitmodules\\n\"\n> +                                 \"  run 'git submodule sync' to update it\"), ce->name);\n> +\n> +               free(expected_url);\n> +       }\n> +}\n> +\n\nThanks\n-- \nD. Ben Knoble\n\n"},{"id":"559531","messageId":"pull.2509.v2.git.git.1795796162.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.git.git.1795774880142.gitgitgadget@gmail.com","subject":"[PATCH v2 0/2] status: report when submodule URLs are out of sync","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-27T16:16:00Z","receivedAt":"2026-11-27T16:16:00Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"When a submodule URL changes in .gitmodules, the corresponding URL in the\nsuperproject's .git/config may keep pointing at the old location. This\nseries makes git status warn about that mismatch and suggest git submodule\nsync.\n\nThe warning resolves relative URLs as git submodule sync does. It also\nsuppresses the warning when the populated submodule has a custom remote URL\nthat a sync would overwrite.\n\nThe series is split into:\n\n 1. submodule: prepare URL helpers for reuse\n 2. status: warn about stale submodule URLs\n\nChanges since v1:\n\n * Move the URL helper extraction into a preparatory commit.\n * Clarify the comparison between the cached URL, .gitmodules, and the\n   populated submodule's remote URL.\n * Keep test output inside its fixture directory.\n\nCloses gitgitgadget/git#565\n\nAlessio Attilio (2):\n  submodule: prepare URL helpers for reuse\n  status: warn about stale submodule URLs\n\n builtin/submodule--helper.c |  63 ++++------------------\n submodule.c                 |  44 +++++++++++++++\n submodule.h                 |   3 ++\n t/t7508-status.sh           |  54 +++++++++++++++++++\n wt-status.c                 | 104 ++++++++++++++++++++++++++++++++++++\n 5 files changed, 215 insertions(+), 53 deletions(-)\n\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v2\nPull-Request: https://github.com/git/git/pull/2509\n\nRange-diff vs v1:\n\n 1:  528258ee95 ! 1:  4cd0ab7e9b status: warn about stale submodule URLs\n     @@ Metadata\n      Author: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n       ## Commit message ##\n     -    status: warn about stale submodule URLs\n     +    submodule: prepare URL helpers for reuse\n      \n     -    When a submodule URL changes in .gitmodules, the URL cached in\n     -    .git/config can keep pointing at the old remote. That leaves users\n     -    with no indication that later submodule operations may use a\n     -    repository different from the one the project declares.\n     +    Move the relative submodule URL resolver and the helper that computes\n     +    the path back to the superproject from builtin/submodule--helper.c to\n     +    submodule.c so they can be shared with git status.\n      \n     -    Warn in git status so users can find and sync stale configuration\n     -    before it causes a confusing fetch or update. Resolve relative URLs\n     -    like git submodule sync does, and leave customized submodule remotes\n     -    alone.\n     +    Pass the repository explicitly to the resolver instead of relying on\n     +    the_repository, and update existing callers to use the shared helpers.\n      \n          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)\n      +\tchar *remoteurl, *resolved_url;\n      +\tstruct strbuf remotesb = STRBUF_INIT;\n      +\n     -+\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n     -+\t\treturn xstrdup(url);\n     -+\n      +\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n      +\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n      +\t\tif (!quiet)\n     @@ submodule.h: int is_tree_submodule_active(struct repository *repo,\n       /*\n        * Determine if a submodule has been populated at a given 'path' by checking if\n        * the <path>/.git resolves to a valid git repository.\n     -\n     - ## t/t7508-status.sh ##\n     -@@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n     - \tgit add sm\n     - '\n     - \n     -+test_expect_success 'status reports submodule URL mismatch' '\n     -+\ttest_when_finished \"rm -rf url-test\" &&\n     -+\ttest_when_finished \"rm -f actual err\" &&\n     -+\ttest_create_repo url-test/source &&\n     -+\ttest_commit -C url-test/source initial &&\n     -+\ttest_create_repo url-test/super &&\n     -+\tgit -C url-test/super -c protocol.file.allow=always \\\n     -+\t\tsubmodule add \"$PWD/url-test/source\" module &&\n     -+\tgit -C url-test/super commit -m \"add submodule\" &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_must_be_empty err &&\n     -+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n     -+\t\t\"$PWD/url-test/updated-source\" &&\n     -+\tgit -C url-test/super status --porcelain >actual 2>err &&\n     -+\ttest_must_be_empty err &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_grep \"module.*different URL\" err &&\n     -+\ttest_grep \"git submodule sync\" err &&\n     -+\tgit -C url-test/super submodule sync &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_must_be_empty err &&\n     -+\tgit -C url-test/super remote add origin ../source-parent &&\n     -+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n     -+\t\t../relative-source &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_grep \"module.*different URL\" err &&\n     -+\tgit -C url-test/super submodule sync &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_must_be_empty err &&\n     -+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n     -+\t\t../another-relative-source &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_grep \"module.*different URL\" err &&\n     -+\tgit -C url-test/super submodule sync &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_must_be_empty err &&\n     -+\tgit -C url-test/super/module config remote.origin.url \\\n     -+\t\t\"$PWD/url-test/fork\" &&\n     -+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n     -+\t\t../fork-source &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_must_be_empty err &&\n     -+\tgit -C url-test/super/module config --add remote.origin.url \\\n     -+\t\t\"$PWD/url-test/another-fork\" &&\n     -+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n     -+\t\t../another-fork-source &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_must_be_empty err &&\n     -+\tgit -C url-test/super/module config --unset-all remote.origin.url &&\n     -+\tgit -C url-test/super config --add submodule.module.url \\\n     -+\t\t\"$PWD/url-test/another-configured-source\" &&\n     -+\tgit -C url-test/super status >actual 2>err &&\n     -+\ttest_grep \"module.*different URL\" err\n     -+'\n     -+\n     - test_expect_success 'status submodule summary is disabled by default' '\n     - \tcat >expect <<EOF &&\n     - On branch main\n     -\n     - ## wt-status.c ##\n     -@@\n     - \n     - #include \"git-compat-util.h\"\n     - #include \"advice.h\"\n     -+#include \"config.h\"\n     - #include \"wt-status.h\"\n     - #include \"object.h\"\n     - #include \"dir.h\"\n     -@@\n     - #include \"remote.h\"\n     - #include \"refs.h\"\n     - #include \"submodule.h\"\n     -+#include \"submodule-config.h\"\n     - #include \"column.h\"\n     - #include \"read-cache.h\"\n     - #include \"setup.h\"\n     -@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n     - \t}\n     - }\n     - \n     -+static int submodule_has_custom_remote_url(struct repository *repo,\n     -+\t\t\t\t\t  const char *path,\n     -+\t\t\t\t\t  const char *url,\n     -+\t\t\t\t\t  const char *configured_url)\n     -+{\n     -+\tstruct repository subrepo = { 0 };\n     -+\tconst struct string_list *remote_urls = NULL;\n     -+\tconst char *remote;\n     -+\tconst char *remote_url;\n     -+\tchar *key, *up_path, *old_url, *new_url;\n     -+\tint error_code, ret = 0;\n     -+\n     -+\tif (!is_submodule_populated_gently(path, &error_code))\n     -+\t\treturn 0;\n     -+\n     -+\tif (repo_submodule_init(&subrepo, repo, path,\n     -+\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n     -+\t\trepo_clear(&subrepo);\n     -+\t\treturn 0;\n     -+\t}\n     -+\n     -+\tremote = repo_default_remote(&subrepo);\n     -+\n     -+\tkey = xstrfmt(\"remote.%s.url\", remote);\n     -+\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n     -+\t    remote_urls->nr == 1) {\n     -+\t\tremote_url = remote_urls->items[0].string;\n     -+\t\tup_path = get_submodule_up_path(path);\n     -+\t\told_url = resolve_submodule_url(repo, configured_url, up_path, 1);\n     -+\t\tnew_url = resolve_submodule_url(repo, url, up_path, 1);\n     -+\t\tret = strcmp(remote_url, old_url) != 0 &&\n     -+\t\t\tstrcmp(remote_url, new_url) != 0;\n     -+\t\tfree(new_url);\n     -+\t\tfree(old_url);\n     -+\t\tfree(up_path);\n     -+\t} else {\n     -+\t\t/*\n     -+\t\t * Multiple URLs are a local customization; sync would replace\n     -+\t\t * them all with a single URL.\n     -+\t\t */\n     -+\t\tret = remote_urls && remote_urls->nr > 1;\n     -+\t}\n     -+\tfree(key);\n     -+\trepo_clear(&subrepo);\n     -+\n     -+\treturn ret;\n     -+}\n     -+\n     -+static void wt_status_check_submodule_urls(struct wt_status *s)\n     -+{\n     -+\tint i;\n     -+\n     -+\tif (s->status_format != STATUS_FORMAT_LONG &&\n     -+\t    s->status_format != STATUS_FORMAT_NONE)\n     -+\t\treturn;\n     -+\n     -+\tif (is_gitmodules_unmerged(s->repo->index))\n     -+\t\treturn;\n     -+\n     -+\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n     -+\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n     -+\t\tconst struct submodule *sub;\n     -+\t\tconst char *configured_url;\n     -+\t\tchar *key, *expected_url;\n     -+\n     -+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))\n     -+\t\t\tcontinue;\n     -+\n     -+\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n     -+\t\t\t\t\t  ce->name);\n     -+\t\tif (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n     -+\t\t\tcontinue;\n     -+\n     -+\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n     -+\t\tif (repo_config_get_value(s->repo, key, &configured_url)) {\n     -+\t\t\tfree(key);\n     -+\t\t\tcontinue;\n     -+\t\t}\n     -+\t\tfree(key);\n     -+\n     -+\t\texpected_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n     -+\t\tif (strcmp(configured_url, expected_url) &&\n     -+\t\t    !submodule_has_custom_remote_url(s->repo, ce->name,\n     -+\t\t\t\t\t\t     expected_url,\n     -+\t\t\t\t\t\t     configured_url))\n     -+\t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n     -+\t\t\t\t  \"than in .gitmodules\\n\"\n     -+\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n     -+\n     -+\t\tfree(expected_url);\n     -+\t}\n     -+}\n     -+\n     - void wt_status_print(struct wt_status *s)\n     - {\n     -+\twt_status_check_submodule_urls(s);\n     -+\n     - \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n     - \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n     - \t\t\t   s->untracked.nr);\n -:  ---------- > 2:  b0dd21100c status: warn about stale submodule URLs\n\n-- \ngitgitgadget\n\n"},{"id":"559532","messageId":"4cd0ab7e9b1e4c9d350534ae9c6ffe18a4a88020.1795796162.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v2.git.git.1795796162.gitgitgadget@gmail.com","subject":"[PATCH v2 1/2] submodule: prepare URL helpers for reuse","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-27T16:16:01Z","receivedAt":"2026-11-27T16:16:01Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nMove the relative submodule URL resolver and the helper that computes\nthe path back to the superproject from builtin/submodule--helper.c to\nsubmodule.c so they can be shared with git status.\n\nPass the repository explicitly to the resolver instead of relying on\nthe_repository, and update existing callers to use the shared helpers.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n builtin/submodule--helper.c | 63 ++++++-------------------------------\n submodule.c                 | 41 ++++++++++++++++++++++++\n submodule.h                 |  3 ++\n 3 files changed, 54 insertions(+), 53 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 461b682d0d..5f293d9dfd 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -46,35 +46,6 @@\n typedef void (*each_submodule_fn)(const struct cache_entry *list_item,\n \t\t\t\t  void *cb_data);\n \n-static char *get_default_remote(void)\n-{\n-\treturn xstrdup(repo_default_remote(the_repository));\n-}\n-\n-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)\n-{\n-\tchar *remoteurl, *resolved_url;\n-\tchar *remote = get_default_remote();\n-\tstruct strbuf remotesb = STRBUF_INIT;\n-\n-\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n-\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n-\t\tif (!quiet)\n-\t\t\twarning(_(\"could not look up configuration '%s'. \"\n-\t\t\t\t  \"Assuming this repository is its own \"\n-\t\t\t\t  \"authoritative upstream.\"),\n-\t\t\t\tremotesb.buf);\n-\t\tremoteurl = xgetcwd();\n-\t}\n-\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n-\n-\tfree(remote);\n-\tfree(remoteurl);\n-\tstrbuf_release(&remotesb);\n-\n-\treturn resolved_url;\n-}\n-\n static int get_default_remote_submodule(const char *module_path, char **default_remote)\n {\n \tconst struct submodule *sub;\n@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 1);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 1);\n \t\t\tfree(oldurl);\n \t\t}\n \t}\n@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)\n \t*list = active_modules;\n }\n \n-static char *get_up_path(const char *path)\n-{\n-\tstruct strbuf sb = STRBUF_INIT;\n-\n-\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n-\n-\t/*\n-\t * Check if 'path' ends with slash or not\n-\t * for having the same output for dir/sub_dir\n-\t * and dir/sub_dir/\n-\t */\n-\tif (!is_dir_sep(path[strlen(path) - 1]))\n-\t\tstrbuf_addstr(&sb, \"../\");\n-\n-\treturn strbuf_detach(&sb, NULL);\n-}\n-\n static void for_each_listed_submodule(const struct module_list *list,\n \t\t\t\t      each_submodule_fn fn, void *cb_data)\n {\n@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 0);\n \t\t\tfree(oldurl);\n \t\t}\n \n@@ -1453,10 +1407,12 @@ static void sync_submodule(const char *path, const char *prefix,\n \tif (sub && sub->url) {\n \t\tif (starts_with_dot_dot_slash(sub->url) ||\n \t\t    starts_with_dot_slash(sub->url)) {\n-\t\t\tchar *up_path = get_up_path(path);\n+\t\t\tchar *up_path = get_submodule_up_path(path);\n \n-\t\t\tsub_origin_url = resolve_relative_url(sub->url, up_path, 1);\n-\t\t\tsuper_config_url = resolve_relative_url(sub->url, NULL, 1);\n+\t\t\tsub_origin_url = resolve_submodule_url(the_repository, sub->url,\n+\t\t\t\t\t\t\t      up_path, 1);\n+\t\t\tsuper_config_url = resolve_submodule_url(the_repository,\n+\t\t\t\t\t\t\t\t sub->url, NULL, 1);\n \t\t\tfree(up_path);\n \t\t} else {\n \t\t\tsub_origin_url = xstrdup(sub->url);\n@@ -2334,7 +2290,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \tif (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {\n \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n-\t\t\turl = resolve_relative_url(sub->url, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, sub->url, NULL, 0);\n \t\t\tneed_free_url = 1;\n \t\t} else\n \t\t\turl = sub->url;\n@@ -3761,7 +3717,8 @@ static int module_add(int argc, const char **argv, const char *prefix,\n \t\t\t      \"of the working tree\"));\n \n \t\t/* dereference source url relative to parent's url */\n-\t\tto_free = resolve_relative_url(add_data.repo, NULL, 1);\n+\t\tto_free = resolve_submodule_url(the_repository, add_data.repo,\n+\t\t\t\t\t\tNULL, 1);\n \t\tadd_data.realrepo = to_free;\n \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n \t\tadd_data.realrepo = add_data.repo;\ndiff --git a/submodule.c b/submodule.c\nindex a74d1925aa..f9ca99c5c8 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -292,6 +292,47 @@ int is_submodule_active(struct repository *repo, const char *path)\n \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n }\n \n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet)\n+{\n+\tconst char *remote = repo_default_remote(repo);\n+\tchar *remoteurl, *resolved_url;\n+\tstruct strbuf remotesb = STRBUF_INIT;\n+\n+\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n+\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n+\t\tif (!quiet)\n+\t\t\twarning(_(\"could not look up configuration '%s'. \"\n+\t\t\t\t  \"Assuming this repository is its own \"\n+\t\t\t\t  \"authoritative upstream.\"),\n+\t\t\t\tremotesb.buf);\n+\t\tremoteurl = xgetcwd();\n+\t}\n+\tresolved_url = relative_url(remoteurl, url, up_path);\n+\n+\tfree(remoteurl);\n+\tstrbuf_release(&remotesb);\n+\n+\treturn resolved_url;\n+}\n+\n+char *get_submodule_up_path(const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n+\n+\t/*\n+\t * Check if 'path' ends with slash or not\n+\t * for having the same output for dir/sub_dir\n+\t * and dir/sub_dir/\n+\t */\n+\tif (!is_dir_sep(path[strlen(path) - 1]))\n+\t\tstrbuf_addstr(&sb, \"../\");\n+\n+\treturn strbuf_detach(&sb, NULL);\n+}\n+\n int is_submodule_populated_gently(const char *path, int *return_error_code)\n {\n \tint ret = 0;\ndiff --git a/submodule.h b/submodule.h\nindex 1a465a1208..2028f272c4 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,\n \t\t\t     const struct object_id *treeish_name,\n \t\t\t     const char *path);\n int is_submodule_active(struct repository *repo, const char *path);\n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet);\n+char *get_submodule_up_path(const char *path);\n /*\n  * Determine if a submodule has been populated at a given 'path' by checking if\n  * the <path>/.git resolves to a valid git repository.\n-- \ngitgitgadget\n\n\n"},{"id":"559533","messageId":"b0dd21100ccfe4411ccc1237fdb7ddedb66075e8.1795796162.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v2.git.git.1795796162.gitgitgadget@gmail.com","subject":"[PATCH v2 2/2] status: warn about stale submodule URLs","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-27T16:16:02Z","receivedAt":"2026-11-27T16:16:02Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nWhen a submodule URL changes in .gitmodules, the cached\nsubmodule.<name>.url in the superproject config can stay stale. Warn\nin git status so users can run git submodule sync before a later\nsubmodule operation uses the outdated URL.\n\nResolve relative URLs using the same paths as git submodule sync.\nAvoid warning when the submodule remote indicates a local\ncustomization that sync would overwrite.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n submodule.c       |   3 ++\n t/t7508-status.sh |  54 ++++++++++++++++++++++++\n wt-status.c       | 104 ++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 161 insertions(+)\n\ndiff --git a/submodule.c b/submodule.c\nindex f9ca99c5c8..5d0018d032 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -299,6 +299,9 @@ char *resolve_submodule_url(struct repository *repo, const char *url,\n \tchar *remoteurl, *resolved_url;\n \tstruct strbuf remotesb = STRBUF_INIT;\n \n+\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n+\t\treturn xstrdup(url);\n+\n \tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n \tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n \t\tif (!quiet)\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..76a2e96dd7 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -921,6 +921,60 @@ test_expect_success 'setup status submodule summary' '\n \tgit add sm\n '\n \n+test_expect_success 'status reports submodule URL mismatch' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_create_repo url-test/source &&\n+\ttest_commit -C url-test/source initial &&\n+\ttest_create_repo url-test/super &&\n+\tgit -C url-test/super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/source\" module &&\n+\tgit -C url-test/super commit -m \"add submodule\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t\"$PWD/url-test/updated-source\" &&\n+\tgit -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\ttest_grep \"git submodule sync\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super remote add origin ../source-parent &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config remote.origin.url \\\n+\t\t\"$PWD/url-test/fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config --add remote.origin.url \\\n+\t\t\"$PWD/url-test/another-fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config --unset-all remote.origin.url &&\n+\tgit -C url-test/super config --add submodule.module.url \\\n+\t\t\"$PWD/url-test/another-configured-source\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err\n+'\n+\n test_expect_success 'status submodule summary is disabled by default' '\n \tcat >expect <<EOF &&\n On branch main\ndiff --git a/wt-status.c b/wt-status.c\nindex 238bb48643..be6902c9dd 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -3,6 +3,7 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n+#include \"config.h\"\n #include \"wt-status.h\"\n #include \"object.h\"\n #include \"dir.h\"\n@@ -23,6 +24,7 @@\n #include \"remote.h\"\n #include \"refs.h\"\n #include \"submodule.h\"\n+#include \"submodule-config.h\"\n #include \"column.h\"\n #include \"read-cache.h\"\n #include \"setup.h\"\n@@ -2692,8 +2694,110 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n \t}\n }\n \n+static int submodule_has_custom_remote_url(struct repository *repo,\n+\t\t\t\t\t  const char *path,\n+\t\t\t\t\t  const char *gitmodules_url,\n+\t\t\t\t\t  const char *config_url)\n+{\n+\tstruct repository subrepo = { 0 };\n+\tconst struct string_list *remote_urls = NULL;\n+\tconst char *remote;\n+\tconst char *remote_url;\n+\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n+\tint error_code, ret = 0;\n+\n+\tif (!is_submodule_populated_gently(path, &error_code))\n+\t\treturn 0;\n+\n+\tif (repo_submodule_init(&subrepo, repo, path,\n+\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n+\t\trepo_clear(&subrepo);\n+\t\treturn 0;\n+\t}\n+\n+\tremote = repo_default_remote(&subrepo);\n+\n+\tkey = xstrfmt(\"remote.%s.url\", remote);\n+\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n+\t    remote_urls->nr == 1) {\n+\t\tremote_url = remote_urls->items[0].string;\n+\t\tup_path = get_submodule_up_path(path);\n+\t\tconfig_remote_url = resolve_submodule_url(repo, config_url,\n+\t\t\t\t\t\t\t  up_path, 1);\n+\t\tgitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,\n+\t\t\t\t\t\t\t      up_path, 1);\n+\t\t/*\n+\t\t * The submodule's remote URL may be a local fork. If it matches\n+\t\t * neither the old cached URL nor the new .gitmodules URL, leave it\n+\t\t * alone; syncing would overwrite that customization.\n+\t\t */\n+\t\tret = strcmp(remote_url, config_remote_url) != 0 &&\n+\t\t\tstrcmp(remote_url, gitmodules_remote_url) != 0;\n+\t\tfree(gitmodules_remote_url);\n+\t\tfree(config_remote_url);\n+\t\tfree(up_path);\n+\t} else {\n+\t\t/*\n+\t\t * Multiple URLs are a local customization; sync would replace\n+\t\t * them all with a single URL.\n+\t\t */\n+\t\tret = remote_urls && remote_urls->nr > 1;\n+\t}\n+\tfree(key);\n+\trepo_clear(&subrepo);\n+\n+\treturn ret;\n+}\n+\n+static void wt_status_check_submodule_urls(struct wt_status *s)\n+{\n+\tint i;\n+\n+\tif (s->status_format != STATUS_FORMAT_LONG &&\n+\t    s->status_format != STATUS_FORMAT_NONE)\n+\t\treturn;\n+\n+\tif (is_gitmodules_unmerged(s->repo->index))\n+\t\treturn;\n+\n+\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n+\t\tconst struct submodule *sub;\n+\t\tconst char *config_url;\n+\t\tchar *key, *gitmodules_url;\n+\n+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))\n+\t\t\tcontinue;\n+\n+\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n+\t\t\t\t\t  ce->name);\n+\t\tif (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n+\t\t\tcontinue;\n+\n+\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n+\t\tif (repo_config_get_value(s->repo, key, &config_url)) {\n+\t\t\tfree(key);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfree(key);\n+\n+\t\tgitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n+\t\tif (strcmp(config_url, gitmodules_url) &&\n+\t\t    !submodule_has_custom_remote_url(s->repo, ce->name,\n+\t\t\t\t\t\t     sub->url,\n+\t\t\t\t\t\t     config_url))\n+\t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n+\t\t\t\t  \"than in .gitmodules\\n\"\n+\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n+\n+\t\tfree(gitmodules_url);\n+\t}\n+}\n+\n void wt_status_print(struct wt_status *s)\n {\n+\twt_status_check_submodule_urls(s);\n+\n \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n \t\t\t   s->untracked.nr);\n-- \ngitgitgadget\n\n"},{"id":"559542","messageId":"xmqqecc69maa.fsf@gitster.g","threadId":"66944","inReplyTo":"b0dd21100ccfe4411ccc1237fdb7ddedb66075e8.1795796162.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 2/2] status: warn about stale submodule URLs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-27T18:11:57Z","receivedAt":"2026-11-27T18:11:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Alessio Attilio via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Alessio Attilio <attilio.alessio@protonmail.com>\n>\n> When a submodule URL changes in .gitmodules, the cached\n> submodule.<name>.url in the superproject config can stay stale. Warn\n> in git status so users can run git submodule sync before a later\n> submodule operation uses the outdated URL.\n>\n> Resolve relative URLs using the same paths as git submodule sync.\n> Avoid warning when the submodule remote indicates a local\n> customization that sync would overwrite.\n>\n> Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n> ---\n\nSurfacing stale submodule configuration in \"git status\" is a very useful\nimprovement.  Like Ben noted, splitting the helper extraction out into a\npreparatory commit made the series easier to follow.\n\nIt would help to explain in the proposed log message why three URLs are\ncompared and under what condition, and which status formats emit the\nwarning.\n\n> diff --git a/submodule.c b/submodule.c\n> index f9ca99c5c8..5d0018d032 100644\n> --- a/submodule.c\n> +++ b/submodule.c\n> @@ -299,6 +299,9 @@ char *resolve_submodule_url(struct repository *repo, const char *url,\n>  \tchar *remoteurl, *resolved_url;\n>  \tstruct strbuf remotesb = STRBUF_INIT;\n>  \n> +\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n> +\t\treturn xstrdup(url);\n> +\n>  \tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n>  \tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n>  \t\tif (!quiet)\n\nThe split made it harder to spot, but this addition forces the helper\nfunction to return if 'url' is not relative, yet we have already spent\ncycles calling repo_default_remote() to compute 'remote', paying the\ncost to call repo_config() and to look up the HEAD branch.  Perhaps move\nthe unnecessary call to repo_default_remote() after this early return,\nbefore the first use of 'remote'?\n\n\n> diff --git a/wt-status.c b/wt-status.c\n> index 238bb48643..be6902c9dd 100644\n> --- a/wt-status.c\n> +++ b/wt-status.c\n> ...\n> +static int submodule_has_custom_remote_url(struct repository *repo,\n> +\t\t\t\t\t  const char *path,\n> +\t\t\t\t\t  const char *gitmodules_url,\n> +\t\t\t\t\t  const char *config_url)\n> +{\n> +\tstruct repository subrepo = { 0 };\n> +\tconst struct string_list *remote_urls = NULL;\n> +\tconst char *remote;\n> +\tconst char *remote_url;\n> +\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n> +\tint error_code, ret = 0;\n> +\n> +\tif (!is_submodule_populated_gently(path, &error_code))\n> +\t\treturn 0;\n> +\n> +\tif (repo_submodule_init(&subrepo, repo, path,\n> +\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n> +\t\trepo_clear(&subrepo);\n> +\t\treturn 0;\n> +\t}\n> +\n> +\tremote = repo_default_remote(&subrepo);\n> +\n> +\tkey = xstrfmt(\"remote.%s.url\", remote);\n> +\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n> +\t    remote_urls->nr == 1) {\n> +\t\tremote_url = remote_urls->items[0].string;\n\nCan the '.string' member be NULL here, either by mistake or by malice?\nWe have two strcmp() calls below to compare this with two other URLs,\nand either would segfault.\n\nPerhaps use repo_config_get_string_multi() instead?  I do not know what\nerror behavior you are aiming for here, but the 'string' variant would\nbarf on an entry like '[remote \"origin\"] url' (valueless true), which\nwould give you NULL in the '.string' member.\n\n\n> +\t\tup_path = get_submodule_up_path(path);\n> +\t\tconfig_remote_url = resolve_submodule_url(repo, config_url,\n> +\t\t\t\t\t\t\t  up_path, 1);\n> +\t\tgitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,\n> +\t\t\t\t\t\t\t      up_path, 1);\n> +\t\t/*\n> +\t\t * The submodule's remote URL may be a local fork. If it matches\n> +\t\t * neither the old cached URL nor the new .gitmodules URL, leave it\n> +\t\t * alone; syncing would overwrite that customization.\n> +\t\t */\n> +\t\tret = strcmp(remote_url, config_remote_url) != 0 &&\n> +\t\t\tstrcmp(remote_url, gitmodules_remote_url) != 0;\n\nRenaming of new/old may address one of the points of confusion Ben had.\n\nWhen the superproject's own default remote URL is relative, doesn't\nthis logic break?\n\nIn wt_status_check_submodule_urls() we see below, 'gitmodules_url' was\nalready computed by resolving sub->url against the superproject's\ndefault remote with 'up_path' set to NULL.  Likewise, 'config_url' from\nsubmodule.<name>.url in .git/config was already resolved once with\n'up_path' set to NULL when init_submodule() or sync_submodule() wrote\nit.\n\nPassing already-resolved URLs into resolve_submodule_url() again smells\nfishy.  There are a few ways I can think of that this can break.  I may\nbe misreading the code flow, and these may be no issue, or there may be\nother issues.\n\n * When the superproject has \"remote.origin.url = a/b\" (relative without\n   \"./\" or \"../\") and .gitmodules has \"../mod1\", sync_submodule() stores\n   \"a/mod1\" in submodule.module.url and \"../a/mod1\" in the submodule's\n   remote.origin.url.\n\n   submodule_has_custom_remote_url() calls resolve_submodule_url() on\n   \"a/mod1\".  It hits the early return without prepending 'up_path', so\n   'config_remote_url' is \"a/mod1\" instead of \"../a/mod1\" and fails to\n   match.\n\n * When the superproject has \"remote.origin.url = ../a/b\", .gitmodules\n   initially has \"submodule.module.url = ../mod1\", and the user runs\n   \"git submodule sync\".  In sync_submodule(), relative_url() stores\n   \"../a/mod1\" in submodule.module.url and \"../../a/mod1\" in the\n   submodule's remote.origin.url.\n\n   If submodule.module.url in .gitmodules then changes to \"../mod2\",\n   wt_status_check_submodule_urls() sets 'gitmodules_remote_url' to\n   \"../a/mod2\".  Inside submodule_has_custom_remote_url(), both\n   \"../a/mod1\" and \"../a/mod2\" still start with \"../\", so\n   resolve_submodule_url() resolves them a second time against \"../a/b\".\n\n   Wouldn't the result be \"../../a/a/mod1\" and \"../../a/a/mod2\" in such\n   a case?\n\n   Neither matches \"../../a/mod1\", so submodule_has_custom_remote_url()\n   returns 1 and suppresses the warning even though the submodule remote\n   was never customized.  The new test in t7508 used \"../source-parent\"\n   with only one path component after \"..\", where the second resolution\n   happened to be a no-op, so it may not have noticed the breakage.\n\nIn order to match what sync_submodule() does, 'gitmodules_remote_url'\nshould be computed from the raw 'sub->url', not from 'gitmodules_url',\nno?  For 'config_remote_url', we do not want to run relative_url() again\non 'config_url', I think.  You only need to prepend 'up_path', or\nsomething, no?  I didn't think this one through, so take it with a huge\ngrain of salt.\n\n\n> +static void wt_status_check_submodule_urls(struct wt_status *s)\n> +{\n> +\tint i;\n> +\n> +\tif (s->status_format != STATUS_FORMAT_LONG &&\n> +\t    s->status_format != STATUS_FORMAT_NONE)\n> +\t\treturn;\n\nMental note.  Restricting this only to the \"long\" and \"none\" formats\nsomehow feels arbitrary.  Perhaps the callers ought to have more direct\nand finer control, and tell the callchain leading to wt_status_print()\nto refrain from calling this helper at all when the callers do not want\nthe warnings (like \"git commit\" preparing the commit template).  That\nwould allow us to free this helper from making this arbitrary choice.\n\n> +\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n> +\t\tif (repo_config_get_value(s->repo, key, &config_url)) {\n> +\t\t\tfree(key);\n> +\t\t\tcontinue;\n> +\t\t}\n> +\t\tfree(key);\n> +\n> +\t\tgitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n> +\t\tif (strcmp(config_url, gitmodules_url) &&\n\nThis is another potential NULL dereference due to the use of\nrepo_config_get_value() instead of _get_string(), no?  The same\nmechanism, the same segfault.\n\n>  void wt_status_print(struct wt_status *s)\n>  {\n> +\twt_status_check_submodule_urls(s);\n> +\n>  \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n>  \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n>  \t\t\t   s->untracked.nr);\n\nwt_status_print() is not just for \"git status\", but is also used to\ngenerate commit templates.  Checking only '.status_format' at the\nbeginning of wt_status_check_submodule_urls() means that these extra\nchecks are done and warnings are leaked into unrelated commands.\n\nIn builtin/commit.c, cmd_commit() sets '.commit_template' to 1 and\n'status_format' to STATUS_FORMAT_NONE, and prepare_to_commit() calls\nrun_status() with 'nowarn' set to 1 when populating COMMIT_EDITMSG.\n\nSimilarly, fill_commit_message() in builtin/history.c leaves\n'.status_format' at STATUS_FORMAT_NONE, sets '.commit_template' to 1,\nand calls wt_status_print() after collecting a diff between two trees.\n\nAs a result, running \"git commit\" with an editor or \"git history\" emits\nthis status warning to stderr.\n\nInstead of excluding individual cases (like \"commit or history can call\nand .commit_template or .nowarn may be set by them\"), can we make sure\nwe call the extra check only when \"git status\" is calling the wt-status\nmachinery to prevent it?\n\nThere are also a few design questions.\n\n * Should \"git status <pathspec>\" limit its check to submodules under\n   the given directory?\n\n * Should \"git status --ignore-submodules\" bypass the new check\n   altogether?\n\n * Should \"git status -s\" and \"git status --porcelain\" detect the\n   misconfiguration like the normal \"git status\"?\n\nMy tentative answers to the above are all \"yes\", but the design needs to\nbe discussed, the choices justified, and the result documented in both\nthe proposed commit log message and in the \"git status --help\"\ndocumentation.\n\nThanks.\n\n"},{"id":"559553","messageId":"OMY1zvJHIGS8yvryfUhct_Q4HkqQNP3QJ0ezjSIY6F5k_L5UpMLJ0B31C5LUjJwglnYlccCCh1WVqawRDXMUQXPX9FgsxWFwrcS5HUGaZ_4=@protonmail.com","threadId":"66944","inReplyTo":"xmqqecc69maa.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] status: warn about stale submodule URLs","fromName":"ATTILIO ALESSIO","fromEmail":"attilio.alessio@protonmail.com","sentAt":"2026-11-27T20:35:29Z","receivedAt":"2026-11-27T20:35:29Z","isPatch":true,"sender":{"key":"attilio.alessio@protonmail.com","avatar":null},"body":"\"Junio C Hamano\" <gitster@pobox.com> writes:\n\n> It would help to explain in the proposed log message why three URLs are\n> compared and under what condition, and which status formats emit the\n> warning.\n\nWill do.  I will explain in the commit message why the three URLs are\ncompared, under what condition the warning triggers, and which status\nformats emit it.\n\n> Perhaps move the unnecessary call to repo_default_remote() after this\n> early return, before the first use of 'remote'?\n\nGood catch.  I will move repo_default_remote() below the early return\nfor non-relative URLs.\n\n> Perhaps use repo_config_get_string_multi() instead?  I do not know what\n> error behavior you are aiming for here, but the 'string' variant would\n> barf on an entry like '[remote \"origin\"] url' (valueless true), which\n> would give you NULL in the '.string' member.\n\nAgreed.  I will switch to the *_get_string*() helpers (or guard against\nvalueless entries) so we never pass NULL to strcmp().\n\n> In order to match what sync_submodule() does, 'gitmodules_remote_url'\n> should be computed from the raw 'sub->url', not from 'gitmodules_url',\n> no?  For 'config_remote_url', we do not want to run relative_url() again\n> on 'config_url', I think.  You only need to prepend 'up_path', or\n> something, no?\n\nYou are right: the values passed to submodule_has_custom_remote_url()\nhave already been resolved once, so resolving them again produces wrong\npaths when the superproject's own remote URL is relative.  I will\nrework this to resolve the raw .gitmodules URL and prepend up_path to\nthe cached config URL, matching git submodule sync.\n\n> Instead of excluding individual cases (like \"commit or history can call\n> and .commit_template or .nowarn may be set by them\"), can we make sure\n> we call the extra check only when \"git status\" is calling the wt-status\n> machinery to prevent it?\n\nYes, gating the check so it runs only when invoked from git status is\nmuch cleaner and avoids leaking warnings into commit templates.\n\n> - Should \"git status <pathspec>\" limit its check to submodules under\n>    the given directory?\n>\n> - Should \"git status --ignore-submodules\" bypass the new check\n>    altogether?\n>\n> - Should \"git status -s\" and \"git status --porcelain\" detect the\n>    misconfiguration like the normal \"git status\"?\n>\n> My tentative answers to the above are all \"yes\", but the design needs to\n> be discussed, the choices justified, and the result documented in both\n> the proposed commit log message and in the \"git status --help\"\n> documentation.\n\nI agree with \"yes\" on all three:\n\n- Respecting <pathspec> keeps the warning scoped to the paths the user\n  asked about.\n- Respecting --ignore-submodules matches user expectations when they\n  explicitly ask status to ignore submodule state.\n- Emitting the warning on stderr in -s and --porcelain modes ensures\n  users and scripts still get the diagnostic without affecting machine-\n  readable stdout output.\n\nI will update the implementation, tests, commit message, and git-status\ndocumentation accordingly for the next reroll.\n\nThanks,\nAlessio"},{"id":"559556","messageId":"pull.2509.v3.git.git.1795814853.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.git.git.1795774880142.gitgitgadget@gmail.com","subject":"[PATCH v3 0/2] status: report when submodule URLs are out of sync","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-27T21:27:31Z","receivedAt":"2026-11-27T21:27:31Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"When a submodule URL changes in .gitmodules, the corresponding URL in the\nsuperproject's .git/config may keep pointing at the old location. This\nseries makes git status warn about that mismatch and suggest git submodule\nsync.\n\nThe warning resolves relative URLs as git submodule sync does. It also\nsuppresses the warning when the populated submodule has a custom remote URL\nthat a sync would overwrite.\n\nThe series is split into:\n\n 1. submodule: move URL helpers to submodule.c\n 2. submodule: make URL resolution repository-aware\n 3. status: warn about stale submodule URLs\n\nChanges since v2:\n\n * Keep the helper relocation in a preparatory commit.\n * Move repository-aware URL resolution into its own commit.\n * Keep test output inside its fixture directory.\n\nCloses gitgitgadget/git#565\n\nAlessio Attilio (2):\n  submodule: prepare URL helpers for reuse\n  status: warn about stale submodule URLs\n\n Documentation/git-status.adoc |   6 ++\n builtin/commit.c              |   1 +\n builtin/submodule--helper.c   |  63 +++---------------\n submodule.c                   |  45 +++++++++++++\n submodule.h                   |   3 +\n t/t7508-status.sh             |  84 ++++++++++++++++++++++++\n wt-status.c                   | 120 ++++++++++++++++++++++++++++++++++\n wt-status.h                   |   1 +\n 8 files changed, 270 insertions(+), 53 deletions(-)\n\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v3\nPull-Request: https://github.com/git/git/pull/2509\n\nRange-diff vs v2:\n\n 1:  4cd0ab7e9b ! 1:  fc300295ff submodule: prepare URL helpers for reuse\n     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)\n       \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n       }\n       \n     -+char *resolve_submodule_url(struct repository *repo, const char *url,\n     ++char *resolve_submodule_url(struct repository *repo, const char *rel_url,\n      +\t\t\t    const char *up_path, int quiet)\n      +{\n     -+\tconst char *remote = repo_default_remote(repo);\n      +\tchar *remoteurl, *resolved_url;\n     ++\tconst char *remote = repo_default_remote(repo);\n      +\tstruct strbuf remotesb = STRBUF_INIT;\n      +\n      +\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)\n      +\t\t\t\tremotesb.buf);\n      +\t\tremoteurl = xgetcwd();\n      +\t}\n     -+\tresolved_url = relative_url(remoteurl, url, up_path);\n     ++\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n      +\n      +\tfree(remoteurl);\n      +\tstrbuf_release(&remotesb);\n 2:  b0dd21100c ! 2:  9dc6283075 status: warn about stale submodule URLs\n     @@ Commit message\n          in git status so users can run git submodule sync before a later\n          submodule operation uses the outdated URL.\n      \n     -    Resolve relative URLs using the same paths as git submodule sync.\n     -    Avoid warning when the submodule remote indicates a local\n     -    customization that sync would overwrite.\n     +    The check considers three URLs: the .gitmodules URL resolved against\n     +    the superproject's default remote, the cached submodule.<name>.url, and\n     +    the submodule's default remote URL. The first two determine whether the\n     +    cached URL is stale. If they differ, compare the submodule remote with\n     +    the old and new URLs as sync would write them. Warn only when that\n     +    remote matches either URL; a different URL or multiple URLs indicate a\n     +    local customization that sync would otherwise overwrite.\n     +\n     +    Resolve relative URLs using the same paths as git submodule sync, and\n     +    do not resolve the already-resolved cached URL a second time. Emit the\n     +    warning on standard error for long, short, and porcelain status output,\n     +    limited to submodules matched by the pathspec. Do not emit it when\n     +    --ignore-submodules is given or when the wt-status machinery is used by\n     +    another command.\n      \n          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n     + ## Documentation/git-status.adoc ##\n     +@@ Documentation/git-status.adoc: are what you _would_ commit by running `git commit`; the second and\n     + third are what you _could_ commit by running `git add` before running\n     + `git commit`.\n     + \n     ++When a submodule's URL in `.gitmodules` differs from the URL cached in\n     ++`.git/config`, `git status` warns that `git submodule sync` can update the\n     ++cached URL. The warning is written to standard error in all output formats.\n     ++It is limited to submodules matched by the pathspec, and is suppressed when\n     ++`--ignore-submodules` is specified.\n     ++\n     + OPTIONS\n     + -------\n     + \n     +\n     + ## builtin/commit.c ##\n     +@@ builtin/commit.c: struct repository *repo UNUSED)\n     + \n     + \ts.ignore_submodule_arg = ignore_submodule_arg;\n     + \ts.status_format = status_format;\n     ++\ts.check_submodule_urls = 1;\n     + \ts.verbose = verbose;\n     + \tif (no_renames != -1)\n     + \t\ts.detect_rename = !no_renames;\n     +\n       ## submodule.c ##\n     -@@ submodule.c: char *resolve_submodule_url(struct repository *repo, const char *url,\n     +@@ submodule.c: char *resolve_submodule_url(struct repository *repo, const char *rel_url,\n     + \t\t\t    const char *up_path, int quiet)\n     + {\n       \tchar *remoteurl, *resolved_url;\n     +-\tconst char *remote = repo_default_remote(repo);\n     ++\tconst char *remote;\n       \tstruct strbuf remotesb = STRBUF_INIT;\n       \n     -+\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n     -+\t\treturn xstrdup(url);\n     ++\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n     ++\t\treturn xstrdup(rel_url);\n      +\n     ++\tremote = repo_default_remote(repo);\n       \tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n       \tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n       \t\tif (!quiet)\n     @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n      +\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n      +\t\t\"$PWD/url-test/updated-source\" &&\n      +\tgit -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tgit -C url-test/super status --short >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tgit -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tgit -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&\n      +\ttest_must_be_empty url-test/err &&\n     ++\tgit -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&\n     ++\ttest_must_be_empty url-test/err &&\n     ++\tgit -C url-test/super status -- module >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n      +\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n      +\ttest_grep \"module.*different URL\" url-test/err &&\n      +\ttest_grep \"git submodule sync\" url-test/err &&\n     @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n      +\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n      +\ttest_grep \"module.*different URL\" url-test/err\n      +'\n     ++\n     ++test_expect_success 'status compares relative submodule URLs only once' '\n     ++\ttest_when_finished \"rm -rf url-test\" &&\n     ++\ttest_create_repo url-test/relative-source &&\n     ++\ttest_commit -C url-test/relative-source initial &&\n     ++\ttest_create_repo url-test/relative-super &&\n     ++\tgit -C url-test/relative-super -c protocol.file.allow=always \\\n     ++\t\tsubmodule add \"$PWD/url-test/relative-source\" module &&\n     ++\tgit -C url-test/relative-super commit -m \"add submodule\" &&\n     ++\tgit -C url-test/relative-super remote add origin ../a/b &&\n     ++\tgit -C url-test/relative-super config -f .gitmodules \\\n     ++\t\tsubmodule.module.url ../mod1 &&\n     ++\tgit -C url-test/relative-super submodule sync &&\n     ++\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n     ++\ttest_must_be_empty url-test/err &&\n     ++\tgit -C url-test/relative-super config -f .gitmodules \\\n     ++\t\tsubmodule.module.url ../mod2 &&\n     ++\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err\n     ++'\n      +\n       test_expect_success 'status submodule summary is disabled by default' '\n       \tcat >expect <<EOF &&\n     @@ wt-status.c\n       \n       #include \"git-compat-util.h\"\n       #include \"advice.h\"\n     ++#include \"abspath.h\"\n      +#include \"config.h\"\n       #include \"wt-status.h\"\n       #include \"object.h\"\n     @@ wt-status.c\n       #include \"remote.h\"\n       #include \"refs.h\"\n       #include \"submodule.h\"\n     ++#include \"url.h\"\n      +#include \"submodule-config.h\"\n       #include \"column.h\"\n       #include \"read-cache.h\"\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\tremote = repo_default_remote(&subrepo);\n      +\n      +\tkey = xstrfmt(\"remote.%s.url\", remote);\n     -+\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n     ++\tif (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&\n      +\t    remote_urls->nr == 1) {\n      +\t\tremote_url = remote_urls->items[0].string;\n      +\t\tup_path = get_submodule_up_path(path);\n     -+\t\tconfig_remote_url = resolve_submodule_url(repo, config_url,\n     -+\t\t\t\t\t\t\t  up_path, 1);\n     ++\t\t/*\n     ++\t\t * sync_submodule() stores a relative URL in the superproject's\n     ++\t\t * config without the submodule path prefix, but adds that prefix\n     ++\t\t * when storing the URL in the submodule's remote configuration.\n     ++\t\t */\n     ++\t\tif (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {\n     ++\t\t\tstruct strbuf sb = STRBUF_INIT;\n     ++\n     ++\t\t\tstrbuf_addstr(&sb, up_path);\n     ++\t\t\tstrbuf_addstr(&sb, config_url);\n     ++\t\t\tconfig_remote_url = strbuf_detach(&sb, NULL);\n     ++\t\t} else {\n     ++\t\t\tconfig_remote_url = xstrdup(config_url);\n     ++\t\t}\n      +\t\tgitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,\n      +\t\t\t\t\t\t\t      up_path, 1);\n      +\t\t/*\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +{\n      +\tint i;\n      +\n     -+\tif (s->status_format != STATUS_FORMAT_LONG &&\n     -+\t    s->status_format != STATUS_FORMAT_NONE)\n     ++\tif (!s->check_submodule_urls || s->ignore_submodule_arg)\n      +\t\treturn;\n      +\n      +\tif (is_gitmodules_unmerged(s->repo->index))\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n      +\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n      +\t\tconst struct submodule *sub;\n     -+\t\tconst char *config_url;\n     ++\t\tchar *config_url;\n      +\t\tchar *key, *gitmodules_url;\n      +\n     -+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))\n     ++\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||\n     ++\t\t    !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))\n      +\t\t\tcontinue;\n      +\n      +\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\t\t\tcontinue;\n      +\n      +\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n     -+\t\tif (repo_config_get_value(s->repo, key, &config_url)) {\n     ++\t\tif (repo_config_get_string(s->repo, key, &config_url)) {\n      +\t\t\tfree(key);\n      +\t\t\tcontinue;\n      +\t\t}\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\t\t\t\t  \"than in .gitmodules\\n\"\n      +\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n      +\n     ++\t\tfree(config_url);\n      +\t\tfree(gitmodules_url);\n      +\t}\n      +}\n      +\n       void wt_status_print(struct wt_status *s)\n       {\n     -+\twt_status_check_submodule_urls(s);\n     ++\tif (s->check_submodule_urls)\n     ++\t\twt_status_check_submodule_urls(s);\n      +\n       \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n       \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n       \t\t\t   s->untracked.nr);\n     +\n     + ## wt-status.h ##\n     +@@ wt-status.h: struct wt_status {\n     + \tunsigned colopts;\n     + \tint null_termination;\n     + \tint commit_template;\n     ++\tint check_submodule_urls;\n     + \tint show_branch;\n     + \tint show_stash;\n     + \tint hints;\n\n-- \ngitgitgadget\n\n"},{"id":"559557","messageId":"fc300295ffaef49b592307a90ac3e58bb803b7ca.1795814853.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v3.git.git.1795814853.gitgitgadget@gmail.com","subject":"[PATCH v3 1/2] submodule: prepare URL helpers for reuse","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-27T21:27:32Z","receivedAt":"2026-11-27T21:27:32Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nMove the relative submodule URL resolver and the helper that computes\nthe path back to the superproject from builtin/submodule--helper.c to\nsubmodule.c so they can be shared with git status.\n\nPass the repository explicitly to the resolver instead of relying on\nthe_repository, and update existing callers to use the shared helpers.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n builtin/submodule--helper.c | 63 ++++++-------------------------------\n submodule.c                 | 41 ++++++++++++++++++++++++\n submodule.h                 |  3 ++\n 3 files changed, 54 insertions(+), 53 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 461b682d0d..5f293d9dfd 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -46,35 +46,6 @@\n typedef void (*each_submodule_fn)(const struct cache_entry *list_item,\n \t\t\t\t  void *cb_data);\n \n-static char *get_default_remote(void)\n-{\n-\treturn xstrdup(repo_default_remote(the_repository));\n-}\n-\n-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)\n-{\n-\tchar *remoteurl, *resolved_url;\n-\tchar *remote = get_default_remote();\n-\tstruct strbuf remotesb = STRBUF_INIT;\n-\n-\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n-\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n-\t\tif (!quiet)\n-\t\t\twarning(_(\"could not look up configuration '%s'. \"\n-\t\t\t\t  \"Assuming this repository is its own \"\n-\t\t\t\t  \"authoritative upstream.\"),\n-\t\t\t\tremotesb.buf);\n-\t\tremoteurl = xgetcwd();\n-\t}\n-\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n-\n-\tfree(remote);\n-\tfree(remoteurl);\n-\tstrbuf_release(&remotesb);\n-\n-\treturn resolved_url;\n-}\n-\n static int get_default_remote_submodule(const char *module_path, char **default_remote)\n {\n \tconst struct submodule *sub;\n@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 1);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 1);\n \t\t\tfree(oldurl);\n \t\t}\n \t}\n@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)\n \t*list = active_modules;\n }\n \n-static char *get_up_path(const char *path)\n-{\n-\tstruct strbuf sb = STRBUF_INIT;\n-\n-\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n-\n-\t/*\n-\t * Check if 'path' ends with slash or not\n-\t * for having the same output for dir/sub_dir\n-\t * and dir/sub_dir/\n-\t */\n-\tif (!is_dir_sep(path[strlen(path) - 1]))\n-\t\tstrbuf_addstr(&sb, \"../\");\n-\n-\treturn strbuf_detach(&sb, NULL);\n-}\n-\n static void for_each_listed_submodule(const struct module_list *list,\n \t\t\t\t      each_submodule_fn fn, void *cb_data)\n {\n@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 0);\n \t\t\tfree(oldurl);\n \t\t}\n \n@@ -1453,10 +1407,12 @@ static void sync_submodule(const char *path, const char *prefix,\n \tif (sub && sub->url) {\n \t\tif (starts_with_dot_dot_slash(sub->url) ||\n \t\t    starts_with_dot_slash(sub->url)) {\n-\t\t\tchar *up_path = get_up_path(path);\n+\t\t\tchar *up_path = get_submodule_up_path(path);\n \n-\t\t\tsub_origin_url = resolve_relative_url(sub->url, up_path, 1);\n-\t\t\tsuper_config_url = resolve_relative_url(sub->url, NULL, 1);\n+\t\t\tsub_origin_url = resolve_submodule_url(the_repository, sub->url,\n+\t\t\t\t\t\t\t      up_path, 1);\n+\t\t\tsuper_config_url = resolve_submodule_url(the_repository,\n+\t\t\t\t\t\t\t\t sub->url, NULL, 1);\n \t\t\tfree(up_path);\n \t\t} else {\n \t\t\tsub_origin_url = xstrdup(sub->url);\n@@ -2334,7 +2290,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \tif (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {\n \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n-\t\t\turl = resolve_relative_url(sub->url, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, sub->url, NULL, 0);\n \t\t\tneed_free_url = 1;\n \t\t} else\n \t\t\turl = sub->url;\n@@ -3761,7 +3717,8 @@ static int module_add(int argc, const char **argv, const char *prefix,\n \t\t\t      \"of the working tree\"));\n \n \t\t/* dereference source url relative to parent's url */\n-\t\tto_free = resolve_relative_url(add_data.repo, NULL, 1);\n+\t\tto_free = resolve_submodule_url(the_repository, add_data.repo,\n+\t\t\t\t\t\tNULL, 1);\n \t\tadd_data.realrepo = to_free;\n \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n \t\tadd_data.realrepo = add_data.repo;\ndiff --git a/submodule.c b/submodule.c\nindex a74d1925aa..3eab799f1f 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -292,6 +292,47 @@ int is_submodule_active(struct repository *repo, const char *path)\n \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n }\n \n+char *resolve_submodule_url(struct repository *repo, const char *rel_url,\n+\t\t\t    const char *up_path, int quiet)\n+{\n+\tchar *remoteurl, *resolved_url;\n+\tconst char *remote = repo_default_remote(repo);\n+\tstruct strbuf remotesb = STRBUF_INIT;\n+\n+\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n+\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n+\t\tif (!quiet)\n+\t\t\twarning(_(\"could not look up configuration '%s'. \"\n+\t\t\t\t  \"Assuming this repository is its own \"\n+\t\t\t\t  \"authoritative upstream.\"),\n+\t\t\t\tremotesb.buf);\n+\t\tremoteurl = xgetcwd();\n+\t}\n+\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n+\n+\tfree(remoteurl);\n+\tstrbuf_release(&remotesb);\n+\n+\treturn resolved_url;\n+}\n+\n+char *get_submodule_up_path(const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n+\n+\t/*\n+\t * Check if 'path' ends with slash or not\n+\t * for having the same output for dir/sub_dir\n+\t * and dir/sub_dir/\n+\t */\n+\tif (!is_dir_sep(path[strlen(path) - 1]))\n+\t\tstrbuf_addstr(&sb, \"../\");\n+\n+\treturn strbuf_detach(&sb, NULL);\n+}\n+\n int is_submodule_populated_gently(const char *path, int *return_error_code)\n {\n \tint ret = 0;\ndiff --git a/submodule.h b/submodule.h\nindex 1a465a1208..2028f272c4 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,\n \t\t\t     const struct object_id *treeish_name,\n \t\t\t     const char *path);\n int is_submodule_active(struct repository *repo, const char *path);\n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet);\n+char *get_submodule_up_path(const char *path);\n /*\n  * Determine if a submodule has been populated at a given 'path' by checking if\n  * the <path>/.git resolves to a valid git repository.\n-- \ngitgitgadget\n\n\n"},{"id":"559558","messageId":"9dc62830755b06ca2a95d307dd0b593d2a77c536.1795814853.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v3.git.git.1795814853.gitgitgadget@gmail.com","subject":"[PATCH v3 2/2] status: warn about stale submodule URLs","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-27T21:27:33Z","receivedAt":"2026-11-27T21:27:33Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nWhen a submodule URL changes in .gitmodules, the cached\nsubmodule.<name>.url in the superproject config can stay stale. Warn\nin git status so users can run git submodule sync before a later\nsubmodule operation uses the outdated URL.\n\nThe check considers three URLs: the .gitmodules URL resolved against\nthe superproject's default remote, the cached submodule.<name>.url, and\nthe submodule's default remote URL. The first two determine whether the\ncached URL is stale. If they differ, compare the submodule remote with\nthe old and new URLs as sync would write them. Warn only when that\nremote matches either URL; a different URL or multiple URLs indicate a\nlocal customization that sync would otherwise overwrite.\n\nResolve relative URLs using the same paths as git submodule sync, and\ndo not resolve the already-resolved cached URL a second time. Emit the\nwarning on standard error for long, short, and porcelain status output,\nlimited to submodules matched by the pathspec. Do not emit it when\n--ignore-submodules is given or when the wt-status machinery is used by\nanother command.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n Documentation/git-status.adoc |   6 ++\n builtin/commit.c              |   1 +\n submodule.c                   |   6 +-\n t/t7508-status.sh             |  84 ++++++++++++++++++++++++\n wt-status.c                   | 120 ++++++++++++++++++++++++++++++++++\n wt-status.h                   |   1 +\n 6 files changed, 217 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-status.adoc b/Documentation/git-status.adoc\nindex 9acca52bfb..1e0831a98e 100644\n--- a/Documentation/git-status.adoc\n+++ b/Documentation/git-status.adoc\n@@ -22,6 +22,12 @@ are what you _would_ commit by running `git commit`; the second and\n third are what you _could_ commit by running `git add` before running\n `git commit`.\n \n+When a submodule's URL in `.gitmodules` differs from the URL cached in\n+`.git/config`, `git status` warns that `git submodule sync` can update the\n+cached URL. The warning is written to standard error in all output formats.\n+It is limited to submodules matched by the pathspec, and is suppressed when\n+`--ignore-submodules` is specified.\n+\n OPTIONS\n -------\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 36e47e18ed..577b097aa0 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1636,6 +1636,7 @@ struct repository *repo UNUSED)\n \n \ts.ignore_submodule_arg = ignore_submodule_arg;\n \ts.status_format = status_format;\n+\ts.check_submodule_urls = 1;\n \ts.verbose = verbose;\n \tif (no_renames != -1)\n \t\ts.detect_rename = !no_renames;\ndiff --git a/submodule.c b/submodule.c\nindex 3eab799f1f..24775b21b7 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -296,9 +296,13 @@ char *resolve_submodule_url(struct repository *repo, const char *rel_url,\n \t\t\t    const char *up_path, int quiet)\n {\n \tchar *remoteurl, *resolved_url;\n-\tconst char *remote = repo_default_remote(repo);\n+\tconst char *remote;\n \tstruct strbuf remotesb = STRBUF_INIT;\n \n+\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n+\t\treturn xstrdup(rel_url);\n+\n+\tremote = repo_default_remote(repo);\n \tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n \tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n \t\tif (!quiet)\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..830217b4a5 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -921,6 +921,90 @@ test_expect_success 'setup status submodule summary' '\n \tgit add sm\n '\n \n+test_expect_success 'status reports submodule URL mismatch' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_create_repo url-test/source &&\n+\ttest_commit -C url-test/source initial &&\n+\ttest_create_repo url-test/super &&\n+\tgit -C url-test/super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/source\" module &&\n+\tgit -C url-test/super commit -m \"add submodule\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t\"$PWD/url-test/updated-source\" &&\n+\tgit -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --short >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status -- module >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\ttest_grep \"git submodule sync\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super remote add origin ../source-parent &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config remote.origin.url \\\n+\t\t\"$PWD/url-test/fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config --add remote.origin.url \\\n+\t\t\"$PWD/url-test/another-fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config --unset-all remote.origin.url &&\n+\tgit -C url-test/super config --add submodule.module.url \\\n+\t\t\"$PWD/url-test/another-configured-source\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err\n+'\n+\n+test_expect_success 'status compares relative submodule URLs only once' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_create_repo url-test/relative-source &&\n+\ttest_commit -C url-test/relative-source initial &&\n+\ttest_create_repo url-test/relative-super &&\n+\tgit -C url-test/relative-super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/relative-source\" module &&\n+\tgit -C url-test/relative-super commit -m \"add submodule\" &&\n+\tgit -C url-test/relative-super remote add origin ../a/b &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod1 &&\n+\tgit -C url-test/relative-super submodule sync &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod2 &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err\n+'\n+\n test_expect_success 'status submodule summary is disabled by default' '\n \tcat >expect <<EOF &&\n On branch main\ndiff --git a/wt-status.c b/wt-status.c\nindex 238bb48643..5bcbe634df 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -3,6 +3,8 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n+#include \"abspath.h\"\n+#include \"config.h\"\n #include \"wt-status.h\"\n #include \"object.h\"\n #include \"dir.h\"\n@@ -23,6 +25,8 @@\n #include \"remote.h\"\n #include \"refs.h\"\n #include \"submodule.h\"\n+#include \"url.h\"\n+#include \"submodule-config.h\"\n #include \"column.h\"\n #include \"read-cache.h\"\n #include \"setup.h\"\n@@ -2692,8 +2696,124 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n \t}\n }\n \n+static int submodule_has_custom_remote_url(struct repository *repo,\n+\t\t\t\t\t  const char *path,\n+\t\t\t\t\t  const char *gitmodules_url,\n+\t\t\t\t\t  const char *config_url)\n+{\n+\tstruct repository subrepo = { 0 };\n+\tconst struct string_list *remote_urls = NULL;\n+\tconst char *remote;\n+\tconst char *remote_url;\n+\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n+\tint error_code, ret = 0;\n+\n+\tif (!is_submodule_populated_gently(path, &error_code))\n+\t\treturn 0;\n+\n+\tif (repo_submodule_init(&subrepo, repo, path,\n+\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n+\t\trepo_clear(&subrepo);\n+\t\treturn 0;\n+\t}\n+\n+\tremote = repo_default_remote(&subrepo);\n+\n+\tkey = xstrfmt(\"remote.%s.url\", remote);\n+\tif (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&\n+\t    remote_urls->nr == 1) {\n+\t\tremote_url = remote_urls->items[0].string;\n+\t\tup_path = get_submodule_up_path(path);\n+\t\t/*\n+\t\t * sync_submodule() stores a relative URL in the superproject's\n+\t\t * config without the submodule path prefix, but adds that prefix\n+\t\t * when storing the URL in the submodule's remote configuration.\n+\t\t */\n+\t\tif (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {\n+\t\t\tstruct strbuf sb = STRBUF_INIT;\n+\n+\t\t\tstrbuf_addstr(&sb, up_path);\n+\t\t\tstrbuf_addstr(&sb, config_url);\n+\t\t\tconfig_remote_url = strbuf_detach(&sb, NULL);\n+\t\t} else {\n+\t\t\tconfig_remote_url = xstrdup(config_url);\n+\t\t}\n+\t\tgitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,\n+\t\t\t\t\t\t\t      up_path, 1);\n+\t\t/*\n+\t\t * The submodule's remote URL may be a local fork. If it matches\n+\t\t * neither the old cached URL nor the new .gitmodules URL, leave it\n+\t\t * alone; syncing would overwrite that customization.\n+\t\t */\n+\t\tret = strcmp(remote_url, config_remote_url) != 0 &&\n+\t\t\tstrcmp(remote_url, gitmodules_remote_url) != 0;\n+\t\tfree(gitmodules_remote_url);\n+\t\tfree(config_remote_url);\n+\t\tfree(up_path);\n+\t} else {\n+\t\t/*\n+\t\t * Multiple URLs are a local customization; sync would replace\n+\t\t * them all with a single URL.\n+\t\t */\n+\t\tret = remote_urls && remote_urls->nr > 1;\n+\t}\n+\tfree(key);\n+\trepo_clear(&subrepo);\n+\n+\treturn ret;\n+}\n+\n+static void wt_status_check_submodule_urls(struct wt_status *s)\n+{\n+\tint i;\n+\n+\tif (!s->check_submodule_urls || s->ignore_submodule_arg)\n+\t\treturn;\n+\n+\tif (is_gitmodules_unmerged(s->repo->index))\n+\t\treturn;\n+\n+\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n+\t\tconst struct submodule *sub;\n+\t\tchar *config_url;\n+\t\tchar *key, *gitmodules_url;\n+\n+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||\n+\t\t    !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))\n+\t\t\tcontinue;\n+\n+\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n+\t\t\t\t\t  ce->name);\n+\t\tif (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n+\t\t\tcontinue;\n+\n+\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n+\t\tif (repo_config_get_string(s->repo, key, &config_url)) {\n+\t\t\tfree(key);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfree(key);\n+\n+\t\tgitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n+\t\tif (strcmp(config_url, gitmodules_url) &&\n+\t\t    !submodule_has_custom_remote_url(s->repo, ce->name,\n+\t\t\t\t\t\t     sub->url,\n+\t\t\t\t\t\t     config_url))\n+\t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n+\t\t\t\t  \"than in .gitmodules\\n\"\n+\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n+\n+\t\tfree(config_url);\n+\t\tfree(gitmodules_url);\n+\t}\n+}\n+\n void wt_status_print(struct wt_status *s)\n {\n+\tif (s->check_submodule_urls)\n+\t\twt_status_check_submodule_urls(s);\n+\n \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n \t\t\t   s->untracked.nr);\ndiff --git a/wt-status.h b/wt-status.h\nindex e9fe32e98c..45eeb8b558 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -123,6 +123,7 @@ struct wt_status {\n \tunsigned colopts;\n \tint null_termination;\n \tint commit_template;\n+\tint check_submodule_urls;\n \tint show_branch;\n \tint show_stash;\n \tint hints;\n-- \ngitgitgadget\n\n"},{"id":"559575","messageId":"xmqq4id1zktq.fsf@gitster.g","threadId":"66944","inReplyTo":"fc300295ffaef49b592307a90ac3e58bb803b7ca.1795814853.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 1/2] submodule: prepare URL helpers for reuse","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-28T03:38:57Z","receivedAt":"2026-11-28T03:38:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Alessio Attilio via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Alessio Attilio <attilio.alessio@protonmail.com>\n>\n> Move the relative submodule URL resolver and the helper that computes\n> the path back to the superproject from builtin/submodule--helper.c to\n> submodule.c so they can be shared with git status.\n>\n> Pass the repository explicitly to the resolver instead of relying on\n> the_repository, and update existing callers to use the shared helpers.\n\nThis preparatory extraction may make the next patch easier to read.\n\nRemoving the get_default_remote() wrapper that has only one caller, and\ncalling repo_default_remote(repo) directly is safe too, because\nrepo_default_remote() returns a pointer owned by repo->remote_state (or\na static \"origin\" string) and repo_config_get_string() does not\ninvalidate remote_state before relative_url() runs.\n\n> Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n> ---\n>  builtin/submodule--helper.c | 63 ++++++-------------------------------\n>  submodule.c                 | 41 ++++++++++++++++++++++++\n>  submodule.h                 |  3 ++\n>  3 files changed, 54 insertions(+), 53 deletions(-)\n\nWhile this takes 'repo', the fallback when remote.<remote>.url is unset\nstill calls xgetcwd().  For current callers ('submodule--helper' and\n'git status' under RUN_SETUP | NEED_WORK_TREE), the working directory is\nalready the superproject worktree root, so behavior is preserved.\n\nStill, if a future caller passes a 'struct repository *' for another\nworktree or subrepository, xgetcwd() will resolve relative URLs against\nthe process working directory instead of repo->worktree.\n\nUsing\n\n    remoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd();\n\nmay make the helper genuinely repository-aware, perhaps?\n\nIn any case, the \"repository-aware\" change should be a separate step,\noutside the \"move code around\" step, right?\n\n> diff --git a/submodule.h b/submodule.h\n> index 1a465a1208..2028f272c4 100644\n> --- a/submodule.h\n> +++ b/submodule.h\n> @@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,\n>  \t\t\t     const struct object_id *treeish_name,\n>  \t\t\t     const char *path);\n>  int is_submodule_active(struct repository *repo, const char *path);\n> +char *resolve_submodule_url(struct repository *repo, const char *url,\n> +\t\t\t    const char *up_path, int quiet);\n> +char *get_submodule_up_path(const char *path);\n\nThe header names the second parameter 'url', while the definition in\nsubmodule.c names it 'rel_url'.\n\nIt would help to add comments above the declarations of these two\nfunctions and to document that callers free the returned string, that\n'up_path' may be NULL, and that get_submodule_up_path() expects a\nnon-empty 'path' (because it indexes path[strlen(path) - 1]).  It would\nmatch the surrounding declarations in this header file.\n\n"},{"id":"559577","messageId":"xmqqv75hy4va.fsf@gitster.g","threadId":"66944","inReplyTo":"9dc62830755b06ca2a95d307dd0b593d2a77c536.1795814853.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 2/2] status: warn about stale submodule URLs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-28T04:08:57Z","receivedAt":"2026-11-28T04:08:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Alessio Attilio via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> Resolve relative URLs using the same paths as git submodule sync, and\n> do not resolve the already-resolved cached URL a second time. Emit the\n> warning on standard error for long, short, and porcelain status output,\n> limited to submodules matched by the pathspec. Do not emit it when\n> --ignore-submodules is given or when the wt-status machinery is used by\n> another command.\n\nThe three-URL check now avoids double-resolving config_url and\ngitmodules_url when the superproject remote URL is relative, and\nswitches from the get_value() config readers to the get_string()\nfamily.\n\nThe check at the beginning of wt_status_check_submodule_urls() has\nbeen replaced with different logic, but I thought that we agreed to\nmove the check to the caller, wt_status_print(), to avoid calling\nthis new helper?  There also is a glaring bug in the updated logic\nfor the \"--ignore-submodules\" check.\n\nOther than these, the issues in the remainder of the patch I saw in\nan earlier round got much better.\n\n> diff --git a/submodule.c b/submodule.c\n> index 3eab799f1f..24775b21b7 100644\n> --- a/submodule.c\n> +++ b/submodule.c\n> @@ -296,9 +296,13 @@ char *resolve_submodule_url(struct repository *repo, const char *rel_url,\n>  \t\t\t    const char *up_path, int quiet)\n>  {\n>  \tchar *remoteurl, *resolved_url;\n> -\tconst char *remote = repo_default_remote(repo);\n> +\tconst char *remote;\n>  \tstruct strbuf remotesb = STRBUF_INIT;\n>  \n> +\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n> +\t\treturn xstrdup(rel_url);\n\nIt would make resolve_submodule_url() self-contained if you moved this\nearly return into the preparatory patch (the one you will split out of\n[1/2] for the \"repository aware\" step).  It would allow callers in\nbuiltin/submodule--helper.c to drop duplicate checks if desired, too.\n\nAlso, starts_with_dot_dot_slash() assumes 'rel_url' is non-NULL;\nwt_status_check_submodule_urls() checks sub->url first, so current\ncallers are safe, though an explicit NULL guard or doc comment in\nsubmodule.h may be worth considering to prevent future surprises.\n\n> diff --git a/wt-status.c b/wt-status.c\n> index 238bb48643..5bcbe634df 100644\n> --- a/wt-status.c\n> +++ b/wt-status.c\n> @@ -2692,8 +2696,124 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n>  \t}\n>  }\n>  \n> +static int submodule_has_custom_remote_url(struct repository *repo,\n> +\t\t\t\t\t  const char *path,\n> +\t\t\t\t\t  const char *gitmodules_url,\n> +\t\t\t\t\t  const char *config_url)\n> +{\n> +\tstruct repository subrepo = { 0 };\n> +\tconst struct string_list *remote_urls = NULL;\n> +\tconst char *remote;\n> +\tconst char *remote_url;\n> +\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n> +\tint error_code, ret = 0;\n> +\n> +\tif (!is_submodule_populated_gently(path, &error_code))\n> +\t\treturn 0;\n> +\n> +\tif (repo_submodule_init(&subrepo, repo, path,\n> +\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n> +\t\trepo_clear(&subrepo);\n> +\t\treturn 0;\n> +\t}\n> +\n> +\tremote = repo_default_remote(&subrepo);\n> +\n> +\tkey = xstrfmt(\"remote.%s.url\", remote);\n\nIn builtin/submodule--helper.c, sync_submodule() picks which submodule\nremote to update by calling get_default_remote_submodule().\n\nThat helper checks repo_remote_from_url() against the resolved\n.gitmodules URL first and falls back to repo_default_remote(&subrepo)\nonly if no remote matches.  If a submodule has both a customized\n'origin' remote and an 'upstream' remote that matches what .gitmodules\nhas, sync_submodule() updates 'upstream' without touching 'origin',\nwhereas submodule_has_custom_remote_url() checks only 'origin' and\nsuppresses the warning.\n\nChecking only the default remote is reasonable for the common\nsingle-remote case, though it is worth keeping this subtle difference in\nmind.\n\n> +static void wt_status_check_submodule_urls(struct wt_status *s)\n> +{\n> +\tint i;\n> +\n> +\tif (!s->check_submodule_urls || s->ignore_submodule_arg)\n> +\t\treturn;\n\nI do not think checking .ignore_submodule_arg like this helps.  It is of\ntype \"const char *\", so I assume it holds string values like \"none\" that\nyou will get when\n\n    git status --ignore-submodules=none\n\nis run, right?  You do not want to punt in such a case.\n\nComparing against wt_longstatus_print() in wt-status.c shows how other\nstatus checks handle this:\n\n    if (s->submodule_summary &&\n        (!s->ignore_submodule_arg ||\n         strcmp(s->ignore_submodule_arg, \"all\"))) {\n\nUsing\n\n    if (!s->check_submodule_urls ||\n        (s->ignore_submodule_arg &&\n         !strcmp(s->ignore_submodule_arg, \"all\")))\n            return;\n\nhere keeps '--ignore-submodules=none' (and =dirty/=untracked) warning as\nexpected, and matches \"suppressed when '--ignore-submodules=all' (or\nbare '--ignore-submodules') is specified\" in the docs and commit log.\n\n"},{"id":"559579","messageId":"xmqqmrqty4e9.fsf@gitster.g","threadId":"66944","inReplyTo":"pull.2509.v3.git.git.1795814853.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 0/2] status: report when submodule URLs are out of sync","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-28T04:19:10Z","receivedAt":"2026-11-28T04:19:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Alessio Attilio via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> When a submodule URL changes in .gitmodules, the corresponding URL in the\n> superproject's .git/config may keep pointing at the old location. This\n> series makes git status warn about that mismatch and suggest git submodule\n> sync.\n>\n> The warning resolves relative URLs as git submodule sync does. It also\n> suppresses the warning when the populated submodule has a custom remote URL\n> that a sync would overwrite.\n>\n> The series is split into:\n>\n>  1. submodule: move URL helpers to submodule.c\n>  2. submodule: make URL resolution repository-aware\n>  3. status: warn about stale submodule URLs\n\nThe cover letter describes a three-patch split, and the changelog notes\nmoving repository-aware URL resolution into its own commit, yet this v3\nseries contains two patches where patch 1/2 both relocates the helpers\nand takes 'struct repository *repo' (matching the two-patch range-diff\nagainst v2).  Sent before finishing the work and checking if the result\nmatches the cover letter description, perhaps?\n\n"},{"id":"559604","messageId":"pull.2509.v4.git.git.1795884822.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.git.git.1795774880142.gitgitgadget@gmail.com","subject":"[PATCH v4 0/3] status: report when submodule URLs are out of sync","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-28T16:53:39Z","receivedAt":"2026-11-28T16:53:39Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"When a submodule URL changes in .gitmodules, the corresponding URL in the\nsuperproject's .git/config may keep pointing at the old location. This\nseries makes git status warn about that mismatch and suggest git submodule\nsync.\n\nThe warning resolves relative URLs as git submodule sync does. It also\nsuppresses the warning when the populated submodule has a custom remote URL\nthat a sync would overwrite.\n\nThe series is split into:\n\n 1. submodule: move URL helpers to submodule.c\n 2. submodule: make URL resolution repository-aware\n 3. status: warn about stale submodule URLs\n\nChanges since v2:\n\n * Keep the helper relocation in a preparatory commit.\n * Move repository-aware URL resolution into its own commit.\n * Keep test output inside its fixture directory.\n\nCloses gitgitgadget/git#565\n\nAlessio Attilio (3):\n  submodule: move URL helpers into submodule.c\n  submodule: make URL resolution repository-aware\n  status: report when submodule URLs are out of sync\n\n Documentation/git-status.adoc |  12 ++++\n builtin/commit.c              |   1 +\n builtin/submodule--helper.c   |  60 ++---------------\n submodule.c                   |  45 +++++++++++++\n submodule.h                   |  12 ++++\n t/t7508-status.sh             | 100 ++++++++++++++++++++++++++++\n wt-status.c                   | 120 ++++++++++++++++++++++++++++++++++\n wt-status.h                   |   1 +\n 8 files changed, 298 insertions(+), 53 deletions(-)\n\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v4\nPull-Request: https://github.com/git/git/pull/2509\n\nRange-diff vs v3:\n\n 1:  fc300295ff ! 1:  b09e8501ed submodule: prepare URL helpers for reuse\n     @@ Metadata\n      Author: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n       ## Commit message ##\n     -    submodule: prepare URL helpers for reuse\n     +    submodule: move URL helpers into submodule.c\n      \n     -    Move the relative submodule URL resolver and the helper that computes\n     -    the path back to the superproject from builtin/submodule--helper.c to\n     -    submodule.c so they can be shared with git status.\n     +    Move the relative submodule URL resolver and the helper that\n     +    computes the path back to the superproject from\n     +    builtin/submodule--helper.c to submodule.c. This lets other\n     +    callers reuse the helpers.\n      \n     -    Pass the repository explicitly to the resolver instead of relying on\n     -    the_repository, and update existing callers to use the shared helpers.\n     +    Return non-relative URLs unchanged before consulting remote\n     +    configuration, so the resolver handles every URL form itself.\n     +    Keep the repository parameter change for the next patch.\n      \n          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n     @@ builtin/submodule--helper.c: static int get_default_remote_submodule(const char\n       \t\t\tchar *oldurl = url;\n       \n      -\t\t\turl = resolve_relative_url(oldurl, NULL, 1);\n     -+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 1);\n     ++\t\t\turl = resolve_submodule_url(oldurl, NULL, 1);\n       \t\t\tfree(oldurl);\n       \t\t}\n       \t}\n     @@ builtin/submodule--helper.c: static void init_submodule(const char *path, const\n       \t\t\tchar *oldurl = url;\n       \n      -\t\t\turl = resolve_relative_url(oldurl, NULL, 0);\n     -+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 0);\n     ++\t\t\turl = resolve_submodule_url(oldurl, NULL, 0);\n       \t\t\tfree(oldurl);\n       \t\t}\n       \n     @@ builtin/submodule--helper.c: static void sync_submodule(const char *path, const\n       \n      -\t\t\tsub_origin_url = resolve_relative_url(sub->url, up_path, 1);\n      -\t\t\tsuper_config_url = resolve_relative_url(sub->url, NULL, 1);\n     -+\t\t\tsub_origin_url = resolve_submodule_url(the_repository, sub->url,\n     -+\t\t\t\t\t\t\t      up_path, 1);\n     -+\t\t\tsuper_config_url = resolve_submodule_url(the_repository,\n     -+\t\t\t\t\t\t\t\t sub->url, NULL, 1);\n     ++\t\t\tsub_origin_url = resolve_submodule_url(sub->url, up_path, 1);\n     ++\t\t\tsuper_config_url = resolve_submodule_url(sub->url, NULL, 1);\n       \t\t\tfree(up_path);\n       \t\t} else {\n       \t\t\tsub_origin_url = xstrdup(sub->url);\n     @@ builtin/submodule--helper.c: static int prepare_to_clone_next_submodule(const st\n       \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n       \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n      -\t\t\turl = resolve_relative_url(sub->url, NULL, 0);\n     -+\t\t\turl = resolve_submodule_url(the_repository, sub->url, NULL, 0);\n     ++\t\t\turl = resolve_submodule_url(sub->url, NULL, 0);\n       \t\t\tneed_free_url = 1;\n       \t\t} else\n       \t\t\turl = sub->url;\n     @@ builtin/submodule--helper.c: static int module_add(int argc, const char **argv,\n       \n       \t\t/* dereference source url relative to parent's url */\n      -\t\tto_free = resolve_relative_url(add_data.repo, NULL, 1);\n     -+\t\tto_free = resolve_submodule_url(the_repository, add_data.repo,\n     -+\t\t\t\t\t\tNULL, 1);\n     ++\t\tto_free = resolve_submodule_url(add_data.repo, NULL, 1);\n       \t\tadd_data.realrepo = to_free;\n       \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n       \t\tadd_data.realrepo = add_data.repo;\n     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)\n       \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n       }\n       \n     -+char *resolve_submodule_url(struct repository *repo, const char *rel_url,\n     -+\t\t\t    const char *up_path, int quiet)\n     ++static char *get_default_remote(void)\n     ++{\n     ++\treturn xstrdup(repo_default_remote(the_repository));\n     ++}\n     ++\n     ++char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)\n      +{\n      +\tchar *remoteurl, *resolved_url;\n     -+\tconst char *remote = repo_default_remote(repo);\n     ++\tchar *remote;\n      +\tstruct strbuf remotesb = STRBUF_INIT;\n      +\n     ++\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n     ++\t\treturn xstrdup(rel_url);\n     ++\n     ++\tremote = get_default_remote();\n      +\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n     -+\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n     ++\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n      +\t\tif (!quiet)\n      +\t\t\twarning(_(\"could not look up configuration '%s'. \"\n      +\t\t\t\t  \"Assuming this repository is its own \"\n     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)\n      +\t}\n      +\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n      +\n     ++\tfree(remote);\n      +\tfree(remoteurl);\n      +\tstrbuf_release(&remotesb);\n      +\n     @@ submodule.h: int is_tree_submodule_active(struct repository *repo,\n       \t\t\t     const struct object_id *treeish_name,\n       \t\t\t     const char *path);\n       int is_submodule_active(struct repository *repo, const char *path);\n     -+char *resolve_submodule_url(struct repository *repo, const char *url,\n     -+\t\t\t    const char *up_path, int quiet);\n     ++char *resolve_submodule_url(const char *url, const char *up_path, int quiet);\n      +char *get_submodule_up_path(const char *path);\n       /*\n        * Determine if a submodule has been populated at a given 'path' by checking if\n -:  ---------- > 2:  ad4dafd82b submodule: make URL resolution repository-aware\n 2:  9dc6283075 ! 3:  619101d5e1 status: warn about stale submodule URLs\n     @@ Metadata\n      Author: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n       ## Commit message ##\n     -    status: warn about stale submodule URLs\n     +    status: report when submodule URLs are out of sync\n      \n     -    When a submodule URL changes in .gitmodules, the cached\n     -    submodule.<name>.url in the superproject config can stay stale. Warn\n     -    in git status so users can run git submodule sync before a later\n     -    submodule operation uses the outdated URL.\n     +    When the URL in .gitmodules differs from the cached URL in the\n     +    superproject config, git status can help users discover that\n     +    submodule operations may use a stale location. Resolve relative\n     +    URLs the same way as git submodule sync does.\n      \n     -    The check considers three URLs: the .gitmodules URL resolved against\n     -    the superproject's default remote, the cached submodule.<name>.url, and\n     -    the submodule's default remote URL. The first two determine whether the\n     -    cached URL is stale. If they differ, compare the submodule remote with\n     -    the old and new URLs as sync would write them. Warn only when that\n     -    remote matches either URL; a different URL or multiple URLs indicate a\n     -    local customization that sync would otherwise overwrite.\n     +    For populated submodules, compare the default remote URL as well.\n     +    If it matches neither the cached URL nor the newly declared URL,\n     +    treat it as a local customization and do not suggest a sync that\n     +    would overwrite it. Multiple remote URLs are also treated as a\n     +    customization.\n      \n     -    Resolve relative URLs using the same paths as git submodule sync, and\n     -    do not resolve the already-resolved cached URL a second time. Emit the\n     -    warning on standard error for long, short, and porcelain status output,\n     -    limited to submodules matched by the pathspec. Do not emit it when\n     -    --ignore-submodules is given or when the wt-status machinery is used by\n     -    another command.\n     +    Emit the warning on standard error for long, short, and porcelain\n     +    formats. Respect pathspecs and suppress the check only when\n     +    --ignore-submodules=all (or its bare form) is given. Run the check\n     +    only for git status, not other users of the wt-status machinery.\n      \n          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n     @@ Documentation/git-status.adoc: are what you _would_ commit by running `git commi\n       \n      +When a submodule's URL in `.gitmodules` differs from the URL cached in\n      +`.git/config`, `git status` warns that `git submodule sync` can update the\n     -+cached URL. The warning is written to standard error in all output formats.\n     -+It is limited to submodules matched by the pathspec, and is suppressed when\n     -+`--ignore-submodules` is specified.\n     ++cached URL. For a populated submodule, the warning is suppressed when its\n     ++default remote URL differs from both URLs, since syncing would overwrite a\n     ++customized remote. Relative URLs are resolved as `git submodule sync`\n     ++resolves them.\n     ++\n     ++The warning is written to standard error in long, short, and porcelain\n     ++formats, and is limited to submodules matched by the pathspec. It is\n     ++suppressed when `--ignore-submodules` or `--ignore-submodules=all` is\n     ++specified.\n      +\n       OPTIONS\n       -------\n     @@ builtin/commit.c: struct repository *repo UNUSED)\n       \tif (no_renames != -1)\n       \t\ts.detect_rename = !no_renames;\n      \n     - ## submodule.c ##\n     -@@ submodule.c: char *resolve_submodule_url(struct repository *repo, const char *rel_url,\n     - \t\t\t    const char *up_path, int quiet)\n     - {\n     - \tchar *remoteurl, *resolved_url;\n     --\tconst char *remote = repo_default_remote(repo);\n     -+\tconst char *remote;\n     - \tstruct strbuf remotesb = STRBUF_INIT;\n     - \n     -+\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n     -+\t\treturn xstrdup(rel_url);\n     -+\n     -+\tremote = repo_default_remote(repo);\n     - \tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n     - \tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n     - \t\tif (!quiet)\n     -\n       ## t/t7508-status.sh ##\n      @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n       \tgit add sm\n     @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n      +\t\t\"$PWD/url-test/updated-source\" &&\n      +\tgit -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&\n      +\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tcat >url-test/editor <<\\EOF &&\n     ++#!/bin/sh\n     ++echo \"status test commit\" >\"$1\"\n     ++EOF\n     ++\tchmod +x url-test/editor &&\n     ++\techo staged >url-test/super/staged &&\n     ++\tgit -C url-test/super add staged &&\n     ++\ttest_set_editor \"$PWD/url-test/editor\" &&\n     ++\tgit -C url-test/super commit >url-test/actual 2>url-test/err &&\n     ++\ttest_must_be_empty url-test/err &&\n      +\tgit -C url-test/super status --short >url-test/actual 2>url-test/err &&\n      +\ttest_grep \"module.*different URL\" url-test/err &&\n      +\tgit -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&\n      +\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tgit -C url-test/super status --ignore-submodules=none >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tgit -C url-test/super status --ignore-submodules=dirty >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tgit -C url-test/super status --ignore-submodules=all >url-test/actual 2>url-test/err &&\n     ++\ttest_must_be_empty url-test/err &&\n      +\tgit -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&\n      +\ttest_must_be_empty url-test/err &&\n      +\tgit -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\tremote = repo_default_remote(&subrepo);\n      +\n      +\tkey = xstrfmt(\"remote.%s.url\", remote);\n     -+\tif (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&\n     -+\t    remote_urls->nr == 1) {\n     -+\t\tremote_url = remote_urls->items[0].string;\n     ++\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n     ++\t    remote_urls->nr == 1 &&\n     ++\t    (remote_url = remote_urls->items[0].string)) {\n      +\t\tup_path = get_submodule_up_path(path);\n      +\t\t/*\n      +\t\t * sync_submodule() stores a relative URL in the superproject's\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +{\n      +\tint i;\n      +\n     -+\tif (!s->check_submodule_urls || s->ignore_submodule_arg)\n     ++\tif (s->ignore_submodule_arg &&\n     ++\t    !strcmp(s->ignore_submodule_arg, \"all\"))\n      +\t\treturn;\n      +\n      +\tif (is_gitmodules_unmerged(s->repo->index))\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n      +\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n      +\t\tconst struct submodule *sub;\n     -+\t\tchar *config_url;\n     ++\t\tconst char *config_url;\n      +\t\tchar *key, *gitmodules_url;\n      +\n      +\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\t\t\tcontinue;\n      +\n      +\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n     -+\t\tif (repo_config_get_string(s->repo, key, &config_url)) {\n     ++\t\tif (repo_config_get_value(s->repo, key, &config_url) || !config_url) {\n      +\t\t\tfree(key);\n      +\t\t\tcontinue;\n      +\t\t}\n     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n      +\t\t\t\t  \"than in .gitmodules\\n\"\n      +\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n      +\n     -+\t\tfree(config_url);\n      +\t\tfree(gitmodules_url);\n      +\t}\n      +}\n\n-- \ngitgitgadget\n\n"},{"id":"559605","messageId":"b09e8501ed8c6d29b75e021b72dccad81a03cfbd.1795884822.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v4.git.git.1795884822.gitgitgadget@gmail.com","subject":"[PATCH v4 1/3] submodule: move URL helpers into submodule.c","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-28T16:53:40Z","receivedAt":"2026-11-28T16:53:40Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nMove the relative submodule URL resolver and the helper that\ncomputes the path back to the superproject from\nbuiltin/submodule--helper.c to submodule.c. This lets other\ncallers reuse the helpers.\n\nReturn non-relative URLs unchanged before consulting remote\nconfiguration, so the resolver handles every URL form itself.\nKeep the repository parameter change for the next patch.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n builtin/submodule--helper.c | 60 +++++--------------------------------\n submodule.c                 | 50 +++++++++++++++++++++++++++++++\n submodule.h                 |  2 ++\n 3 files changed, 59 insertions(+), 53 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 461b682d0d..cc84968bd3 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -46,35 +46,6 @@\n typedef void (*each_submodule_fn)(const struct cache_entry *list_item,\n \t\t\t\t  void *cb_data);\n \n-static char *get_default_remote(void)\n-{\n-\treturn xstrdup(repo_default_remote(the_repository));\n-}\n-\n-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)\n-{\n-\tchar *remoteurl, *resolved_url;\n-\tchar *remote = get_default_remote();\n-\tstruct strbuf remotesb = STRBUF_INIT;\n-\n-\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n-\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n-\t\tif (!quiet)\n-\t\t\twarning(_(\"could not look up configuration '%s'. \"\n-\t\t\t\t  \"Assuming this repository is its own \"\n-\t\t\t\t  \"authoritative upstream.\"),\n-\t\t\t\tremotesb.buf);\n-\t\tremoteurl = xgetcwd();\n-\t}\n-\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n-\n-\tfree(remote);\n-\tfree(remoteurl);\n-\tstrbuf_release(&remotesb);\n-\n-\treturn resolved_url;\n-}\n-\n static int get_default_remote_submodule(const char *module_path, char **default_remote)\n {\n \tconst struct submodule *sub;\n@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 1);\n+\t\t\turl = resolve_submodule_url(oldurl, NULL, 1);\n \t\t\tfree(oldurl);\n \t\t}\n \t}\n@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)\n \t*list = active_modules;\n }\n \n-static char *get_up_path(const char *path)\n-{\n-\tstruct strbuf sb = STRBUF_INIT;\n-\n-\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n-\n-\t/*\n-\t * Check if 'path' ends with slash or not\n-\t * for having the same output for dir/sub_dir\n-\t * and dir/sub_dir/\n-\t */\n-\tif (!is_dir_sep(path[strlen(path) - 1]))\n-\t\tstrbuf_addstr(&sb, \"../\");\n-\n-\treturn strbuf_detach(&sb, NULL);\n-}\n-\n static void for_each_listed_submodule(const struct module_list *list,\n \t\t\t\t      each_submodule_fn fn, void *cb_data)\n {\n@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 0);\n+\t\t\turl = resolve_submodule_url(oldurl, NULL, 0);\n \t\t\tfree(oldurl);\n \t\t}\n \n@@ -1453,10 +1407,10 @@ static void sync_submodule(const char *path, const char *prefix,\n \tif (sub && sub->url) {\n \t\tif (starts_with_dot_dot_slash(sub->url) ||\n \t\t    starts_with_dot_slash(sub->url)) {\n-\t\t\tchar *up_path = get_up_path(path);\n+\t\t\tchar *up_path = get_submodule_up_path(path);\n \n-\t\t\tsub_origin_url = resolve_relative_url(sub->url, up_path, 1);\n-\t\t\tsuper_config_url = resolve_relative_url(sub->url, NULL, 1);\n+\t\t\tsub_origin_url = resolve_submodule_url(sub->url, up_path, 1);\n+\t\t\tsuper_config_url = resolve_submodule_url(sub->url, NULL, 1);\n \t\t\tfree(up_path);\n \t\t} else {\n \t\t\tsub_origin_url = xstrdup(sub->url);\n@@ -2334,7 +2288,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \tif (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {\n \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n-\t\t\turl = resolve_relative_url(sub->url, NULL, 0);\n+\t\t\turl = resolve_submodule_url(sub->url, NULL, 0);\n \t\t\tneed_free_url = 1;\n \t\t} else\n \t\t\turl = sub->url;\n@@ -3761,7 +3715,7 @@ static int module_add(int argc, const char **argv, const char *prefix,\n \t\t\t      \"of the working tree\"));\n \n \t\t/* dereference source url relative to parent's url */\n-\t\tto_free = resolve_relative_url(add_data.repo, NULL, 1);\n+\t\tto_free = resolve_submodule_url(add_data.repo, NULL, 1);\n \t\tadd_data.realrepo = to_free;\n \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n \t\tadd_data.realrepo = add_data.repo;\ndiff --git a/submodule.c b/submodule.c\nindex a74d1925aa..9b7bb5c2f3 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -292,6 +292,56 @@ int is_submodule_active(struct repository *repo, const char *path)\n \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n }\n \n+static char *get_default_remote(void)\n+{\n+\treturn xstrdup(repo_default_remote(the_repository));\n+}\n+\n+char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)\n+{\n+\tchar *remoteurl, *resolved_url;\n+\tchar *remote;\n+\tstruct strbuf remotesb = STRBUF_INIT;\n+\n+\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n+\t\treturn xstrdup(rel_url);\n+\n+\tremote = get_default_remote();\n+\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n+\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n+\t\tif (!quiet)\n+\t\t\twarning(_(\"could not look up configuration '%s'. \"\n+\t\t\t\t  \"Assuming this repository is its own \"\n+\t\t\t\t  \"authoritative upstream.\"),\n+\t\t\t\tremotesb.buf);\n+\t\tremoteurl = xgetcwd();\n+\t}\n+\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n+\n+\tfree(remote);\n+\tfree(remoteurl);\n+\tstrbuf_release(&remotesb);\n+\n+\treturn resolved_url;\n+}\n+\n+char *get_submodule_up_path(const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n+\n+\t/*\n+\t * Check if 'path' ends with slash or not\n+\t * for having the same output for dir/sub_dir\n+\t * and dir/sub_dir/\n+\t */\n+\tif (!is_dir_sep(path[strlen(path) - 1]))\n+\t\tstrbuf_addstr(&sb, \"../\");\n+\n+\treturn strbuf_detach(&sb, NULL);\n+}\n+\n int is_submodule_populated_gently(const char *path, int *return_error_code)\n {\n \tint ret = 0;\ndiff --git a/submodule.h b/submodule.h\nindex 1a465a1208..82972781b4 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -62,6 +62,8 @@ int is_tree_submodule_active(struct repository *repo,\n \t\t\t     const struct object_id *treeish_name,\n \t\t\t     const char *path);\n int is_submodule_active(struct repository *repo, const char *path);\n+char *resolve_submodule_url(const char *url, const char *up_path, int quiet);\n+char *get_submodule_up_path(const char *path);\n /*\n  * Determine if a submodule has been populated at a given 'path' by checking if\n  * the <path>/.git resolves to a valid git repository.\n-- \ngitgitgadget\n\n\n"},{"id":"559606","messageId":"ad4dafd82bb3759ab77805bb2fbc27ffd33c4e52.1795884822.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v4.git.git.1795884822.gitgitgadget@gmail.com","subject":"[PATCH v4 2/3] submodule: make URL resolution repository-aware","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-28T16:53:41Z","receivedAt":"2026-11-28T16:53:41Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nPass the repository explicitly to resolve_submodule_url() instead\nof relying on the_repository, and update existing callers. Resolve\nrelative URLs against the repository worktree when no default\nremote URL is configured.\n\nKeep this API change separate from moving the helpers. The\nnon-relative URL fast path is established in the preparatory\npatch and remains independent of repository lookup.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n builtin/submodule--helper.c | 12 ++++++------\n submodule.c                 | 23 +++++++++--------------\n submodule.h                 | 12 +++++++++++-\n 3 files changed, 26 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex cc84968bd3..a05372bae8 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -63,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_submodule_url(oldurl, NULL, 1);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 1);\n \t\t\tfree(oldurl);\n \t\t}\n \t}\n@@ -577,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_submodule_url(oldurl, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 0);\n \t\t\tfree(oldurl);\n \t\t}\n \n@@ -1409,8 +1409,8 @@ static void sync_submodule(const char *path, const char *prefix,\n \t\t    starts_with_dot_slash(sub->url)) {\n \t\t\tchar *up_path = get_submodule_up_path(path);\n \n-\t\t\tsub_origin_url = resolve_submodule_url(sub->url, up_path, 1);\n-\t\t\tsuper_config_url = resolve_submodule_url(sub->url, NULL, 1);\n+\t\t\tsub_origin_url = resolve_submodule_url(the_repository, sub->url, up_path, 1);\n+\t\t\tsuper_config_url = resolve_submodule_url(the_repository, sub->url, NULL, 1);\n \t\t\tfree(up_path);\n \t\t} else {\n \t\t\tsub_origin_url = xstrdup(sub->url);\n@@ -2288,7 +2288,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \tif (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {\n \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n-\t\t\turl = resolve_submodule_url(sub->url, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, sub->url, NULL, 0);\n \t\t\tneed_free_url = 1;\n \t\t} else\n \t\t\turl = sub->url;\n@@ -3715,7 +3715,7 @@ static int module_add(int argc, const char **argv, const char *prefix,\n \t\t\t      \"of the working tree\"));\n \n \t\t/* dereference source url relative to parent's url */\n-\t\tto_free = resolve_submodule_url(add_data.repo, NULL, 1);\n+\t\tto_free = resolve_submodule_url(the_repository, add_data.repo, NULL, 1);\n \t\tadd_data.realrepo = to_free;\n \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n \t\tadd_data.realrepo = add_data.repo;\ndiff --git a/submodule.c b/submodule.c\nindex 9b7bb5c2f3..c8d95538d0 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -292,33 +292,28 @@ int is_submodule_active(struct repository *repo, const char *path)\n \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n }\n \n-static char *get_default_remote(void)\n-{\n-\treturn xstrdup(repo_default_remote(the_repository));\n-}\n-\n-char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)\n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet)\n {\n \tchar *remoteurl, *resolved_url;\n-\tchar *remote;\n+\tconst char *remote;\n \tstruct strbuf remotesb = STRBUF_INIT;\n \n-\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n-\t\treturn xstrdup(rel_url);\n+\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n+\t\treturn xstrdup(url);\n \n-\tremote = get_default_remote();\n+\tremote = repo_default_remote(repo);\n \tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n-\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n+\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n \t\tif (!quiet)\n \t\t\twarning(_(\"could not look up configuration '%s'. \"\n \t\t\t\t  \"Assuming this repository is its own \"\n \t\t\t\t  \"authoritative upstream.\"),\n \t\t\t\tremotesb.buf);\n-\t\tremoteurl = xgetcwd();\n+\t\tremoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd();\n \t}\n-\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n+\tresolved_url = relative_url(remoteurl, url, up_path);\n \n-\tfree(remote);\n \tfree(remoteurl);\n \tstrbuf_release(&remotesb);\n \ndiff --git a/submodule.h b/submodule.h\nindex 82972781b4..477091cd3c 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -62,7 +62,17 @@ int is_tree_submodule_active(struct repository *repo,\n \t\t\t     const struct object_id *treeish_name,\n \t\t\t     const char *path);\n int is_submodule_active(struct repository *repo, const char *path);\n-char *resolve_submodule_url(const char *url, const char *up_path, int quiet);\n+/*\n+ * Resolve a relative submodule URL against the superproject's default remote.\n+ * 'url' must be non-NULL; 'up_path' may be NULL. The caller must free the\n+ * returned string.\n+ */\n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet);\n+/*\n+ * Return the path prefix from a submodule back to its superproject. 'path'\n+ * must be non-NULL and non-empty. The caller must free the returned string.\n+ */\n char *get_submodule_up_path(const char *path);\n /*\n  * Determine if a submodule has been populated at a given 'path' by checking if\n-- \ngitgitgadget\n\n\n"},{"id":"559607","messageId":"619101d5e124115a43faf51c84655b7b99a431dd.1795884822.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v4.git.git.1795884822.gitgitgadget@gmail.com","subject":"[PATCH v4 3/3] status: report when submodule URLs are out of sync","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-28T16:53:42Z","receivedAt":"2026-11-28T16:53:42Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nWhen the URL in .gitmodules differs from the cached URL in the\nsuperproject config, git status can help users discover that\nsubmodule operations may use a stale location. Resolve relative\nURLs the same way as git submodule sync does.\n\nFor populated submodules, compare the default remote URL as well.\nIf it matches neither the cached URL nor the newly declared URL,\ntreat it as a local customization and do not suggest a sync that\nwould overwrite it. Multiple remote URLs are also treated as a\ncustomization.\n\nEmit the warning on standard error for long, short, and porcelain\nformats. Respect pathspecs and suppress the check only when\n--ignore-submodules=all (or its bare form) is given. Run the check\nonly for git status, not other users of the wt-status machinery.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n Documentation/git-status.adoc |  12 ++++\n builtin/commit.c              |   1 +\n t/t7508-status.sh             | 100 ++++++++++++++++++++++++++++\n wt-status.c                   | 120 ++++++++++++++++++++++++++++++++++\n wt-status.h                   |   1 +\n 5 files changed, 234 insertions(+)\n\ndiff --git a/Documentation/git-status.adoc b/Documentation/git-status.adoc\nindex 9acca52bfb..6e997fbef0 100644\n--- a/Documentation/git-status.adoc\n+++ b/Documentation/git-status.adoc\n@@ -22,6 +22,18 @@ are what you _would_ commit by running `git commit`; the second and\n third are what you _could_ commit by running `git add` before running\n `git commit`.\n \n+When a submodule's URL in `.gitmodules` differs from the URL cached in\n+`.git/config`, `git status` warns that `git submodule sync` can update the\n+cached URL. For a populated submodule, the warning is suppressed when its\n+default remote URL differs from both URLs, since syncing would overwrite a\n+customized remote. Relative URLs are resolved as `git submodule sync`\n+resolves them.\n+\n+The warning is written to standard error in long, short, and porcelain\n+formats, and is limited to submodules matched by the pathspec. It is\n+suppressed when `--ignore-submodules` or `--ignore-submodules=all` is\n+specified.\n+\n OPTIONS\n -------\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 36e47e18ed..577b097aa0 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1636,6 +1636,7 @@ struct repository *repo UNUSED)\n \n \ts.ignore_submodule_arg = ignore_submodule_arg;\n \ts.status_format = status_format;\n+\ts.check_submodule_urls = 1;\n \ts.verbose = verbose;\n \tif (no_renames != -1)\n \t\ts.detect_rename = !no_renames;\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..ce85920380 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -921,6 +921,106 @@ test_expect_success 'setup status submodule summary' '\n \tgit add sm\n '\n \n+test_expect_success 'status reports submodule URL mismatch' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_create_repo url-test/source &&\n+\ttest_commit -C url-test/source initial &&\n+\ttest_create_repo url-test/super &&\n+\tgit -C url-test/super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/source\" module &&\n+\tgit -C url-test/super commit -m \"add submodule\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t\"$PWD/url-test/updated-source\" &&\n+\tgit -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tcat >url-test/editor <<\\EOF &&\n+#!/bin/sh\n+echo \"status test commit\" >\"$1\"\n+EOF\n+\tchmod +x url-test/editor &&\n+\techo staged >url-test/super/staged &&\n+\tgit -C url-test/super add staged &&\n+\ttest_set_editor \"$PWD/url-test/editor\" &&\n+\tgit -C url-test/super commit >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status --short >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules=none >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules=dirty >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules=all >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status -- module >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\ttest_grep \"git submodule sync\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super remote add origin ../source-parent &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config remote.origin.url \\\n+\t\t\"$PWD/url-test/fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config --add remote.origin.url \\\n+\t\t\"$PWD/url-test/another-fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config --unset-all remote.origin.url &&\n+\tgit -C url-test/super config --add submodule.module.url \\\n+\t\t\"$PWD/url-test/another-configured-source\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err\n+'\n+\n+test_expect_success 'status compares relative submodule URLs only once' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_create_repo url-test/relative-source &&\n+\ttest_commit -C url-test/relative-source initial &&\n+\ttest_create_repo url-test/relative-super &&\n+\tgit -C url-test/relative-super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/relative-source\" module &&\n+\tgit -C url-test/relative-super commit -m \"add submodule\" &&\n+\tgit -C url-test/relative-super remote add origin ../a/b &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod1 &&\n+\tgit -C url-test/relative-super submodule sync &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod2 &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err\n+'\n+\n test_expect_success 'status submodule summary is disabled by default' '\n \tcat >expect <<EOF &&\n On branch main\ndiff --git a/wt-status.c b/wt-status.c\nindex 238bb48643..84fb985a4e 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -3,6 +3,8 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n+#include \"abspath.h\"\n+#include \"config.h\"\n #include \"wt-status.h\"\n #include \"object.h\"\n #include \"dir.h\"\n@@ -23,6 +25,8 @@\n #include \"remote.h\"\n #include \"refs.h\"\n #include \"submodule.h\"\n+#include \"url.h\"\n+#include \"submodule-config.h\"\n #include \"column.h\"\n #include \"read-cache.h\"\n #include \"setup.h\"\n@@ -2692,8 +2696,124 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n \t}\n }\n \n+static int submodule_has_custom_remote_url(struct repository *repo,\n+\t\t\t\t\t  const char *path,\n+\t\t\t\t\t  const char *gitmodules_url,\n+\t\t\t\t\t  const char *config_url)\n+{\n+\tstruct repository subrepo = { 0 };\n+\tconst struct string_list *remote_urls = NULL;\n+\tconst char *remote;\n+\tconst char *remote_url;\n+\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n+\tint error_code, ret = 0;\n+\n+\tif (!is_submodule_populated_gently(path, &error_code))\n+\t\treturn 0;\n+\n+\tif (repo_submodule_init(&subrepo, repo, path,\n+\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n+\t\trepo_clear(&subrepo);\n+\t\treturn 0;\n+\t}\n+\n+\tremote = repo_default_remote(&subrepo);\n+\n+\tkey = xstrfmt(\"remote.%s.url\", remote);\n+\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n+\t    remote_urls->nr == 1 &&\n+\t    (remote_url = remote_urls->items[0].string)) {\n+\t\tup_path = get_submodule_up_path(path);\n+\t\t/*\n+\t\t * sync_submodule() stores a relative URL in the superproject's\n+\t\t * config without the submodule path prefix, but adds that prefix\n+\t\t * when storing the URL in the submodule's remote configuration.\n+\t\t */\n+\t\tif (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {\n+\t\t\tstruct strbuf sb = STRBUF_INIT;\n+\n+\t\t\tstrbuf_addstr(&sb, up_path);\n+\t\t\tstrbuf_addstr(&sb, config_url);\n+\t\t\tconfig_remote_url = strbuf_detach(&sb, NULL);\n+\t\t} else {\n+\t\t\tconfig_remote_url = xstrdup(config_url);\n+\t\t}\n+\t\tgitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,\n+\t\t\t\t\t\t\t      up_path, 1);\n+\t\t/*\n+\t\t * The submodule's remote URL may be a local fork. If it matches\n+\t\t * neither the old cached URL nor the new .gitmodules URL, leave it\n+\t\t * alone; syncing would overwrite that customization.\n+\t\t */\n+\t\tret = strcmp(remote_url, config_remote_url) != 0 &&\n+\t\t\tstrcmp(remote_url, gitmodules_remote_url) != 0;\n+\t\tfree(gitmodules_remote_url);\n+\t\tfree(config_remote_url);\n+\t\tfree(up_path);\n+\t} else {\n+\t\t/*\n+\t\t * Multiple URLs are a local customization; sync would replace\n+\t\t * them all with a single URL.\n+\t\t */\n+\t\tret = remote_urls && remote_urls->nr > 1;\n+\t}\n+\tfree(key);\n+\trepo_clear(&subrepo);\n+\n+\treturn ret;\n+}\n+\n+static void wt_status_check_submodule_urls(struct wt_status *s)\n+{\n+\tint i;\n+\n+\tif (s->ignore_submodule_arg &&\n+\t    !strcmp(s->ignore_submodule_arg, \"all\"))\n+\t\treturn;\n+\n+\tif (is_gitmodules_unmerged(s->repo->index))\n+\t\treturn;\n+\n+\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n+\t\tconst struct submodule *sub;\n+\t\tconst char *config_url;\n+\t\tchar *key, *gitmodules_url;\n+\n+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||\n+\t\t    !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))\n+\t\t\tcontinue;\n+\n+\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n+\t\t\t\t\t  ce->name);\n+\t\tif (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n+\t\t\tcontinue;\n+\n+\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n+\t\tif (repo_config_get_value(s->repo, key, &config_url) || !config_url) {\n+\t\t\tfree(key);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfree(key);\n+\n+\t\tgitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n+\t\tif (strcmp(config_url, gitmodules_url) &&\n+\t\t    !submodule_has_custom_remote_url(s->repo, ce->name,\n+\t\t\t\t\t\t     sub->url,\n+\t\t\t\t\t\t     config_url))\n+\t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n+\t\t\t\t  \"than in .gitmodules\\n\"\n+\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n+\n+\t\tfree(gitmodules_url);\n+\t}\n+}\n+\n void wt_status_print(struct wt_status *s)\n {\n+\tif (s->check_submodule_urls)\n+\t\twt_status_check_submodule_urls(s);\n+\n \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n \t\t\t   s->untracked.nr);\ndiff --git a/wt-status.h b/wt-status.h\nindex e9fe32e98c..45eeb8b558 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -123,6 +123,7 @@ struct wt_status {\n \tunsigned colopts;\n \tint null_termination;\n \tint commit_template;\n+\tint check_submodule_urls;\n \tint show_branch;\n \tint show_stash;\n \tint hints;\n-- \ngitgitgadget\n\n"},{"id":"559637","messageId":"xmqqfqwjod8f.fsf@gitster.g","threadId":"66944","inReplyTo":"619101d5e124115a43faf51c84655b7b99a431dd.1795884822.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 3/3] status: report when submodule URLs are out of sync","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-29T15:42:56Z","receivedAt":"2026-11-29T15:42:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Alessio Attilio via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index 36e47e18ed..577b097aa0 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -1636,6 +1636,7 @@ struct repository *repo UNUSED)\n>  \n>  \ts.ignore_submodule_arg = ignore_submodule_arg;\n>  \ts.status_format = status_format;\n> +\ts.check_submodule_urls = 1;\n\nThe hunk header unfortunately is hard to read but this is inside\ncmd_status().\n\nNow whichever format wt_status_print() is triggered with, we will show\nthe submodule changes but only when the top-level command is \"git\nstatus\".\n\nGood.\n\n> diff --git a/wt-status.c b/wt-status.c\n> ...\n> +static int submodule_has_custom_remote_url(struct repository *repo,\n> +\t\t\t\t\t  const char *path,\n> +\t\t\t\t\t  const char *gitmodules_url,\n> +\t\t\t\t\t  const char *config_url)\n> +{\n> +\tstruct repository subrepo = { 0 };\n> +\tconst struct string_list *remote_urls = NULL;\n> +\tconst char *remote;\n> +\tconst char *remote_url;\n> +\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n> +\tint error_code, ret = 0;\n> +\n> +\tif (!is_submodule_populated_gently(path, &error_code))\n> +\t\treturn 0;\n> +\n> +\tif (repo_submodule_init(&subrepo, repo, path,\n> +\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n> +\t\trepo_clear(&subrepo);\n> +\t\treturn 0;\n> +\t}\n> +\n> +\tremote = repo_default_remote(&subrepo);\n> +\n> +\tkey = xstrfmt(\"remote.%s.url\", remote);\n> +\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n> +\t    remote_urls->nr == 1 &&\n> +\t    (remote_url = remote_urls->items[0].string)) {\n\nThe third condition being a non-NULL check of the value and not a\ncomparison can easily become confusing.  GNU toolchains seem to\nencourage putting such a \"var = value\" assignment that is also used for\na non-NULL/0 check inside an extra pair of parentheses, which is the\nconvention the above code also uses.  Use of the _get_value_ variant and\nchecking the NULL-ness of .string allows us to cope with a valueless\ntruth \"[remote \"frotz\"] url;\" cleanly.\n\n> +static int submodule_has_custom_remote_url(struct repository *repo,\n> +\t\t\t\t\t  const char *path,\n> +\t\t\t\t\t  const char *gitmodules_url,\n> +\t\t\t\t\t  const char *config_url)\n> +{\n> +\tstruct repository subrepo = { 0 };\n> +\tconst struct string_list *remote_urls = NULL;\n> +\tconst char *remote;\n> +\tconst char *remote_url;\n> +\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n> +\tint error_code, ret = 0;\n> +\n> +\tif (!is_submodule_populated_gently(path, &error_code))\n> +\t\treturn 0;\n> +\n> +\tif (repo_submodule_init(&subrepo, repo, path,\n> +\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n> +\t\trepo_clear(&subrepo);\n> +\t\treturn 0;\n> +\t}\n\nDo we see a small inconsistency with the repository-aware design from\nthe previous patch here?\n\nThis function takes 'repo' and passes it to repo_submodule_init() and\nresolve_submodule_url(), yet is_submodule_populated_gently() inspects\n\"%s/.git\" relative to the current working directory rather than the\n'.worktree' member of 'repo'.  \n\nThat may be harmless today because cmd_status() runs with NEED_WORK_TREE\nand repo == the_repository, so we are always at the worktree root.  It\nmight be worth a comment near the call to is_submodule_populated_gently()\nthough.\n\n> +static void wt_status_check_submodule_urls(struct wt_status *s)\n> +{\n> +\tint i;\n> +\n> +\tif (s->ignore_submodule_arg &&\n> +\t    !strcmp(s->ignore_submodule_arg, \"all\"))\n> +\t\treturn;\n> +\n> +\tif (is_gitmodules_unmerged(s->repo->index))\n> +\t\treturn;\n> +\n> +\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n> +\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n\nBecause cmd_status() sets '.command_requires_full_index' to 0, you need\nto be careful when iterating '.cache' directly like the above loop when\nsparse-index is in effect.\n\nIn sparse-index.c, convert_to_sparse_rec() refuses to collapse any\ndirectory containing S_ISGITLINK entries, so I _think_ gitlinks remain\nvisible even in a sparse index, but please double check.\n\nOverall, this iteration was a very pleasant read.\nThanks for working on it.\n\n"},{"id":"559706","messageId":"CALnO6CBdBZYTHpRRtdctoHDdXiDs-PBuNrxoW9SULk3-WZJC6A@mail.gmail.com","threadId":"66944","inReplyTo":"xmqqecc69maa.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] status: warn about stale submodule URLs","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-11-30T15:46:00Z","receivedAt":"2026-11-30T15:46:00Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Fri, Nov 27, 2026 at 1:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Alessio Attilio via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n>\n> > From: Alessio Attilio <attilio.alessio@protonmail.com>\n> >\n> > When a submodule URL changes in .gitmodules, the cached\n> > submodule.<name>.url in the superproject config can stay stale. Warn\n> > in git status so users can run git submodule sync before a later\n> > submodule operation uses the outdated URL.\n> >\n> > Resolve relative URLs using the same paths as git submodule sync.\n> > Avoid warning when the submodule remote indicates a local\n> > customization that sync would overwrite.\n> >\n> > Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n> > ---\n>\n> Surfacing stale submodule configuration in \"git status\" is a very useful\n> improvement.  Like Ben noted, splitting the helper extraction out into a\n> preparatory commit made the series easier to follow.\n>\n> It would help to explain in the proposed log message why three URLs are\n> compared and under what condition, and which status formats emit the\n> warning.\n\nIndeed, I was minded of \"reviewing is a discussion\"\n(https://lore.kernel.org/git/20261022211404.380904-3-gitster@pobox.com/)\nand \"good manners\" being to discuss before sending off v2\n(https://lore.kernel.org/git/xmqqmrquetqq.fsf@gitster.g/).\n\n> > +             up_path = get_submodule_up_path(path);\n> > +             config_remote_url = resolve_submodule_url(repo, config_url,\n> > +                                                       up_path, 1);\n> > +             gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,\n> > +                                                           up_path, 1);\n> > +             /*\n> > +              * The submodule's remote URL may be a local fork. If it matches\n> > +              * neither the old cached URL nor the new .gitmodules URL, leave it\n> > +              * alone; syncing would overwrite that customization.\n> > +              */\n> > +             ret = strcmp(remote_url, config_remote_url) != 0 &&\n> > +                     strcmp(remote_url, gitmodules_remote_url) != 0;\n>\n> Renaming of new/old may address one of the points of confusion Ben had.\n\nI think so: it now seems that \"remote_url\" is the one from the\nsubmodule (e.g., git -C sub remote -v), config_*url is the cached URL,\nand gitmodules_*url is, well, the .gitmodules URL.\n\n> When the superproject's own default remote URL is relative, doesn't\n> this logic break?\n>\n> In wt_status_check_submodule_urls() we see below, 'gitmodules_url' was\n> already computed by resolving sub->url against the superproject's\n> default remote with 'up_path' set to NULL.  Likewise, 'config_url' from\n> submodule.<name>.url in .git/config was already resolved once with\n> 'up_path' set to NULL when init_submodule() or sync_submodule() wrote\n> it.\n>\n> Passing already-resolved URLs into resolve_submodule_url() again smells\n> fishy.  There are a few ways I can think of that this can break.  I may\n> be misreading the code flow, and these may be no issue, or there may be\n> other issues.\n\nI mentioned the double-resolution in passing before, thanks for making\nthe potential issues (which I only thought of for performance) more\nexplicit.\n\n>  * When the superproject has \"remote.origin.url = a/b\" (relative without\n>    \"./\" or \"../\") and .gitmodules has \"../mod1\", sync_submodule() stores\n>    \"a/mod1\" in submodule.module.url and \"../a/mod1\" in the submodule's\n>    remote.origin.url.\n>\n>    submodule_has_custom_remote_url() calls resolve_submodule_url() on\n>    \"a/mod1\".  It hits the early return without prepending 'up_path', so\n>    'config_remote_url' is \"a/mod1\" instead of \"../a/mod1\" and fails to\n>    match.\n>\n>  * When the superproject has \"remote.origin.url = ../a/b\", .gitmodules\n>    initially has \"submodule.module.url = ../mod1\", and the user runs\n>    \"git submodule sync\".  In sync_submodule(), relative_url() stores\n>    \"../a/mod1\" in submodule.module.url and \"../../a/mod1\" in the\n>    submodule's remote.origin.url.\n>\n>    If submodule.module.url in .gitmodules then changes to \"../mod2\",\n>    wt_status_check_submodule_urls() sets 'gitmodules_remote_url' to\n>    \"../a/mod2\".  Inside submodule_has_custom_remote_url(), both\n>    \"../a/mod1\" and \"../a/mod2\" still start with \"../\", so\n>    resolve_submodule_url() resolves them a second time against \"../a/b\".\n>\n>    Wouldn't the result be \"../../a/a/mod1\" and \"../../a/a/mod2\" in such\n>    a case?\n>\n>    Neither matches \"../../a/mod1\", so submodule_has_custom_remote_url()\n>    returns 1 and suppresses the warning even though the submodule remote\n>    was never customized.  The new test in t7508 used \"../source-parent\"\n>    with only one path component after \"..\", where the second resolution\n>    happened to be a no-op, so it may not have noticed the breakage.\n>\n> In order to match what sync_submodule() does, 'gitmodules_remote_url'\n> should be computed from the raw 'sub->url', not from 'gitmodules_url',\n> no?  For 'config_remote_url', we do not want to run relative_url() again\n> on 'config_url', I think.  You only need to prepend 'up_path', or\n> something, no?  I didn't think this one through, so take it with a huge\n> grain of salt.\n\nThanks,\nBen\n\n"},{"id":"559707","messageId":"CALnO6CCP1=G0eF_GTgCkc4MxiK-zXS7yk_q_v5sMxOxVC6afTQ@mail.gmail.com","threadId":"66944","inReplyTo":"b09e8501ed8c6d29b75e021b72dccad81a03cfbd.1795884822.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 1/3] submodule: move URL helpers into submodule.c","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-11-30T15:54:26Z","receivedAt":"2026-11-30T15:54:26Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"Hi Alessio,\n\nOn Sat, Nov 28, 2026 at 11:53 AM Alessio Attilio via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Alessio Attilio <attilio.alessio@protonmail.com>\n>\n> Move the relative submodule URL resolver and the helper that\n> computes the path back to the superproject from\n> builtin/submodule--helper.c to submodule.c. This lets other\n> callers reuse the helpers.\n>\n> Return non-relative URLs unchanged before consulting remote\n> configuration, so the resolver handles every URL form itself.\n> Keep the repository parameter change for the next patch.\n\nThis comment applies to [2/3] also: it is normal to explain a\npreparatory commit by discussing what it prepares for (\"lets other\ncallers reuse the helpers\"), but I find the sentence \"Keep the\nrepository parameter change for the next patch\" very unusual.\n\nA future reader must wonder: what change? (And why \"the change\"?) The\nanswers only make sense in context of prior iterations, not\nnecessarily in context of the final commits upstream.\n\nI would rephrase (or drop that line altogether):\n\n    We also want to make these helpers repository-aware, but do that\nin a later step to make it easy to see the code movement.\n\nperhaps?\n\n-- \nD. Ben Knoble\n\n"},{"id":"559709","messageId":"CALnO6CAOJugzrCQn0zDit-rG0ORu7ZFHgTtw1FvOB9eBGcTzHA@mail.gmail.com","threadId":"66944","inReplyTo":"ad4dafd82bb3759ab77805bb2fbc27ffd33c4e52.1795884822.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v4 2/3] submodule: make URL resolution repository-aware","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-11-30T15:56:05Z","receivedAt":"2026-11-30T15:56:05Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"On Sat, Nov 28, 2026 at 11:54 AM Alessio Attilio via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Alessio Attilio <attilio.alessio@protonmail.com>\n>\n> Pass the repository explicitly to resolve_submodule_url() instead\n> of relying on the_repository, and update existing callers. Resolve\n> relative URLs against the repository worktree when no default\n> remote URL is configured.\n>\n> Keep this API change separate from moving the helpers. The\n> non-relative URL fast path is established in the preparatory\n> patch and remains independent of repository lookup.\n\nThis is the paragraph in [2/3] that corresponds to the unusual\nsentence in [1/3]. These would make fine \"changes\" notes on the commit\nor cover letter, but this paragraph especially doesn't belong in the\nproposed log message.\n\n"},{"id":"559837","messageId":"pull.2509.v5.git.git.1796159338.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.git.git.1795774880142.gitgitgadget@gmail.com","subject":"[PATCH v5 0/4] status: report when submodule URLs are out of sync","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-12-01T21:08:54Z","receivedAt":"2026-12-01T21:08:54Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"When a submodule URL changes in .gitmodules, the URL cached in the\nsuperproject's .git/config can remain stale. This change makes git status\nreport the mismatch and suggest git submodule sync.\n\nRelative URLs are resolved as git submodule sync resolves them. For\npopulated submodules, the check follows the remote that git submodule sync\nwould update. Local remote customizations are respected so the advice does\nnot suggest overwriting them.\n\nThe warning is written to standard error for long, short, and porcelain\nformats, follows pathspecs, and is suppressed by --ignore-submodules=all.\n\nCloses gitgitgadget/git#565\n\nAlessio Attilio (4):\n  submodule: share repository-aware URL resolution\n  status: warn about submodule URL mismatches\n  status: preserve customized submodule remotes\n  status: test submodule URL warnings\n\n Documentation/git-status.adoc |  12 +++\n builtin/commit.c              |   1 +\n builtin/submodule--helper.c   |  60 ++-------------\n submodule.c                   |  45 +++++++++++\n submodule.h                   |  12 +++\n t/t7508-status.sh             | 121 ++++++++++++++++++++++++++++++\n wt-status.c                   | 136 ++++++++++++++++++++++++++++++++++\n wt-status.h                   |   1 +\n 8 files changed, 335 insertions(+), 53 deletions(-)\n\n\nbase-commit: 566b6997dd4710b625c0882cf10a7443bf52d183\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v5\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v5\nPull-Request: https://github.com/git/git/pull/2509\n\nRange-diff vs v4:\n\n 1:  b09e8501ed ! 1:  35d9d09ebe submodule: move URL helpers into submodule.c\n     @@ Metadata\n      Author: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n       ## Commit message ##\n     -    submodule: move URL helpers into submodule.c\n     +    submodule: share repository-aware URL resolution\n      \n     -    Move the relative submodule URL resolver and the helper that\n     -    computes the path back to the superproject from\n     -    builtin/submodule--helper.c to submodule.c. This lets other\n     -    callers reuse the helpers.\n     -\n     -    Return non-relative URLs unchanged before consulting remote\n     -    configuration, so the resolver handles every URL form itself.\n     -    Keep the repository parameter change for the next patch.\n     +    Status must resolve relative submodule URLs against the same remote as\n     +    git submodule sync. Move the resolver into common submodule code and\n     +    pass the repository explicitly, preserving existing helper behavior.\n      \n          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n     @@ builtin/submodule--helper.c: static int get_default_remote_submodule(const char\n       \t\t\tchar *oldurl = url;\n       \n      -\t\t\turl = resolve_relative_url(oldurl, NULL, 1);\n     -+\t\t\turl = resolve_submodule_url(oldurl, NULL, 1);\n     ++\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 1);\n       \t\t\tfree(oldurl);\n       \t\t}\n       \t}\n     @@ builtin/submodule--helper.c: static void init_submodule(const char *path, const\n       \t\t\tchar *oldurl = url;\n       \n      -\t\t\turl = resolve_relative_url(oldurl, NULL, 0);\n     -+\t\t\turl = resolve_submodule_url(oldurl, NULL, 0);\n     ++\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 0);\n       \t\t\tfree(oldurl);\n       \t\t}\n       \n     @@ builtin/submodule--helper.c: static void sync_submodule(const char *path, const\n       \n      -\t\t\tsub_origin_url = resolve_relative_url(sub->url, up_path, 1);\n      -\t\t\tsuper_config_url = resolve_relative_url(sub->url, NULL, 1);\n     -+\t\t\tsub_origin_url = resolve_submodule_url(sub->url, up_path, 1);\n     -+\t\t\tsuper_config_url = resolve_submodule_url(sub->url, NULL, 1);\n     ++\t\t\tsub_origin_url = resolve_submodule_url(the_repository, sub->url, up_path, 1);\n     ++\t\t\tsuper_config_url = resolve_submodule_url(the_repository, sub->url, NULL, 1);\n       \t\t\tfree(up_path);\n       \t\t} else {\n       \t\t\tsub_origin_url = xstrdup(sub->url);\n     @@ builtin/submodule--helper.c: static int prepare_to_clone_next_submodule(const st\n       \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n       \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n      -\t\t\turl = resolve_relative_url(sub->url, NULL, 0);\n     -+\t\t\turl = resolve_submodule_url(sub->url, NULL, 0);\n     ++\t\t\turl = resolve_submodule_url(the_repository, sub->url, NULL, 0);\n       \t\t\tneed_free_url = 1;\n       \t\t} else\n       \t\t\turl = sub->url;\n     @@ builtin/submodule--helper.c: static int module_add(int argc, const char **argv,\n       \n       \t\t/* dereference source url relative to parent's url */\n      -\t\tto_free = resolve_relative_url(add_data.repo, NULL, 1);\n     -+\t\tto_free = resolve_submodule_url(add_data.repo, NULL, 1);\n     ++\t\tto_free = resolve_submodule_url(the_repository, add_data.repo, NULL, 1);\n       \t\tadd_data.realrepo = to_free;\n       \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n       \t\tadd_data.realrepo = add_data.repo;\n     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)\n       \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n       }\n       \n     -+static char *get_default_remote(void)\n     -+{\n     -+\treturn xstrdup(repo_default_remote(the_repository));\n     -+}\n     -+\n     -+char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)\n     ++char *resolve_submodule_url(struct repository *repo, const char *url,\n     ++\t\t\t    const char *up_path, int quiet)\n      +{\n      +\tchar *remoteurl, *resolved_url;\n     -+\tchar *remote;\n     ++\tconst char *remote;\n      +\tstruct strbuf remotesb = STRBUF_INIT;\n      +\n     -+\tif (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))\n     -+\t\treturn xstrdup(rel_url);\n     ++\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n     ++\t\treturn xstrdup(url);\n      +\n     -+\tremote = get_default_remote();\n     ++\tremote = repo_default_remote(repo);\n      +\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n     -+\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n     ++\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n      +\t\tif (!quiet)\n      +\t\t\twarning(_(\"could not look up configuration '%s'. \"\n      +\t\t\t\t  \"Assuming this repository is its own \"\n      +\t\t\t\t  \"authoritative upstream.\"),\n      +\t\t\t\tremotesb.buf);\n     -+\t\tremoteurl = xgetcwd();\n     ++\t\tremoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd();\n      +\t}\n     -+\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n     ++\tresolved_url = relative_url(remoteurl, url, up_path);\n      +\n     -+\tfree(remote);\n      +\tfree(remoteurl);\n      +\tstrbuf_release(&remotesb);\n      +\n     @@ submodule.h: int is_tree_submodule_active(struct repository *repo,\n       \t\t\t     const struct object_id *treeish_name,\n       \t\t\t     const char *path);\n       int is_submodule_active(struct repository *repo, const char *path);\n     -+char *resolve_submodule_url(const char *url, const char *up_path, int quiet);\n     ++/*\n     ++ * Resolve a relative submodule URL against the superproject's default remote.\n     ++ * 'url' must be non-NULL; 'up_path' may be NULL. The caller must free the\n     ++ * returned string.\n     ++ */\n     ++char *resolve_submodule_url(struct repository *repo, const char *url,\n     ++\t\t\t    const char *up_path, int quiet);\n     ++/*\n     ++ * Return the path prefix from a submodule back to its superproject. 'path'\n     ++ * must be non-NULL and non-empty. The caller must free the returned string.\n     ++ */\n      +char *get_submodule_up_path(const char *path);\n       /*\n        * Determine if a submodule has been populated at a given 'path' by checking if\n 2:  ad4dafd82b < -:  ---------- submodule: make URL resolution repository-aware\n -:  ---------- > 2:  6db7dc9415 status: warn about submodule URL mismatches\n -:  ---------- > 3:  d80542df12 status: preserve customized submodule remotes\n 3:  619101d5e1 ! 4:  ec282a2a6c status: report when submodule URLs are out of sync\n     @@ Metadata\n      Author: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n       ## Commit message ##\n     -    status: report when submodule URLs are out of sync\n     +    status: test submodule URL warnings\n      \n     -    When the URL in .gitmodules differs from the cached URL in the\n     -    superproject config, git status can help users discover that\n     -    submodule operations may use a stale location. Resolve relative\n     -    URLs the same way as git submodule sync does.\n     -\n     -    For populated submodules, compare the default remote URL as well.\n     -    If it matches neither the cached URL nor the newly declared URL,\n     -    treat it as a local customization and do not suggest a sync that\n     -    would overwrite it. Multiple remote URLs are also treated as a\n     -    customization.\n     -\n     -    Emit the warning on standard error for long, short, and porcelain\n     -    formats. Respect pathspecs and suppress the check only when\n     -    --ignore-submodules=all (or its bare form) is given. Run the check\n     -    only for git status, not other users of the wt-status machinery.\n     +    Exercise the warning and sync advice across output formats, relative URLs,\n     +    pathspecs, ignored submodules, populated remotes, and commit status.\n     +    Document when the warning appears and how to clear the mismatch.\n      \n          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n      \n     @@ Documentation/git-status.adoc: are what you _would_ commit by running `git commi\n       -------\n       \n      \n     - ## builtin/commit.c ##\n     -@@ builtin/commit.c: struct repository *repo UNUSED)\n     - \n     - \ts.ignore_submodule_arg = ignore_submodule_arg;\n     - \ts.status_format = status_format;\n     -+\ts.check_submodule_urls = 1;\n     - \ts.verbose = verbose;\n     - \tif (no_renames != -1)\n     - \t\ts.detect_rename = !no_renames;\n     -\n       ## t/t7508-status.sh ##\n      @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n       \tgit add sm\n     @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n      +\t\t../fork-source &&\n      +\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n      +\ttest_must_be_empty url-test/err &&\n     ++\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n     ++\t\t\"$PWD/url-test/upstream-source\" &&\n     ++\tgit -C url-test/super submodule sync &&\n     ++\tgit -C url-test/super/module config remote.upstream.url \\\n     ++\t\t\"$PWD/url-test/upstream-source\" &&\n     ++\tgit -C url-test/super/module config remote.origin.url \\\n     ++\t\t\"$PWD/url-test/fork\" &&\n     ++\tgit -C url-test/super config submodule.module.url \\\n     ++\t\t\"$PWD/url-test/stale-source\" &&\n     ++\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n      +\tgit -C url-test/super/module config --add remote.origin.url \\\n      +\t\t\"$PWD/url-test/another-fork\" &&\n      +\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n     @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '\n      +\tgit -C url-test/relative-super config -f .gitmodules \\\n      +\t\tsubmodule.module.url ../mod2 &&\n      +\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n     ++\ttest_grep \"module.*different URL\" url-test/err &&\n     ++\tgit -C url-test/relative-super remote set-url origin a/b &&\n     ++\tgit -C url-test/relative-super config -f .gitmodules \\\n     ++\t\tsubmodule.module.url ../mod1 &&\n     ++\tgit -C url-test/relative-super submodule sync &&\n     ++\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n     ++\ttest_must_be_empty url-test/err &&\n     ++\tgit -C url-test/relative-super config -f .gitmodules \\\n     ++\t\tsubmodule.module.url ../mod2 &&\n     ++\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n      +\ttest_grep \"module.*different URL\" url-test/err\n      +'\n      +\n       test_expect_success 'status submodule summary is disabled by default' '\n       \tcat >expect <<EOF &&\n       On branch main\n     -\n     - ## wt-status.c ##\n     -@@\n     - \n     - #include \"git-compat-util.h\"\n     - #include \"advice.h\"\n     -+#include \"abspath.h\"\n     -+#include \"config.h\"\n     - #include \"wt-status.h\"\n     - #include \"object.h\"\n     - #include \"dir.h\"\n     -@@\n     - #include \"remote.h\"\n     - #include \"refs.h\"\n     - #include \"submodule.h\"\n     -+#include \"url.h\"\n     -+#include \"submodule-config.h\"\n     - #include \"column.h\"\n     - #include \"read-cache.h\"\n     - #include \"setup.h\"\n     -@@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)\n     - \t}\n     - }\n     - \n     -+static int submodule_has_custom_remote_url(struct repository *repo,\n     -+\t\t\t\t\t  const char *path,\n     -+\t\t\t\t\t  const char *gitmodules_url,\n     -+\t\t\t\t\t  const char *config_url)\n     -+{\n     -+\tstruct repository subrepo = { 0 };\n     -+\tconst struct string_list *remote_urls = NULL;\n     -+\tconst char *remote;\n     -+\tconst char *remote_url;\n     -+\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n     -+\tint error_code, ret = 0;\n     -+\n     -+\tif (!is_submodule_populated_gently(path, &error_code))\n     -+\t\treturn 0;\n     -+\n     -+\tif (repo_submodule_init(&subrepo, repo, path,\n     -+\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n     -+\t\trepo_clear(&subrepo);\n     -+\t\treturn 0;\n     -+\t}\n     -+\n     -+\tremote = repo_default_remote(&subrepo);\n     -+\n     -+\tkey = xstrfmt(\"remote.%s.url\", remote);\n     -+\tif (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&\n     -+\t    remote_urls->nr == 1 &&\n     -+\t    (remote_url = remote_urls->items[0].string)) {\n     -+\t\tup_path = get_submodule_up_path(path);\n     -+\t\t/*\n     -+\t\t * sync_submodule() stores a relative URL in the superproject's\n     -+\t\t * config without the submodule path prefix, but adds that prefix\n     -+\t\t * when storing the URL in the submodule's remote configuration.\n     -+\t\t */\n     -+\t\tif (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {\n     -+\t\t\tstruct strbuf sb = STRBUF_INIT;\n     -+\n     -+\t\t\tstrbuf_addstr(&sb, up_path);\n     -+\t\t\tstrbuf_addstr(&sb, config_url);\n     -+\t\t\tconfig_remote_url = strbuf_detach(&sb, NULL);\n     -+\t\t} else {\n     -+\t\t\tconfig_remote_url = xstrdup(config_url);\n     -+\t\t}\n     -+\t\tgitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,\n     -+\t\t\t\t\t\t\t      up_path, 1);\n     -+\t\t/*\n     -+\t\t * The submodule's remote URL may be a local fork. If it matches\n     -+\t\t * neither the old cached URL nor the new .gitmodules URL, leave it\n     -+\t\t * alone; syncing would overwrite that customization.\n     -+\t\t */\n     -+\t\tret = strcmp(remote_url, config_remote_url) != 0 &&\n     -+\t\t\tstrcmp(remote_url, gitmodules_remote_url) != 0;\n     -+\t\tfree(gitmodules_remote_url);\n     -+\t\tfree(config_remote_url);\n     -+\t\tfree(up_path);\n     -+\t} else {\n     -+\t\t/*\n     -+\t\t * Multiple URLs are a local customization; sync would replace\n     -+\t\t * them all with a single URL.\n     -+\t\t */\n     -+\t\tret = remote_urls && remote_urls->nr > 1;\n     -+\t}\n     -+\tfree(key);\n     -+\trepo_clear(&subrepo);\n     -+\n     -+\treturn ret;\n     -+}\n     -+\n     -+static void wt_status_check_submodule_urls(struct wt_status *s)\n     -+{\n     -+\tint i;\n     -+\n     -+\tif (s->ignore_submodule_arg &&\n     -+\t    !strcmp(s->ignore_submodule_arg, \"all\"))\n     -+\t\treturn;\n     -+\n     -+\tif (is_gitmodules_unmerged(s->repo->index))\n     -+\t\treturn;\n     -+\n     -+\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n     -+\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n     -+\t\tconst struct submodule *sub;\n     -+\t\tconst char *config_url;\n     -+\t\tchar *key, *gitmodules_url;\n     -+\n     -+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||\n     -+\t\t    !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))\n     -+\t\t\tcontinue;\n     -+\n     -+\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n     -+\t\t\t\t\t  ce->name);\n     -+\t\tif (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n     -+\t\t\tcontinue;\n     -+\n     -+\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n     -+\t\tif (repo_config_get_value(s->repo, key, &config_url) || !config_url) {\n     -+\t\t\tfree(key);\n     -+\t\t\tcontinue;\n     -+\t\t}\n     -+\t\tfree(key);\n     -+\n     -+\t\tgitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n     -+\t\tif (strcmp(config_url, gitmodules_url) &&\n     -+\t\t    !submodule_has_custom_remote_url(s->repo, ce->name,\n     -+\t\t\t\t\t\t     sub->url,\n     -+\t\t\t\t\t\t     config_url))\n     -+\t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n     -+\t\t\t\t  \"than in .gitmodules\\n\"\n     -+\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n     -+\n     -+\t\tfree(gitmodules_url);\n     -+\t}\n     -+}\n     -+\n     - void wt_status_print(struct wt_status *s)\n     - {\n     -+\tif (s->check_submodule_urls)\n     -+\t\twt_status_check_submodule_urls(s);\n     -+\n     - \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n     - \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n     - \t\t\t   s->untracked.nr);\n     -\n     - ## wt-status.h ##\n     -@@ wt-status.h: struct wt_status {\n     - \tunsigned colopts;\n     - \tint null_termination;\n     - \tint commit_template;\n     -+\tint check_submodule_urls;\n     - \tint show_branch;\n     - \tint show_stash;\n     - \tint hints;\n\n-- \ngitgitgadget\n\n"},{"id":"559838","messageId":"35d9d09ebea6fa065b8266dcd87bf71f44594458.1796159338.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v5.git.git.1796159338.gitgitgadget@gmail.com","subject":"[PATCH v5 1/4] submodule: share repository-aware URL resolution","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-12-01T21:08:55Z","receivedAt":"2026-12-01T21:08:55Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nStatus must resolve relative submodule URLs against the same remote as\ngit submodule sync. Move the resolver into common submodule code and\npass the repository explicitly, preserving existing helper behavior.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n builtin/submodule--helper.c | 60 +++++--------------------------------\n submodule.c                 | 45 ++++++++++++++++++++++++++++\n submodule.h                 | 12 ++++++++\n 3 files changed, 64 insertions(+), 53 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 461b682d0d..a05372bae8 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -46,35 +46,6 @@\n typedef void (*each_submodule_fn)(const struct cache_entry *list_item,\n \t\t\t\t  void *cb_data);\n \n-static char *get_default_remote(void)\n-{\n-\treturn xstrdup(repo_default_remote(the_repository));\n-}\n-\n-static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)\n-{\n-\tchar *remoteurl, *resolved_url;\n-\tchar *remote = get_default_remote();\n-\tstruct strbuf remotesb = STRBUF_INIT;\n-\n-\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n-\tif (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {\n-\t\tif (!quiet)\n-\t\t\twarning(_(\"could not look up configuration '%s'. \"\n-\t\t\t\t  \"Assuming this repository is its own \"\n-\t\t\t\t  \"authoritative upstream.\"),\n-\t\t\t\tremotesb.buf);\n-\t\tremoteurl = xgetcwd();\n-\t}\n-\tresolved_url = relative_url(remoteurl, rel_url, up_path);\n-\n-\tfree(remote);\n-\tfree(remoteurl);\n-\tstrbuf_release(&remotesb);\n-\n-\treturn resolved_url;\n-}\n-\n static int get_default_remote_submodule(const char *module_path, char **default_remote)\n {\n \tconst struct submodule *sub;\n@@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 1);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 1);\n \t\t\tfree(oldurl);\n \t\t}\n \t}\n@@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list)\n \t*list = active_modules;\n }\n \n-static char *get_up_path(const char *path)\n-{\n-\tstruct strbuf sb = STRBUF_INIT;\n-\n-\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n-\n-\t/*\n-\t * Check if 'path' ends with slash or not\n-\t * for having the same output for dir/sub_dir\n-\t * and dir/sub_dir/\n-\t */\n-\tif (!is_dir_sep(path[strlen(path) - 1]))\n-\t\tstrbuf_addstr(&sb, \"../\");\n-\n-\treturn strbuf_detach(&sb, NULL);\n-}\n-\n static void for_each_listed_submodule(const struct module_list *list,\n \t\t\t\t      each_submodule_fn fn, void *cb_data)\n {\n@@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix,\n \t\t    starts_with_dot_slash(url)) {\n \t\t\tchar *oldurl = url;\n \n-\t\t\turl = resolve_relative_url(oldurl, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, oldurl, NULL, 0);\n \t\t\tfree(oldurl);\n \t\t}\n \n@@ -1453,10 +1407,10 @@ static void sync_submodule(const char *path, const char *prefix,\n \tif (sub && sub->url) {\n \t\tif (starts_with_dot_dot_slash(sub->url) ||\n \t\t    starts_with_dot_slash(sub->url)) {\n-\t\t\tchar *up_path = get_up_path(path);\n+\t\t\tchar *up_path = get_submodule_up_path(path);\n \n-\t\t\tsub_origin_url = resolve_relative_url(sub->url, up_path, 1);\n-\t\t\tsuper_config_url = resolve_relative_url(sub->url, NULL, 1);\n+\t\t\tsub_origin_url = resolve_submodule_url(the_repository, sub->url, up_path, 1);\n+\t\t\tsuper_config_url = resolve_submodule_url(the_repository, sub->url, NULL, 1);\n \t\t\tfree(up_path);\n \t\t} else {\n \t\t\tsub_origin_url = xstrdup(sub->url);\n@@ -2334,7 +2288,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \tif (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {\n \t\tif (sub->url && (starts_with_dot_slash(sub->url) ||\n \t\t\t\t starts_with_dot_dot_slash(sub->url))) {\n-\t\t\turl = resolve_relative_url(sub->url, NULL, 0);\n+\t\t\turl = resolve_submodule_url(the_repository, sub->url, NULL, 0);\n \t\t\tneed_free_url = 1;\n \t\t} else\n \t\t\turl = sub->url;\n@@ -3761,7 +3715,7 @@ static int module_add(int argc, const char **argv, const char *prefix,\n \t\t\t      \"of the working tree\"));\n \n \t\t/* dereference source url relative to parent's url */\n-\t\tto_free = resolve_relative_url(add_data.repo, NULL, 1);\n+\t\tto_free = resolve_submodule_url(the_repository, add_data.repo, NULL, 1);\n \t\tadd_data.realrepo = to_free;\n \t} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {\n \t\tadd_data.realrepo = add_data.repo;\ndiff --git a/submodule.c b/submodule.c\nindex a74d1925aa..c8d95538d0 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -292,6 +292,51 @@ int is_submodule_active(struct repository *repo, const char *path)\n \treturn is_tree_submodule_active(repo, null_oid(the_hash_algo), path);\n }\n \n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet)\n+{\n+\tchar *remoteurl, *resolved_url;\n+\tconst char *remote;\n+\tstruct strbuf remotesb = STRBUF_INIT;\n+\n+\tif (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))\n+\t\treturn xstrdup(url);\n+\n+\tremote = repo_default_remote(repo);\n+\tstrbuf_addf(&remotesb, \"remote.%s.url\", remote);\n+\tif (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {\n+\t\tif (!quiet)\n+\t\t\twarning(_(\"could not look up configuration '%s'. \"\n+\t\t\t\t  \"Assuming this repository is its own \"\n+\t\t\t\t  \"authoritative upstream.\"),\n+\t\t\t\tremotesb.buf);\n+\t\tremoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd();\n+\t}\n+\tresolved_url = relative_url(remoteurl, url, up_path);\n+\n+\tfree(remoteurl);\n+\tstrbuf_release(&remotesb);\n+\n+\treturn resolved_url;\n+}\n+\n+char *get_submodule_up_path(const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\n+\tstrbuf_addstrings(&sb, \"../\", count_slashes(path));\n+\n+\t/*\n+\t * Check if 'path' ends with slash or not\n+\t * for having the same output for dir/sub_dir\n+\t * and dir/sub_dir/\n+\t */\n+\tif (!is_dir_sep(path[strlen(path) - 1]))\n+\t\tstrbuf_addstr(&sb, \"../\");\n+\n+\treturn strbuf_detach(&sb, NULL);\n+}\n+\n int is_submodule_populated_gently(const char *path, int *return_error_code)\n {\n \tint ret = 0;\ndiff --git a/submodule.h b/submodule.h\nindex 1a465a1208..477091cd3c 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -62,6 +62,18 @@ int is_tree_submodule_active(struct repository *repo,\n \t\t\t     const struct object_id *treeish_name,\n \t\t\t     const char *path);\n int is_submodule_active(struct repository *repo, const char *path);\n+/*\n+ * Resolve a relative submodule URL against the superproject's default remote.\n+ * 'url' must be non-NULL; 'up_path' may be NULL. The caller must free the\n+ * returned string.\n+ */\n+char *resolve_submodule_url(struct repository *repo, const char *url,\n+\t\t\t    const char *up_path, int quiet);\n+/*\n+ * Return the path prefix from a submodule back to its superproject. 'path'\n+ * must be non-NULL and non-empty. The caller must free the returned string.\n+ */\n+char *get_submodule_up_path(const char *path);\n /*\n  * Determine if a submodule has been populated at a given 'path' by checking if\n  * the <path>/.git resolves to a valid git repository.\n-- \ngitgitgadget\n\n\n"},{"id":"559839","messageId":"6db7dc9415227488ddf422d35802a7c9569ddfa5.1796159338.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v5.git.git.1796159338.gitgitgadget@gmail.com","subject":"[PATCH v5 2/4] status: warn about submodule URL mismatches","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-12-01T21:08:56Z","receivedAt":"2026-12-01T21:08:56Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nWhen a user changes a URL in .gitmodules, the cached URL in .git/config\ncan remain stale and status looks clean. Compare active declarations\nwith cached URLs while printing status; honor pathspec and ignore options.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n builtin/commit.c |  1 +\n wt-status.c      | 54 ++++++++++++++++++++++++++++++++++++++++++++++++\n wt-status.h      |  1 +\n 3 files changed, 56 insertions(+)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 36e47e18ed..577b097aa0 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1636,6 +1636,7 @@ struct repository *repo UNUSED)\n \n \ts.ignore_submodule_arg = ignore_submodule_arg;\n \ts.status_format = status_format;\n+\ts.check_submodule_urls = 1;\n \ts.verbose = verbose;\n \tif (no_renames != -1)\n \t\ts.detect_rename = !no_renames;\ndiff --git a/wt-status.c b/wt-status.c\nindex 238bb48643..bbd0e082dc 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -3,6 +3,8 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n+#include \"abspath.h\"\n+#include \"config.h\"\n #include \"wt-status.h\"\n #include \"object.h\"\n #include \"dir.h\"\n@@ -23,6 +25,8 @@\n #include \"remote.h\"\n #include \"refs.h\"\n #include \"submodule.h\"\n+#include \"url.h\"\n+#include \"submodule-config.h\"\n #include \"column.h\"\n #include \"read-cache.h\"\n #include \"setup.h\"\n@@ -2692,8 +2696,58 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n \t}\n }\n \n+static void wt_status_check_submodule_urls(struct wt_status *s)\n+{\n+\tint i;\n+\n+\tif (s->ignore_submodule_arg &&\n+\t    !strcmp(s->ignore_submodule_arg, \"all\"))\n+\t\treturn;\n+\n+\tif (is_gitmodules_unmerged(s->repo->index))\n+\t\treturn;\n+\n+\t/*\n+\t * Sparse-index directories containing gitlinks are not collapsed, so\n+\t * every gitlink remains visible in this cache iteration.\n+\t */\n+\tfor (i = 0; i < s->repo->index->cache_nr; i++) {\n+\t\tstruct cache_entry *ce = s->repo->index->cache[i];\n+\t\tconst struct submodule *sub;\n+\t\tconst char *config_url;\n+\t\tchar *key, *gitmodules_url;\n+\n+\t\tif (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||\n+\t\t    !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))\n+\t\t\tcontinue;\n+\n+\t\tsub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),\n+\t\t\t\t\t  ce->name);\n+\t\tif (!sub || !sub->url || !is_submodule_active(s->repo, ce->name))\n+\t\t\tcontinue;\n+\n+\t\tkey = xstrfmt(\"submodule.%s.url\", sub->name);\n+\t\tif (repo_config_get_value(s->repo, key, &config_url) || !config_url) {\n+\t\t\tfree(key);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tfree(key);\n+\n+\t\tgitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n+\t\tif (strcmp(config_url, gitmodules_url))\n+\t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n+\t\t\t\t  \"than in .gitmodules\\n\"\n+\t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n+\n+\t\tfree(gitmodules_url);\n+\t}\n+}\n+\n void wt_status_print(struct wt_status *s)\n {\n+\tif (s->check_submodule_urls)\n+\t\twt_status_check_submodule_urls(s);\n+\n \ttrace2_data_intmax(\"status\", s->repo, \"count/changed\", s->change.nr);\n \ttrace2_data_intmax(\"status\", s->repo, \"count/untracked\",\n \t\t\t   s->untracked.nr);\ndiff --git a/wt-status.h b/wt-status.h\nindex e9fe32e98c..45eeb8b558 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -123,6 +123,7 @@ struct wt_status {\n \tunsigned colopts;\n \tint null_termination;\n \tint commit_template;\n+\tint check_submodule_urls;\n \tint show_branch;\n \tint show_stash;\n \tint hints;\n-- \ngitgitgadget\n\n\n"},{"id":"559840","messageId":"d80542df121417ad82ed52e29d8efd8ce75b01d7.1796159338.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v5.git.git.1796159338.gitgitgadget@gmail.com","subject":"[PATCH v5 3/4] status: preserve customized submodule remotes","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-12-01T21:08:57Z","receivedAt":"2026-12-01T21:08:57Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nUsers may point a populated submodule remote at a fork. Since git\nsubmodule sync would overwrite custom or multi-URL remotes, suppress\nthe advice unless the configured remote matches the old or declared URL.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n wt-status.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 83 insertions(+), 1 deletion(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex bbd0e082dc..69c05735ec 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2696,6 +2696,85 @@ static void wt_porcelain_v2_print(struct wt_status *s)\n \t}\n }\n \n+static int submodule_has_custom_remote_url(struct repository *repo,\n+\t\t\t\t\t  const char *path,\n+\t\t\t\t\t  const char *declared_url,\n+\t\t\t\t\t  const char *cached_url)\n+{\n+\tstruct repository subrepo = { 0 };\n+\tconst struct string_list *remote_urls = NULL;\n+\tconst char *remote;\n+\tconst char *remote_url;\n+\tchar *key, *up_path, *config_remote_url, *gitmodules_remote_url;\n+\tchar *declared_super_url;\n+\tchar *worktree_path;\n+\tint error_code, populated, ret = 0;\n+\n+\tworktree_path = repo_worktree_path(repo, \"%s\", path);\n+\tif (!worktree_path)\n+\t\treturn 0;\n+\tpopulated = is_submodule_populated_gently(worktree_path, &error_code);\n+\tfree(worktree_path);\n+\tif (!populated)\n+\t\treturn 0;\n+\n+\tif (repo_submodule_init(&subrepo, repo, path,\n+\t\t\t\tnull_oid(repo->hash_algo)) < 0) {\n+\t\trepo_clear(&subrepo);\n+\t\treturn 0;\n+\t}\n+\n+\tdeclared_super_url = resolve_submodule_url(repo, declared_url, NULL, 1);\n+\tremote = repo_remote_from_url(&subrepo, declared_super_url);\n+\tif (!remote)\n+\t\tremote = repo_default_remote(&subrepo);\n+\tfree(declared_super_url);\n+\n+\tkey = xstrfmt(\"remote.%s.url\", remote);\n+\tif (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&\n+\t    remote_urls->nr == 1 &&\n+\t    (remote_url = remote_urls->items[0].string)) {\n+\t\tup_path = get_submodule_up_path(path);\n+\t\t/*\n+\t\t * sync_submodule() stores a relative URL in the superproject's\n+\t\t * config without the submodule path prefix, but adds that prefix\n+\t\t * when storing the URL in the submodule's remote configuration.\n+\t\t */\n+\t\tif (url_is_local_not_ssh(cached_url) &&\n+\t\t    !is_absolute_path(cached_url)) {\n+\t\t\tstruct strbuf sb = STRBUF_INIT;\n+\n+\t\t\tstrbuf_addstr(&sb, up_path);\n+\t\t\tstrbuf_addstr(&sb, cached_url);\n+\t\t\tconfig_remote_url = strbuf_detach(&sb, NULL);\n+\t\t} else {\n+\t\t\tconfig_remote_url = xstrdup(cached_url);\n+\t\t}\n+\t\tgitmodules_remote_url = resolve_submodule_url(repo, declared_url,\n+\t\t\t\t\t\t\t      up_path, 1);\n+\t\t/*\n+\t\t * The submodule's remote URL may be a local fork. If it matches\n+\t\t * neither the old cached URL nor the new .gitmodules URL, leave it\n+\t\t * alone; syncing would overwrite that customization.\n+\t\t */\n+\t\tret = strcmp(remote_url, config_remote_url) != 0 &&\n+\t\t\tstrcmp(remote_url, gitmodules_remote_url) != 0;\n+\t\tfree(gitmodules_remote_url);\n+\t\tfree(config_remote_url);\n+\t\tfree(up_path);\n+\t} else {\n+\t\t/*\n+\t\t * Multiple URLs are a local customization; sync would replace\n+\t\t * them all with a single URL.\n+\t\t */\n+\t\tret = remote_urls && remote_urls->nr > 1;\n+\t}\n+\tfree(key);\n+\trepo_clear(&subrepo);\n+\n+\treturn ret;\n+}\n+\n static void wt_status_check_submodule_urls(struct wt_status *s)\n {\n \tint i;\n@@ -2734,7 +2813,10 @@ static void wt_status_check_submodule_urls(struct wt_status *s)\n \t\tfree(key);\n \n \t\tgitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);\n-\t\tif (strcmp(config_url, gitmodules_url))\n+\t\tif (strcmp(config_url, gitmodules_url) &&\n+\t\t    !submodule_has_custom_remote_url(s->repo, ce->name,\n+\t\t\t\t\t\t     sub->url,\n+\t\t\t\t\t\t     config_url))\n \t\t\twarning(_(\"submodule '%s' has a different URL in .git/config \"\n \t\t\t\t  \"than in .gitmodules\\n\"\n \t\t\t\t  \"  run 'git submodule sync' to update it\"), ce->name);\n-- \ngitgitgadget\n\n\n"},{"id":"559841","messageId":"ec282a2a6c40eb728c861c7f5b3eaf17ef56a64f.1796159338.git.gitgitgadget@gmail.com","threadId":"66944","inReplyTo":"pull.2509.v5.git.git.1796159338.gitgitgadget@gmail.com","subject":"[PATCH v5 4/4] status: test submodule URL warnings","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-12-01T21:08:58Z","receivedAt":"2026-12-01T21:08:58Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nExercise the warning and sync advice across output formats, relative URLs,\npathspecs, ignored submodules, populated remotes, and commit status.\nDocument when the warning appears and how to clear the mismatch.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n Documentation/git-status.adoc |  12 ++++\n t/t7508-status.sh             | 121 ++++++++++++++++++++++++++++++++++\n 2 files changed, 133 insertions(+)\n\ndiff --git a/Documentation/git-status.adoc b/Documentation/git-status.adoc\nindex 9acca52bfb..6e997fbef0 100644\n--- a/Documentation/git-status.adoc\n+++ b/Documentation/git-status.adoc\n@@ -22,6 +22,18 @@ are what you _would_ commit by running `git commit`; the second and\n third are what you _could_ commit by running `git add` before running\n `git commit`.\n \n+When a submodule's URL in `.gitmodules` differs from the URL cached in\n+`.git/config`, `git status` warns that `git submodule sync` can update the\n+cached URL. For a populated submodule, the warning is suppressed when its\n+default remote URL differs from both URLs, since syncing would overwrite a\n+customized remote. Relative URLs are resolved as `git submodule sync`\n+resolves them.\n+\n+The warning is written to standard error in long, short, and porcelain\n+formats, and is limited to submodules matched by the pathspec. It is\n+suppressed when `--ignore-submodules` or `--ignore-submodules=all` is\n+specified.\n+\n OPTIONS\n -------\n \ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..ff03c6a96e 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -921,6 +921,127 @@ test_expect_success 'setup status submodule summary' '\n \tgit add sm\n '\n \n+test_expect_success 'status reports submodule URL mismatch' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_create_repo url-test/source &&\n+\ttest_commit -C url-test/source initial &&\n+\ttest_create_repo url-test/super &&\n+\tgit -C url-test/super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/source\" module &&\n+\tgit -C url-test/super commit -m \"add submodule\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t\"$PWD/url-test/updated-source\" &&\n+\tgit -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tcat >url-test/editor <<\\EOF &&\n+#!/bin/sh\n+echo \"status test commit\" >\"$1\"\n+EOF\n+\tchmod +x url-test/editor &&\n+\techo staged >url-test/super/staged &&\n+\tgit -C url-test/super add staged &&\n+\ttest_set_editor \"$PWD/url-test/editor\" &&\n+\tgit -C url-test/super commit >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status --short >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules=none >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules=dirty >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules=all >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super status -- module >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\ttest_grep \"git submodule sync\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super remote add origin ../source-parent &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-relative-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config remote.origin.url \\\n+\t\t\"$PWD/url-test/fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t\"$PWD/url-test/upstream-source\" &&\n+\tgit -C url-test/super submodule sync &&\n+\tgit -C url-test/super/module config remote.upstream.url \\\n+\t\t\"$PWD/url-test/upstream-source\" &&\n+\tgit -C url-test/super/module config remote.origin.url \\\n+\t\t\"$PWD/url-test/fork\" &&\n+\tgit -C url-test/super config submodule.module.url \\\n+\t\t\"$PWD/url-test/stale-source\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/super/module config --add remote.origin.url \\\n+\t\t\"$PWD/url-test/another-fork\" &&\n+\tgit -C url-test/super config -f .gitmodules submodule.module.url \\\n+\t\t../another-fork-source &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/super/module config --unset-all remote.origin.url &&\n+\tgit -C url-test/super config --add submodule.module.url \\\n+\t\t\"$PWD/url-test/another-configured-source\" &&\n+\tgit -C url-test/super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err\n+'\n+\n+test_expect_success 'status compares relative submodule URLs only once' '\n+\ttest_when_finished \"rm -rf url-test\" &&\n+\ttest_create_repo url-test/relative-source &&\n+\ttest_commit -C url-test/relative-source initial &&\n+\ttest_create_repo url-test/relative-super &&\n+\tgit -C url-test/relative-super -c protocol.file.allow=always \\\n+\t\tsubmodule add \"$PWD/url-test/relative-source\" module &&\n+\tgit -C url-test/relative-super commit -m \"add submodule\" &&\n+\tgit -C url-test/relative-super remote add origin ../a/b &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod1 &&\n+\tgit -C url-test/relative-super submodule sync &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod2 &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err &&\n+\tgit -C url-test/relative-super remote set-url origin a/b &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod1 &&\n+\tgit -C url-test/relative-super submodule sync &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_must_be_empty url-test/err &&\n+\tgit -C url-test/relative-super config -f .gitmodules \\\n+\t\tsubmodule.module.url ../mod2 &&\n+\tgit -C url-test/relative-super status >url-test/actual 2>url-test/err &&\n+\ttest_grep \"module.*different URL\" url-test/err\n+'\n+\n test_expect_success 'status submodule summary is disabled by default' '\n \tcat >expect <<EOF &&\n On branch main\n-- \ngitgitgadget\n\n"}]}