Article View: linux.kernel.git
Article #1693[PATCH v2 0/3] submodule: foreach in reverse order, with the superproject
From: William Hatfield
Date: Wed, 28 Oct 2026 00:15
Date: Wed, 28 Oct 2026 00:15
95 lines
15274 bytes
15274 bytes
Some commands need to visit nested submodules before the repositories
that contain them. For example, when committing changes throughout a
project, a superproject can record a submodule's new commit only after
that commit exists. "git submodule foreach --recursive" visits each
submodule before descending into it, so it cannot do that in one pass.
This adds three options to "git submodule foreach":
- --reverse-traversal visits submodules in the reverse of their usual
order. With --recursive, each submodule is visited after the
submodules nested in it.
- --include-superproject also runs the command in the superproject,
after all the submodules.
- --reversive is a shorthand for --recursive --reverse-traversal
--include-superproject.
Take a project "top" with a submodule "mods/a" that has a nested
submodule "inner", and uncommitted changes in all three. After
git submodule foreach --reversive 'git commit -a -m update || :'
"git status" shows nothing modified in any of them. With --recursive
instead of --reversive, "inner" is committed after "mods/a", which
still records its old "inner" and shows it as modified. t7427 checks
both outcomes. (The "|| :" is there because "git commit" fails where
there is nothing to commit. What a failure means is left to the
command, as it is for "git submodule foreach" today: a non-zero exit
status stops the traversal, and the superproject is only visited if
every submodule succeeded.)
This is a new version of "[PATCH 0/5] submodule: add 'reversive'
traversal options to foreach" [1], reworked after the review by Junio
and Jean-Noel:
- Tests are part of the commits that add the behavior they test,
instead of a separate first commit with test_expect_failure.
- --append-superproject is now --include-superproject, which says
what it does: the command is run in the superproject too, last. Of
the variables a command can use in a submodule, Git sets only
$displaypath there, to the name of the superproject's directory.
The others are not cleared and may come from the environment.
- The command run in the superproject keeps the environment that
selects the repository, such as GIT_DIR and GIT_INDEX_FILE, because
it is the repository "git submodule foreach" itself runs in, not
another one being entered. The tests cover a detached worktree and
an alternate index, also from a subdirectory.
- --reverse-traversal keeps its name, but the manual now says what the
order it reverses is: the submodules by path, each one immediately
followed by the submodules nested in it. That was the missing piece
in the objection that there is no "natural" order. I do not think
of it as a walk of a tree, for which "bottom-up" or "post-order"
would be better names: those say nothing without --recursive, and
reversing also reverses the order of siblings, which "bottom-up"
does not promise. Please tell me if it still reads as unclear.
- With --recursive and --reverse-traversal, the submodules nested in
a submodule are looked for before the command runs in it, so a
command that checks out nested submodules itself does not get them
visited, unlike in the usual order. This is documented and tested.
- The documentation follows the synopsis style that git-submodule.adoc
has been converted to, describes each option by what it does first,
and has an example of the resulting order. The usage message, the
synopsis and the completion are updated too.
Because the series is organised differently from v1 (three patches
instead of five, with the tests moved), a range-diff against v1 would
only show it as replaced, so there is none.
[1] https://lore.kernel.org/git/20260131214309.1899376-1-whatfield.git@gmail.com/
William Hatfield (3):
submodule: add --reverse-traversal to foreach
submodule: add --include-superproject to foreach
submodule: add --reversive shorthand to foreach
Documentation/git-submodule.adoc | 41 ++-
builtin/submodule--helper.c | 103 ++++--
contrib/completion/git-completion.bash | 5 +-
git-submodule.sh | 17 +-
t/meson.build | 1 +
t/t7427-submodule-foreach-reversive.sh | 429 +++++++++++++++++++++++++
6 files changed, 573 insertions(+), 23 deletions(-)
create mode 100755 t/t7427-submodule-foreach-reversive.sh
base-commit: 37b3475fb530c14109211faca33716a173db61ed
--
2.56.0
Technical Details
Message-ID:
<20261028001529.81557-1-whatfield.git@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73578-linux-kernel-git=dewy.ruReferences:
<20260131214309.1899376-1-whatfield.git@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-73578-linux-kernel-git=dewy.ru
From: whatfield.git@gmail.com (William Hatfield)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 0/3] submodule: foreach in reverse order, with the superproject
Date: Tue, 27 Oct 2026 20:15:26 -0400
Organization: Usenet Network
Message-ID: <20261028001529.81557-1-whatfield.git@gmail.com>
References: <20260131214309.1899376-1-whatfield.git@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1666375"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qISchou7VYeNyQq7iu1RhSvquyo= sha256:pxYiEvcuHQJwltuft9GVh7GnOFQFcPdFqqPiNtz0UEE=
sha1:4HMCR+kpvYPXxH61pQEi7b7kM2s= sha256:t5mmFBRPP5MxxFNU+u+djnplpyeteLNwbSuyX2ATlu0=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 25D45125C2C; Wed, 28 Oct 2026 03:15:49 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.148
X-Spam-Status: No, score=-2.148 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 9LKa7Om6HtnO;
Wed, 28 Oct 2026 03:15:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-73578-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id A4E4F125C25; Wed, 28 Oct 2026 03:15:36 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 4F16A60365C; Wed, 28 Oct 2026 00:15:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793146534;
b=DUWUUxa1aaf3X1M/IwljMSfG92WCOPpYaT/ZhFAroe3F6gWEMiSU4dxxM4cJKMXZF180
kgKtygmeOrRe2aDevuh9qbfehtFvXP5wYRdhPJhIAYHjTe7KIogMjKvoQ9v/Gkj6mU9RT
6b5Pmnv9cfTkH/QceALj7G2pGpK2czxRg6GTdPpvq5Ww0Zv8orWvMEEUfMg2BrQ0RgFLz
CL1ywMDSQm8RshU3z+DeL/YCJxy/lFcZHcEHr67hVXr7NdrFe0r4m0j9CEPyehBMkJ/V5
z4ky+w3PqLy+fyrL7cX5tKbs8bWfj4t05YDX0DW+g8zdES6DJOHKXXiErq8kOgH6TSg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793146534;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=0kufzUFQ8a5cekKgSVKYdYZlTro9zGZLuNn1kSFvO2Q=;
b=H2GUHztflOFYfUDFJLApjGMGpK1aaG3yWKwU90mFBw1MsoGN/oILyBR9e1CP4AIvIwr1
voqj2XeCHyXJeGd6lPgY+MGJXyYyYv5tmic6pmt7aQJnus7DmMfGHrkZ5yU/c/kEimaqo
fkDpX5rFMh7JpPUCBCAjRv8H+UCupFft2J9gmNoWtmcIX/E0ffznOjlK11yAnHy1rkYP2
+GdMXZbQ6LgWrvcWCyqi1hCz9AH1trpFIeV800IOMGH+4Vd3UxnPVwdBYRfdXec3F1X/e
fS6zA31Mk5A3XmqBimDha/DzsQSgUKT3MnKs49SveyIVwj5szY8zfROrJFhdbHLh0Mg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KrpMgTrk;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 01B59606A323;
Wed, 28 Oct 2026 00:15:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KrpMgTrk
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.177
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793146533;
b=zLzDl3gvR3crHeOaLj8cdeTG0hepKznTYOZo0zuChyhKR0FmsknPSPZASFhGE0k5K8Vr
eErOco1EOhQZUgRr9/T/yqHQoWj8GpLQNtDqr37YSlA5j5u4v2+qSKcy6jRTwEY3lvyQG
6/E6Vbzp0+SDo199fMR57lg1zTTSb/u4pDdLSDDtitGoHGM9eB+PYbbgVLVsVgFxaNyRv
JISKeoFEJES135EE4KzAMr82r0tpA5kQAo4hKYtxyd8Co2rnHy0hglhMF4Li8C6mCxZku
aY4V3oQeucDpPlwIlVRxmnhr1whafn3pQ1mAvgkZm97fYM/jiF+E8UFiH+djtLPVpeA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793146533;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=0kufzUFQ8a5cekKgSVKYdYZlTro9zGZLuNn1kSFvO2Q=;
b=BJ5Z3m+tjJu5K4lzd6+p8glZw066mbr4Ab+wUSAbxAcjoYDnwl0AzX0+2Kn42fgqNYQH
UEKgdMCoS5C7MnrQIyYuEqsbDTd45LMfAW6dzU6owBew9dA5ma2nDsBAzO77798qZRM32
gi8S9jrvMpnGL/m0Sm7A3JdnX35M8EfiuQgfyi27b1Zn2tOS+x5gBELKRJ3+GJg7i1QMb
IoyvsxyINuh50ghp1C+nlYZab4DpuZpG5EKqm/W7Erfqb6tCpr+i39AhQAazeDbkNclpQ
McsAvG4SelYTtjdFWB0+5W8qwPmw7WcG5vA/ApOv4RQHFpC6jGF5lUhmLBLUZQq/ewA==
X-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=KrpMgTrk;
arc=none smtp.remote-ip=209.85.160.177
X-Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.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 B1299606A31D
for <git@vger.kernel.org>; Wed, 28 Oct 2026 00:15:32 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B1299606A31D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-53667180af3so6092471cf.2
for <git@vger.kernel.org>; Tue, 27 Oct 2026 17:15:32 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793146532; x=1793751332; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=0kufzUFQ8a5cekKgSVKYdYZlTro9zGZLuNn1kSFvO2Q=;
b=KrpMgTrkq5UC0T+9KvY0eWagng1YzKNzm5phtyLqjS1cdx6lyN+ILI5//YeADS4BPU
dPlDMZq7pcJy1ELXDiqhOVl//1v4Kl8U9YopunhIXeqvDJupJrD2HuefyY+ikijqqrXs
kUU9ZDzvmEqNVMK1Ag9KNMfSG+6OJkdxN1iPtxNdy27v5GLY3+7/uK6YQm91smBVssuo
89ALeKIpGraAXhnqNk1MbSp81lcuw3WaRZ+Lq/GJ5jeYGkrP2UY9KFLyLAd23QqLYLuN
vV7AnzGVZDkF/ZXQBgYeVBItcMSasA8qisTA2AWjauM9/mN/UtDm4IUTExzWyHDEBQ0K
4eAg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793146532; x=1793751332;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=0kufzUFQ8a5cekKgSVKYdYZlTro9zGZLuNn1kSFvO2Q=;
b=KAf0dw6ZFV9Ljf7Dw1SuEkgUSrIS4wcucS0V2W5LqL6cqPax5kB1qDL5XDXH3gOP7n
5W+szMPiEoun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received: by 2002:ac8:5e06:0:b0:536:986f:e97e with SMTP id d75a77b69052e-53fccbb76e9mr15334611cf.63.1793146531618;
Tue, 27 Oct 2026 17:15:31 -0700 (PDT)
X-Received: from Williams-MBP.internal ([107.11.98.107])
by smtp.gmail.com with ESMTPSA id 6a1803df08f44-91c6e20ba4fsm38666656d6.14.2026.10.27.17.15.30
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Tue, 27 Oct 2026 17:15:31 -0700 (PDT)
X-Cc: Junio C Hamano <gitster@pobox.com>,
Jean-Noël AVILA <jn.avila@free.fr>,
Patrick Steinhardt <ps@pks.im>,
Glen Choo <glencbz@gmail.com>,
Ævar Arnfjörð Bjarmason <avarab@gmail.com>,
William Hatfield <whatfield.git@gmail.com>
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <20260131214309.1899376-1-whatfield.git@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list