From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795884830; b=bGrdMQ9OQjFnxLwuFoU5Q7FvnTA1zEjbO2x+SvK/g1Ib9NVOEeTRUjrSXxAiffPFrPkj Y2Bc+Cia+Pnr9AFiom+aPI4rJTvfeX/2joFg+V+FhCeODZtBKQk7afelnSUYxq61x4EAH 9XgCUlbfeKagemlmRJWTO5vAc5fLS3XGa+T2sJb+iSjg4loZEiyOaJXeyBohVpuG1qA4Y vNe87DJzYnrH5s5sTN3zdL0ipwLD1fnw2vCWO3Db4W2aGeJNYyVL6nCuXqoeHgqswK6XC DPr6mrxbyntcUBbK63BMy0gb+8Yt8ZvUNoOxfl5JjVvT4OSUPgE+KkSitIZPF4PdJzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795884830; 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=w9S/dC4aiSB3lyeoSH8gnxim19b8FMFDBkP8eCEh7Vc=; b=ffjPw8Fwp3cIEnHU2ooY2mA3kTzndkHmx9C+pyex5JoF92yT58cHQ1SJ88Z2V4A1YBja iJ2pyZJcANMY2M3GJavbJxQu9foCUQ5wY7BXjUmJ67s+wYu8Xx4PTvPkHEIRTGfoxRN5+ Upj+71x8ilCzH3n+4DhVo03G7WDk0+DNeB8k0OlsycorgGVocuyGLBiaZxHOzSIAXOjUw ZQKfIcOVLn4nEv77Oil8L6/RAyjq177Zke01kXmuQxzEZKKGvUSZqhsVC8iBuSQx1sizS nZ0tAoKxcMCVPxRKqhDudClH4xMY5pupmoI+LSynH/imYAeXH4nkJZV7YC7G2O2hYEA== 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=rNKud13C; arc=none smtp.remote-ip=209.85.128.182 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (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 6064A606A31C for ; Sat, 28 Nov 2026 16:53:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6064A606A31C 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=rNKud13C Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-8b4c685c751so79496667b3.1 for ; Sat, 28 Nov 2026 08:53:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795884829; x=1796489629; 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=w9S/dC4aiSB3lyeoSH8gnxim19b8FMFDBkP8eCEh7Vc=; b=rNKud13CSNWSJjIYjtkanOPW82eHT2XnsHBtMISCnQnTzUP3u40opfuyTON5g/A6R4 CLgcnBqhYO9RiVETQg1/P5yFEFH4VkyLLYL4uBM3ZuRRx2Pnyh1/ap+fInzYYz8cwPlg KvSuQMw+Qt3bXwvwVvj1oyyAjuEurtc3JmtzjhCfvcap1lcKDKkeHeB8rTzUieE+KeLb rIT8y8vtgi4iJcqQjS9Ri5+j8+Q50EeO/jZ6QjY5Tynyg0evkN9WRtuEAgzbgp1BlQlS Hc4kuGmNEyNFwdqzzPetFHnmJSfVoGgMeNVYwKKZxZL59BCoFrm3euRV8lFClYIYsp0l 7k4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795884829; x=1796489629; 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=w9S/dC4aiSB3lyeoSH8gnxim19b8FMFDBkP8eCEh7Vc=; b=P8pvZS8RqSGWoMKYl2lMS2bznbbjQJmZeQeOe0ECxVbwackGk+TDVkR5iCSwbqHiFo Knrc5abZyOgMLC6JdwR/+GQZk74BEXAJMQPNvxVTh2WLQ/KCf/Z0dKeq1TrZ442CA4/A MlLzZR/0fy+1czZUc3VFKT0XCr4pvHU2/OvKJERFevCsjupHtzc5MzgaT5qYvUOBSt38 paDilszr8bNBIbfLcHMD5lOLrwRj3FUM36d2U6MjDI4AeIhAzXoFocaviMA2egHfVI+D Pb4qStM52KJ1rGI7A8dVAcyW+cyS53PlRBe04PWO5Ea1j2WtkDT4vImuj/k/vND9mqd2 WWVw== X-Gm-Message-State: APuU4Z+A4hSUeKm/G0ZohRJM1aB7Xfn6If4piZ/jqJ40CiPXbyey5Och Ijbib3MoUYeWFEZOim+dZXvhV1jabBDXmIwtiJJXdXFoAsq1Ulrlp+jfyVIjf0Q1 X-Gm-Gg: AZFdTZeCy1BonwuH18gWHAA138VSHGEd9EaFhp70dGCA7ff0c+LfyDad24LnQ0aOKta x0Z0+rjJaZ3EMeOQ6XfqvlMAacyHhI74zr7xv6Qk+A13ToGNROZWmozAu6eGVMd1av0ZRTCqCp4 U5JSPDix2vvtV9Y7yHryzPQUOsj3kQA8LY+qcKdO7DmVMOrDo5C680diIcvf80xxp4heBILvmUm z/zYopg2ZUgNObmgk3+uZ8H7OT0DbQzVd4xZhEBsY7Rc2oBU1je3M1AcIbYnHNr43cRh8ZRb/Bk sWEUh1ns7eCiaIYeIqmFc/sLCbjTa8V6Rex58owfF07YA6LDzgWoxxPGeOOIT5pauFtgSo+9a5T xWDnL+YJwNFLs5olFlHKzhDSJWsEpUcJGs/6DOrUL4cyixcMuVN7KffFe6Hmoj+xkf7xvWuXObm Hi4O86/SZ32oW9XfDGS1DZH4kpToSUc0P8tZLO+zIlA88N1astTJfx8nhMLe6Ua9KqHcwvT4H1t IbYiGXYH7arLDyKD9NsQTg/DlnwnSekJAIE8wUdiYAOdXWeDkP2jL9F5g6/Wbz1frmri1UYifpL Rb1+mfVXy2ZxU1mPX2y+zuaJYCFhNi1Bug== X-Received: by 2002:a05:690c:6986:b0:8b4:c469:bfcc with SMTP id 00721157ae682-8b5204ba6aamr102447947b3.65.1795884829232; Sat, 28 Nov 2026 08:53:49 -0800 (PST) Received: from [127.0.0.1] ([134.138.59.129]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b52034f7absm107693107b3.41.2026.11.28.08.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 08:53:48 -0800 (PST) Message-Id: <619101d5e124115a43faf51c84655b7b99a431dd.1795884822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Alessio Attilio via GitGitGadget" Date: Sat, 28 Nov 2026 16:53:42 +0000 Subject: [PATCH v4 3/3] 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: Alessio Attilio , Alessio Attilio From: Alessio Attilio When the URL in .gitmodules differs from the cached URL in the superproject config, git status can help users discover that submodule operations may use a stale location. Resolve relative URLs the same way as git submodule sync does. For populated submodules, compare the default remote URL as well. If it matches neither the cached URL nor the newly declared URL, treat it as a local customization and do not suggest a sync that would overwrite it. Multiple remote URLs are also treated as a customization. Emit the warning on standard error for long, short, and porcelain formats. Respect pathspecs and suppress the check only when --ignore-submodules=all (or its bare form) is given. Run the check only for git status, not other users of the wt-status machinery. Signed-off-by: Alessio Attilio --- Documentation/git-status.adoc | 12 ++++ builtin/commit.c | 1 + t/t7508-status.sh | 100 ++++++++++++++++++++++++++++ wt-status.c | 120 ++++++++++++++++++++++++++++++++++ wt-status.h | 1 + 5 files changed, 234 insertions(+) diff --git a/Documentation/git-status.adoc b/Documentation/git-status.adoc index 9acca52bfb..6e997fbef0 100644 --- a/Documentation/git-status.adoc +++ b/Documentation/git-status.adoc @@ -22,6 +22,18 @@ are what you _would_ commit by running `git commit`; the second and third are what you _could_ commit by running `git add` before running `git commit`. +When a submodule's URL in `.gitmodules` differs from the URL cached in +`.git/config`, `git status` warns that `git submodule sync` can update the +cached URL. For a populated submodule, the warning is suppressed when its +default remote URL differs from both URLs, since syncing would overwrite a +customized remote. Relative URLs are resolved as `git submodule sync` +resolves them. + +The warning is written to standard error in long, short, and porcelain +formats, and is limited to submodules matched by the pathspec. It is +suppressed when `--ignore-submodules` or `--ignore-submodules=all` is +specified. + OPTIONS ------- diff --git a/builtin/commit.c b/builtin/commit.c index 36e47e18ed..577b097aa0 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1636,6 +1636,7 @@ struct repository *repo UNUSED) s.ignore_submodule_arg = ignore_submodule_arg; s.status_format = status_format; + s.check_submodule_urls = 1; s.verbose = verbose; if (no_renames != -1) s.detect_rename = !no_renames; diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e10c961268..ce85920380 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -921,6 +921,106 @@ test_expect_success 'setup status submodule summary' ' git add sm ' +test_expect_success 'status reports submodule URL mismatch' ' + test_when_finished "rm -rf url-test" && + test_create_repo url-test/source && + test_commit -C url-test/source initial && + test_create_repo url-test/super && + git -C url-test/super -c protocol.file.allow=always \ + submodule add "$PWD/url-test/source" module && + git -C url-test/super commit -m "add submodule" && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super config -f .gitmodules submodule.module.url \ + "$PWD/url-test/updated-source" && + git -C url-test/super status --porcelain >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + cat >url-test/editor <<\EOF && +#!/bin/sh +echo "status test commit" >"$1" +EOF + chmod +x url-test/editor && + echo staged >url-test/super/staged && + git -C url-test/super add staged && + test_set_editor "$PWD/url-test/editor" && + git -C url-test/super commit >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super status --short >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + git -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + git -C url-test/super status --ignore-submodules=none >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + git -C url-test/super status --ignore-submodules=dirty >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + git -C url-test/super status --ignore-submodules=all >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super status -- module >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + test_grep "git submodule sync" url-test/err && + git -C url-test/super submodule sync && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super remote add origin ../source-parent && + git -C url-test/super config -f .gitmodules submodule.module.url \ + ../relative-source && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + git -C url-test/super submodule sync && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super config -f .gitmodules submodule.module.url \ + ../another-relative-source && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err && + git -C url-test/super submodule sync && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super/module config remote.origin.url \ + "$PWD/url-test/fork" && + git -C url-test/super config -f .gitmodules submodule.module.url \ + ../fork-source && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super/module config --add remote.origin.url \ + "$PWD/url-test/another-fork" && + git -C url-test/super config -f .gitmodules submodule.module.url \ + ../another-fork-source && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/super/module config --unset-all remote.origin.url && + git -C url-test/super config --add submodule.module.url \ + "$PWD/url-test/another-configured-source" && + git -C url-test/super status >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err +' + +test_expect_success 'status compares relative submodule URLs only once' ' + test_when_finished "rm -rf url-test" && + test_create_repo url-test/relative-source && + test_commit -C url-test/relative-source initial && + test_create_repo url-test/relative-super && + git -C url-test/relative-super -c protocol.file.allow=always \ + submodule add "$PWD/url-test/relative-source" module && + git -C url-test/relative-super commit -m "add submodule" && + git -C url-test/relative-super remote add origin ../a/b && + git -C url-test/relative-super config -f .gitmodules \ + submodule.module.url ../mod1 && + git -C url-test/relative-super submodule sync && + git -C url-test/relative-super status >url-test/actual 2>url-test/err && + test_must_be_empty url-test/err && + git -C url-test/relative-super config -f .gitmodules \ + submodule.module.url ../mod2 && + git -C url-test/relative-super status >url-test/actual 2>url-test/err && + test_grep "module.*different URL" url-test/err +' + test_expect_success 'status submodule summary is disabled by default' ' cat >expect <hash_algo)) < 0) { + repo_clear(&subrepo); + return 0; + } + + remote = repo_default_remote(&subrepo); + + key = xstrfmt("remote.%s.url", remote); + if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) && + remote_urls->nr == 1 && + (remote_url = remote_urls->items[0].string)) { + up_path = get_submodule_up_path(path); + /* + * sync_submodule() stores a relative URL in the superproject's + * config without the submodule path prefix, but adds that prefix + * when storing the URL in the submodule's remote configuration. + */ + if (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) { + struct strbuf sb = STRBUF_INIT; + + strbuf_addstr(&sb, up_path); + strbuf_addstr(&sb, config_url); + config_remote_url = strbuf_detach(&sb, NULL); + } else { + config_remote_url = xstrdup(config_url); + } + gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url, + up_path, 1); + /* + * The submodule's remote URL may be a local fork. If it matches + * neither the old cached URL nor the new .gitmodules URL, leave it + * alone; syncing would overwrite that customization. + */ + ret = strcmp(remote_url, config_remote_url) != 0 && + strcmp(remote_url, gitmodules_remote_url) != 0; + free(gitmodules_remote_url); + free(config_remote_url); + free(up_path); + } else { + /* + * Multiple URLs are a local customization; sync would replace + * them all with a single URL. + */ + ret = remote_urls && remote_urls->nr > 1; + } + free(key); + repo_clear(&subrepo); + + return ret; +} + +static void wt_status_check_submodule_urls(struct wt_status *s) +{ + int i; + + if (s->ignore_submodule_arg && + !strcmp(s->ignore_submodule_arg, "all")) + return; + + if (is_gitmodules_unmerged(s->repo->index)) + return; + + for (i = 0; i < s->repo->index->cache_nr; i++) { + struct cache_entry *ce = s->repo->index->cache[i]; + const struct submodule *sub; + const char *config_url; + char *key, *gitmodules_url; + + if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) || + !ce_path_match(s->repo->index, ce, &s->pathspec, NULL)) + continue; + + sub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo), + ce->name); + if (!sub || !sub->url || !is_submodule_active(s->repo, ce->name)) + continue; + + key = xstrfmt("submodule.%s.url", sub->name); + if (repo_config_get_value(s->repo, key, &config_url) || !config_url) { + free(key); + continue; + } + free(key); + + gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1); + if (strcmp(config_url, gitmodules_url) && + !submodule_has_custom_remote_url(s->repo, ce->name, + sub->url, + config_url)) + warning(_("submodule '%s' has a different URL in .git/config " + "than in .gitmodules\n" + " run 'git submodule sync' to update it"), ce->name); + + free(gitmodules_url); + } +} + void wt_status_print(struct wt_status *s) { + if (s->check_submodule_urls) + wt_status_check_submodule_urls(s); + trace2_data_intmax("status", s->repo, "count/changed", s->change.nr); trace2_data_intmax("status", s->repo, "count/untracked", s->untracked.nr); diff --git a/wt-status.h b/wt-status.h index e9fe32e98c..45eeb8b558 100644 --- a/wt-status.h +++ b/wt-status.h @@ -123,6 +123,7 @@ struct wt_status { unsigned colopts; int null_termination; int commit_template; + int check_submodule_urls; int show_branch; int show_stash; int hints; -- gitgitgadget