From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796159341; b=F4OzEDH5bKyVLPnz8Hiyn1ORZtukEKqE3TH4IcOwDVtlV9ixDnRUtVj/ekcekR8Vn+ft 2+S2ahbfX3jogNRs9kY5Y5qy6ZY9G3OC898x1x2J37RRw0MvewFLlx65Uep4PdtOJEPhf AaxYMO9m9EVcDZXCndbebSUxoLeXBLJHBa4Nb5Wwg4qdSIuyQ5UFCMLPi04cwq7pKDVH1 pVLyNhSvaDW2Ur8vyUoph5V/0eR8gzy6YAFL8fe1tomkzXto+drKjNAAEs7CqrzevOwBu wAN/5SQtyS2Lmv+znQHB1miJ6oBgDiUu+eIclGHPdgMzTk1oE10JYjUXNNWXQZn76xg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796159341; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=4TuN74trRhVvpoJ5VBP7hFYR08FQNBfndU3kF9+j9bA=; b=SxtZ00X2OSj1qk2BPUZ8rBOwqAdNUVagON4dIClOCJey313iqFp37DU/GlgWX4K4pv+K 8Ca1zw6EmPGb/nVwufWNuhE0WiMTO1wPkPpC7nsXHF2EAOZCusNzMZOe78ldV+syBKqRH 8qn6nM3S209zX6Xo6zD6+8ovMOTgwxOrWe5nIrgI8emlfb8du6jil9PCnsufJtBO+6XYd OQssrA8Jad1cMnmu7y/L1kUaYSUxXVrSN/LYuoFPh1yvOQ1KFInpzqoymgWcZAT5/ciEw HV2nEiEZV73/YlF+dCOhj+REBGjnN/S/9FaMWyzMyeNd3nBP0Qy7mroDbxEtqv1vFTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Sv1zENBZ; arc=none smtp.remote-ip=209.85.214.177 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 135EB606A31A for ; Tue, 1 Dec 2026 21:09:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 135EB606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Sv1zENBZ Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2f052ae3c86so67382065ad.1 for ; Tue, 01 Dec 2026 13:09:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796159340; x=1796764140; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=4TuN74trRhVvpoJ5VBP7hFYR08FQNBfndU3kF9+j9bA=; b=Sv1zENBZf4g7wzC08Dq6p6pyVgxWT6MvtlVrWgvjv1E1LAoYiZD3+F3t+CWK9lV/S+ 98XLQORCqAr5Z5qcHIHOvOeO669c7bKSFGYEDfBub5v5vR7bGsVpCxkKKsU9mLGJbBeN QMtqrA+uGFV3T5eWS38SS6HTsfj0SM+H67uwWrPUqEIXXw1101sKftiEqkFnAM86NY25 T1oQNEFVVK3b3BIpSWEo76UH+86B9/1gd4bMIPuyK7NESRbuRnNDLzbyp09DXVc1pfv3 HWP3yuPkJVw+R+jg2YdG4hInZhjxwQVl42yMj51KwzS5BFetmPwYbHYaAa/fQGlA3AK5 ufWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796159340; x=1796764140; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4TuN74trRhVvpoJ5VBP7hFYR08FQNBfndU3kF9+j9bA=; b=y7brtDfPdYrDODzC0a5KpPRtF3Esjx61J5YdTLSvPUKLTdfeJHd5St96tsQYgIXHg1 8izYwWlSa/efNHnWmrSHxCUJF6LQyUGVbPh+syVtjWeSNmJJxasW4ZbO7x79aWHG1hz8 8JAhJX7EYsiqpvMABQWUXD/3vqKNv5/PVjYCtbsvN3ZLkqNdzCwkzm0hsJh5HXkqup61 PwK+ZviPasouC4D60w6kdYtrl83C6r8LIJ7JdjtS3a6u4sU3uK+wgj2fvBQOjyR3i3e8 DxfBdocazalSkzDChyBb+l8FTztRoVh5QKhx8iqXjLgHWtAuPU1jgIO9/bfDn8NtvPa6 WZFA== X-Gm-Message-State: APuU4Z/fxu1qUAYdO5BU/ZL2JWCFrBMB232o1D+zDUyt8CYzv/FaKpF4 LPmfka6iZsSc0tW7oK/pOfSq+mzcty7gYv2yzjwVd+0B3hvFsAxSXBiu6pwEbw== X-Gm-Gg: AZFdTZfgjvoHWmVCw5N4fQe5RVKHwFkx+iwFHh9/yFaU3EqQCJNQlbSjxfUDFvMakPD KUekGuDKwJkBSxKoCkDVA1wVySiu59alLmzBhi+94DmAXnIUJAKNDzuL/DVACWdGXIM0DQF2yZC 8oVVOyRFGxfAkUtE2Z7H+/dAj5mv8hTCkXeb+vv0STGGanIB3gcAhecbNIE3qmNz+JbQn4meZaT br/BxrXcBQ3B25NDMcuscmilfwmym0DeUyDSPiLabzd78gBeJ8iACRhQaLzA/9dEK4qprF2gxD1 Vvx+jZoOZJ9Pl2siHCGcb8bw2sMZhtDDV9treynsaXoDhksxyVTqeTzt7b0VocCqqjQ68HWYpnK GLhdOAJ9TdR8tWXtDorbOvPooYwfrdhZoWVv0tKPnH6m7/rPoAo9ON4mMhIK0flTvGKalGIZYM9 dXilFADW9+ymecuujLxnwZYFuLIWuzG8RHCzGsTWBeZsjnXFNfRGYLNSOcLzakD/VwHHZKtaeH2 dyMauUccyNjkCzBSjfzQi64y8oCFvqgYV4kPJ+BNx83qHEhUetiNr3d0ubUW8YIoAUPJXc46lV4 MkQAza/POy45U9GqKzC5L3+/8J8OF5R0pbvngGYkTNo4M3PX2zbQ6gANgaZpmKo63NN7CTaQRGi aNwr71w== X-Received: by 2002:a17:903:3b8f:b0:2ef:d79b:680f with SMTP id d9443c01a7336-2f1742aff5bmr6471675ad.15.1796159340141; Tue, 01 Dec 2026 13:09:00 -0800 (PST) Received: from [127.0.0.1] (ec2-3-42-157-20.us-west-2.compute.amazonaws.com. [3.42.157.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f191464sm194300195ad.1.2026.12.01.13.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 13:08:59 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alessio Attilio via GitGitGadget" Date: Tue, 01 Dec 2026 21:08:54 +0000 Subject: [PATCH v5 0/4] status: report when submodule URLs are out of sync Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: "D. Ben Knoble" , Alessio Attilio When a submodule URL changes in .gitmodules, the URL cached in the superproject's .git/config can remain stale. This change makes git status report the mismatch and suggest git submodule sync. Relative URLs are resolved as git submodule sync resolves them. For populated submodules, the check follows the remote that git submodule sync would update. Local remote customizations are respected so the advice does not suggest overwriting them. The warning is written to standard error for long, short, and porcelain formats, follows pathspecs, and is suppressed by --ignore-submodules=all. Closes gitgitgadget/git#565 Alessio Attilio (4): submodule: share repository-aware URL resolution status: warn about submodule URL mismatches status: preserve customized submodule remotes status: test submodule URL warnings Documentation/git-status.adoc | 12 +++ builtin/commit.c | 1 + builtin/submodule--helper.c | 60 ++------------- submodule.c | 45 +++++++++++ submodule.h | 12 +++ t/t7508-status.sh | 121 ++++++++++++++++++++++++++++++ wt-status.c | 136 ++++++++++++++++++++++++++++++++++ wt-status.h | 1 + 8 files changed, 335 insertions(+), 53 deletions(-) base-commit: 566b6997dd4710b625c0882cf10a7443bf52d183 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v5 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v5 Pull-Request: https://github.com/git/git/pull/2509 Range-diff vs v4: 1: b09e8501ed ! 1: 35d9d09ebe submodule: move URL helpers into submodule.c @@ Metadata Author: Alessio Attilio ## Commit message ## - submodule: move URL helpers into submodule.c + submodule: share repository-aware URL resolution - Move the relative submodule URL resolver and the helper that - computes the path back to the superproject from - builtin/submodule--helper.c to submodule.c. This lets other - callers reuse the helpers. - - Return non-relative URLs unchanged before consulting remote - configuration, so the resolver handles every URL form itself. - Keep the repository parameter change for the next patch. + Status must resolve relative submodule URLs against the same remote as + git submodule sync. Move the resolver into common submodule code and + pass the repository explicitly, preserving existing helper behavior. Signed-off-by: Alessio Attilio @@ builtin/submodule--helper.c: static int get_default_remote_submodule(const char char *oldurl = url; - url = resolve_relative_url(oldurl, NULL, 1); -+ url = resolve_submodule_url(oldurl, NULL, 1); ++ url = resolve_submodule_url(the_repository, oldurl, NULL, 1); free(oldurl); } } @@ builtin/submodule--helper.c: static void init_submodule(const char *path, const char *oldurl = url; - url = resolve_relative_url(oldurl, NULL, 0); -+ url = resolve_submodule_url(oldurl, NULL, 0); ++ url = resolve_submodule_url(the_repository, oldurl, NULL, 0); free(oldurl); } @@ builtin/submodule--helper.c: static void sync_submodule(const char *path, const - sub_origin_url = resolve_relative_url(sub->url, up_path, 1); - super_config_url = resolve_relative_url(sub->url, NULL, 1); -+ sub_origin_url = resolve_submodule_url(sub->url, up_path, 1); -+ super_config_url = resolve_submodule_url(sub->url, NULL, 1); ++ sub_origin_url = resolve_submodule_url(the_repository, sub->url, up_path, 1); ++ super_config_url = resolve_submodule_url(the_repository, sub->url, NULL, 1); free(up_path); } else { sub_origin_url = xstrdup(sub->url); @@ builtin/submodule--helper.c: static int prepare_to_clone_next_submodule(const st if (sub->url && (starts_with_dot_slash(sub->url) || starts_with_dot_dot_slash(sub->url))) { - url = resolve_relative_url(sub->url, NULL, 0); -+ url = resolve_submodule_url(sub->url, NULL, 0); ++ url = resolve_submodule_url(the_repository, sub->url, NULL, 0); need_free_url = 1; } else url = sub->url; @@ builtin/submodule--helper.c: static int module_add(int argc, const char **argv, /* dereference source url relative to parent's url */ - to_free = resolve_relative_url(add_data.repo, NULL, 1); -+ to_free = resolve_submodule_url(add_data.repo, NULL, 1); ++ to_free = resolve_submodule_url(the_repository, add_data.repo, NULL, 1); add_data.realrepo = to_free; } else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) { add_data.realrepo = add_data.repo; @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path) return is_tree_submodule_active(repo, null_oid(the_hash_algo), path); } -+static char *get_default_remote(void) -+{ -+ return xstrdup(repo_default_remote(the_repository)); -+} -+ -+char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet) ++char *resolve_submodule_url(struct repository *repo, const char *url, ++ const char *up_path, int quiet) +{ + char *remoteurl, *resolved_url; -+ char *remote; ++ const char *remote; + struct strbuf remotesb = STRBUF_INIT; + -+ if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url)) -+ return xstrdup(rel_url); ++ if (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url)) ++ return xstrdup(url); + -+ remote = get_default_remote(); ++ remote = repo_default_remote(repo); + strbuf_addf(&remotesb, "remote.%s.url", remote); -+ if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) { ++ if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) { + if (!quiet) + warning(_("could not look up configuration '%s'. " + "Assuming this repository is its own " + "authoritative upstream."), + remotesb.buf); -+ remoteurl = xgetcwd(); ++ remoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd(); + } -+ resolved_url = relative_url(remoteurl, rel_url, up_path); ++ resolved_url = relative_url(remoteurl, url, up_path); + -+ free(remote); + free(remoteurl); + strbuf_release(&remotesb); + @@ submodule.h: int is_tree_submodule_active(struct repository *repo, const struct object_id *treeish_name, const char *path); int is_submodule_active(struct repository *repo, const char *path); -+char *resolve_submodule_url(const char *url, const char *up_path, int quiet); ++/* ++ * Resolve a relative submodule URL against the superproject's default remote. ++ * 'url' must be non-NULL; 'up_path' may be NULL. The caller must free the ++ * returned string. ++ */ ++char *resolve_submodule_url(struct repository *repo, const char *url, ++ const char *up_path, int quiet); ++/* ++ * Return the path prefix from a submodule back to its superproject. 'path' ++ * must be non-NULL and non-empty. The caller must free the returned string. ++ */ +char *get_submodule_up_path(const char *path); /* * Determine if a submodule has been populated at a given 'path' by checking if 2: ad4dafd82b < -: ---------- submodule: make URL resolution repository-aware -: ---------- > 2: 6db7dc9415 status: warn about submodule URL mismatches -: ---------- > 3: d80542df12 status: preserve customized submodule remotes 3: 619101d5e1 ! 4: ec282a2a6c status: report when submodule URLs are out of sync @@ Metadata Author: Alessio Attilio ## Commit message ## - status: report when submodule URLs are out of sync + status: test submodule URL warnings - When the URL in .gitmodules differs from the cached URL in the - superproject config, git status can help users discover that - submodule operations may use a stale location. Resolve relative - URLs the same way as git submodule sync does. - - For populated submodules, compare the default remote URL as well. - If it matches neither the cached URL nor the newly declared URL, - treat it as a local customization and do not suggest a sync that - would overwrite it. Multiple remote URLs are also treated as a - customization. - - Emit the warning on standard error for long, short, and porcelain - formats. Respect pathspecs and suppress the check only when - --ignore-submodules=all (or its bare form) is given. Run the check - only for git status, not other users of the wt-status machinery. + Exercise the warning and sync advice across output formats, relative URLs, + pathspecs, ignored submodules, populated remotes, and commit status. + Document when the warning appears and how to clear the mismatch. Signed-off-by: Alessio Attilio @@ Documentation/git-status.adoc: are what you _would_ commit by running `git commi ------- - ## builtin/commit.c ## -@@ builtin/commit.c: struct repository *repo UNUSED) - - s.ignore_submodule_arg = ignore_submodule_arg; - s.status_format = status_format; -+ s.check_submodule_urls = 1; - s.verbose = verbose; - if (no_renames != -1) - s.detect_rename = !no_renames; - ## t/t7508-status.sh ## @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' ' git add sm @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' ' + ../fork-source && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && ++ git -C url-test/super config -f .gitmodules submodule.module.url \ ++ "$PWD/url-test/upstream-source" && ++ git -C url-test/super submodule sync && ++ git -C url-test/super/module config remote.upstream.url \ ++ "$PWD/url-test/upstream-source" && ++ git -C url-test/super/module config remote.origin.url \ ++ "$PWD/url-test/fork" && ++ git -C url-test/super config submodule.module.url \ ++ "$PWD/url-test/stale-source" && ++ git -C url-test/super status >url-test/actual 2>url-test/err && ++ test_grep "module.*different URL" url-test/err && + git -C url-test/super/module config --add remote.origin.url \ + "$PWD/url-test/another-fork" && + git -C url-test/super config -f .gitmodules submodule.module.url \ @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' ' + git -C url-test/relative-super config -f .gitmodules \ + submodule.module.url ../mod2 && + git -C url-test/relative-super status >url-test/actual 2>url-test/err && ++ test_grep "module.*different URL" url-test/err && ++ git -C url-test/relative-super remote set-url origin a/b && ++ git -C url-test/relative-super config -f .gitmodules \ ++ submodule.module.url ../mod1 && ++ git -C url-test/relative-super submodule sync && ++ git -C url-test/relative-super status >url-test/actual 2>url-test/err && ++ test_must_be_empty url-test/err && ++ git -C url-test/relative-super config -f .gitmodules \ ++ submodule.module.url ../mod2 && ++ git -C url-test/relative-super status >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err +' + test_expect_success 'status submodule summary is disabled by default' ' cat >expect <hash_algo)) < 0) { -+ repo_clear(&subrepo); -+ return 0; -+ } -+ -+ remote = repo_default_remote(&subrepo); -+ -+ key = xstrfmt("remote.%s.url", remote); -+ if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) && -+ remote_urls->nr == 1 && -+ (remote_url = remote_urls->items[0].string)) { -+ up_path = get_submodule_up_path(path); -+ /* -+ * sync_submodule() stores a relative URL in the superproject's -+ * config without the submodule path prefix, but adds that prefix -+ * when storing the URL in the submodule's remote configuration. -+ */ -+ if (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) { -+ struct strbuf sb = STRBUF_INIT; -+ -+ strbuf_addstr(&sb, up_path); -+ strbuf_addstr(&sb, config_url); -+ config_remote_url = strbuf_detach(&sb, NULL); -+ } else { -+ config_remote_url = xstrdup(config_url); -+ } -+ gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url, -+ up_path, 1); -+ /* -+ * The submodule's remote URL may be a local fork. If it matches -+ * neither the old cached URL nor the new .gitmodules URL, leave it -+ * alone; syncing would overwrite that customization. -+ */ -+ ret = strcmp(remote_url, config_remote_url) != 0 && -+ strcmp(remote_url, gitmodules_remote_url) != 0; -+ free(gitmodules_remote_url); -+ free(config_remote_url); -+ free(up_path); -+ } else { -+ /* -+ * Multiple URLs are a local customization; sync would replace -+ * them all with a single URL. -+ */ -+ ret = remote_urls && remote_urls->nr > 1; -+ } -+ free(key); -+ repo_clear(&subrepo); -+ -+ return ret; -+} -+ -+static void wt_status_check_submodule_urls(struct wt_status *s) -+{ -+ int i; -+ -+ if (s->ignore_submodule_arg && -+ !strcmp(s->ignore_submodule_arg, "all")) -+ return; -+ -+ if (is_gitmodules_unmerged(s->repo->index)) -+ return; -+ -+ for (i = 0; i < s->repo->index->cache_nr; i++) { -+ struct cache_entry *ce = s->repo->index->cache[i]; -+ const struct submodule *sub; -+ const char *config_url; -+ char *key, *gitmodules_url; -+ -+ if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) || -+ !ce_path_match(s->repo->index, ce, &s->pathspec, NULL)) -+ continue; -+ -+ sub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo), -+ ce->name); -+ if (!sub || !sub->url || !is_submodule_active(s->repo, ce->name)) -+ continue; -+ -+ key = xstrfmt("submodule.%s.url", sub->name); -+ if (repo_config_get_value(s->repo, key, &config_url) || !config_url) { -+ free(key); -+ continue; -+ } -+ free(key); -+ -+ gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1); -+ if (strcmp(config_url, gitmodules_url) && -+ !submodule_has_custom_remote_url(s->repo, ce->name, -+ sub->url, -+ config_url)) -+ warning(_("submodule '%s' has a different URL in .git/config " -+ "than in .gitmodules\n" -+ " run 'git submodule sync' to update it"), ce->name); -+ -+ free(gitmodules_url); -+ } -+} -+ - void wt_status_print(struct wt_status *s) - { -+ if (s->check_submodule_urls) -+ wt_status_check_submodule_urls(s); -+ - trace2_data_intmax("status", s->repo, "count/changed", s->change.nr); - trace2_data_intmax("status", s->repo, "count/untracked", - s->untracked.nr); - - ## wt-status.h ## -@@ wt-status.h: struct wt_status { - unsigned colopts; - int null_termination; - int commit_template; -+ int check_submodule_urls; - int show_branch; - int show_stash; - int hints; -- gitgitgadget