🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #1450

[PATCH v11 5/5] remote: default to --limited-fetch in a shallow repository

#1450
From: "Harald Nordgren via GitGitGadge...
Date: Sun, 25 Oct 2026 20:25
146 lines
16415 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>

Adding a second remote to a shallow clone used to still fetch every
branch that remote has, since "git remote add" always set up a
wildcard remote.<name>.fetch refspec regardless of how shallow the
repository already was. That defeats the purpose of having cloned
shallow in the first place (for example with --single-branch), and
can make a plain "git fetch" on that remote hang or take a very long
time on a repository with many branches.

Turn --limited-fetch on by default when the repository is already
shallow and neither -t/--track nor --mirror was given, so that
adding a remote there does not by itself commit to following every
branch it has. --no-limited-fetch keeps the previous behavior for
whoever wants it.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 Documentation/git-remote.adoc |  8 ++++-
 builtin/remote.c              |  5 ++-
 t/t5505-remote.sh             | 60 +++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-remote.adoc b/Documentation/git-remote.adoc
index f8764394e7..f43d707c91 100644
--- a/Documentation/git-remote.adoc
+++ b/Documentation/git-remote.adoc
@@ -57,6 +57,11 @@ Add a remote named _<name>_ for the repository at
 _<URL>_.  The command `git fetch <name>` can then be used to create and
 update remote-tracking branches `<name>/<branch>`.
 +
+If the repository is already a shallow repository (see linkgit:git-clone[1]
+`--depth`) and neither `-t`, `--mirror` nor `--no-limited-fetch` is given,
+`--limited-fetch` is turned on by default, so that `git fetch <name>` does
+not need to negotiate history for every branch the remote has.
++
 With `-f` option, `git fetch <name>` is run immediately after
 the remote information is set up.
 +
@@ -79,7 +84,8 @@ With `--limited-fetch` option, instead of a `remote.<name>.fetch` refspec
 that tracks all branches, `remote.<name>.refmap` is set up so that a
 refspec-less `git fetch <name>` only fetches branches our local branches
 are built on. See the `--refmap` entry in linkgit:git-fetch[1] for
-details.
+details. `--no-limited-fetch` explicitly disables this, overriding the
+shallow-repository default described above.
 +
 With `-m <master>` option, a symbolic-ref `refs/remotes/<name>/HEAD` is set
 up to point at remote's _<master>_ branch. See also the set-head command.
diff --git a/builtin/remote.c b/builtin/remote.c
index 7e81a91aef..0104f23761 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -16,6 +16,7 @@
 #include "rebase.h"
 #include "refs.h"
 #include "refspec.h"
+#include "shallow.h"
 #include "odb.h"
 #include "strvec.h"
 #include "commit-reach.h"
@@ -238,7 +239,9 @@ static int add(int argc, const char **argv, const char *prefix,
 
 	if (!mirror || mirror & MIRROR_FETCH) {
 		bool use_limited_fetch = mirror == MIRROR_NONE && track.nr == 0 &&
-			limited_fetch == 1;
+			(limited_fetch == 1 ||
+			 (limited_fetch == -1 &&
+			  is_repository_shallow(the_repository)));
 
 		strbuf_reset(&buf);
 		if (use_limited_fetch) {
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 0168d5abfe..f3b5905e9e 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -137,6 +137,66 @@ test_expect_success 'filters are listed by git remote -v only' '
 	test_grep ! "\[blob:none\]" out
 '
 
+test_expect_success 'add remote -t keeps an explicit refspec in a shallow repository' '
+	test_when_finished "rm -rf shallow-add" &&
+	git clone --no-local --depth=1 --branch main --single-branch \
+		one shallow-add &&
+	(
+		cd shallow-add &&
+		git remote add -t main upstream ../two &&
+		test_cmp_config "+refs/heads/main:refs/remotes/upstream/main" \
+			remote.upstream.fetch
+	)
+'
+
+test_expect_success 'add remote keeps the wildcard refspec in a full repository' '
+	test_when_finished "rm -rf full-add" &&
+	git clone --no-local one full-add &&
+	(
+		cd full-add &&
+		git remote add upstream ../two &&
+		test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \
+			remote.upstream.fetch
+	)
+'
+
+test_expect_success 'a remote added in a shallow repository defaults to --limited-fetch' '
+	test_when_finished "rm -rf shallow-add" &&
+	git clone --no-local --depth=1 --branch main --single-branch \
+		one shallow-add &&
+	(
+		cd shallow-add &&
+		git remote add upstream ../two &&
+		test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \
+			remote.upstream.refmap &&
+		test_must_fail git config get remote.upstream.fetch &&
+		git fetch upstream main &&
+		git branch --set-upstream-to=upstream/main &&
+		test_cmp_config upstream branch.main.remote &&
+		test_cmp_config refs/heads/main branch.main.merge &&
+		git fetch upstream &&
+		git for-each-ref --format="%(refname)" refs/remotes/upstream >actual &&
+		cat >expect <<-\EOF &&
+		refs/remotes/upstream/HEAD
+		refs/remotes/upstream/main
+		EOF
+		test_cmp expect actual
+	)
+'
+
+test_expect_success '--no-limited-fetch overrides the shallow-repository default' '
+	test_when_finished "rm -rf shallow-add" &&
+	git clone --no-local --depth=1 --branch main --single-branch \
+		one shallow-add &&
+	(
+		cd shallow-add &&
+		git remote add --no-limited-fetch upstream ../two &&
+		test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \
+			remote.upstream.fetch &&
+		test_must_fail git config get remote.upstream.refmap
+	)
+'
+
 test_expect_success '--limited-fetch works in a full repository too' '
 	test_when_finished "rm -rf full-add" &&
 	git clone --no-local one full-add &&
-- 
gitgitgadget
Technical Details
Message-ID: <de0daa8623b76c47b5c822d0aaa4287950f5c780.1792959921.git.gitgitgadget@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-73222-linux-kernel-git=dewy.ru
References: <pull.2412.git.git.1789829246437.gitgitgadget@gmail.com> <pull.2412.v11.git.git.1792959921.gitgitgadget@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-73222-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v11 5/5] remote: default to --limited-fetch in a shallow
 repository
Date: Sun, 25 Oct 2026 20:25:21 +0000
Organization: Usenet Network
Message-ID: <de0daa8623b76c47b5c822d0aaa4287950f5c780.1792959921.git.gitgitgadget@gmail.com>
References: <pull.2412.git.git.1789829246437.gitgitgadget@gmail.com>
	<pull.2412.v11.git.git.1792959921.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1124720"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VDVzEHDlGRdP+Nykj8wae4Y78mw= sha256:YI04UOWY+6LzcmcztQSb9StdBEBLkUNNq8dt8/3R33w=
	sha1:jUrah6v7GBZkPyjI3JuEIvu7wRY= sha256:y6yZW6OIr69y5hLPiz2RCP0iYiknhPdqwLRK8Zp3RW0=
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 16CEC125B64; Sun, 25 Oct 2026 23:26:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.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 nQ5gdxY75wPU;
	Sun, 25 Oct 2026 23:26:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-73222-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id B5ACF125B52; Sun, 25 Oct 2026 23:26:13 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id AD89A3A3F0; Sun, 25 Oct 2026 20:25:30 +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=1792959930;
	b=lulG/3fdh6+xpintnPYkHoZwSR6C0Om2CrrwUgzeFuisxvL4CIP0A/whu+lds4luNUyW
	 OQe41EjV2ZtcQmLdFIvFNZwF+gIh3kjW+Q/TWaKj/xE2Biodm1JciLQRWl5Y8RDFRVAxw
	 JgFELZa9CBjwjanNN4Ik69T7eXe4zw3y5VblQx+6E6tl/e+Vn4kSAivWGMjZpkxx+Cmwa
	 TLDQvKzjk+xKx00D6ZzraSyvJo20DWYJILVqiFBRKHpPl1/WHeyyBRlJD7gdKypLkm8fL
	 yucKwdpRVRs3lCaUFAtgg8DOjbXgdQWy8EdUFgASpD4BsP3TvJaedEDyWitnGcyDYVQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792959930;
	h=X-Original-To:Received: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:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:To:Cc;
	bh=eeEeIh6RGxgGnQ1M/hXIkUZ9QO/4BOzBPOxSHWSbkPk=;
	b=APlW1/OrLH0IlT1VTRUb681DXOzgfAnuEGzJ7jsDYsBkbBKDc8s7NBJ0Ja/Dh8XTAvN+
	 bIteDR+f3BuaBi+8HU8Cf+Ov/L7Ft+UriqUMRfdAwDGgONJfPp+FX0Gka+QPqfnsjldlN
	 u1ci2ftWvs309rHCDZ+WZk9fiK6s6wj+64WVpG1f/JXMUKI6gLYfcnK91N9UlnNfTxi9z
	 NCyIVMoKcac/APWkwHyfTIdJqJGTmuQkuU6dyY+9l/8Y8VAEPHfUaleYqa3wHqXnbRcEX
	 3+ZsGEUi5gdq1o3+59wjTDe7sNL3DqgVuW/pnXsHMfauicRMExvJCPWvYeil4oMr0/w==
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=20251104 header.b="EYbV/uZn";
	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 849C3606A31D;
	Sun, 25 Oct 2026 20:25:30 +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=20251104 header.b=EYbV/uZn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792959929;
	b=mhB1O1/KhzP4iCRYuBhA86fIKFu3kNP4iNuyJwCmaMtTFtrhA/r1Vd/90aHuOhAZQ6VM
	 4/SRYS7jtubhq/e1uwfQrNmJGbKLdTqlCC4Z0c4bl7uGCuF7cOJ/CfZsYNK6g23e4uDiM
	 T+tXvLV14CnkogL04L7LnXokq/WryBveyRBHX9/Y3BipUA611aJL2LpeeiIWD/lK44vYR
	 v/9eoBaUL1QHXVzWqDCUnhWwsCsqpqrK9IGMY/BFDKiK3JFfRu4+MFd+Pr1X8nBT/YLrd
	 Tft1jx016fQKcvOMN3AMqCkrfpQ4hX20a/RdVtikKwF9u4czBBBbDqRxRsANSDD24QA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792959929;
	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=eeEeIh6RGxgGnQ1M/hXIkUZ9QO/4BOzBPOxSHWSbkPk=;
	b=POkiJt1LZlotCE727qtqhvPvS62R/uQtm09tMIuWWsKKkop46ZzLH622dUKK2Ntomw+G
	 bWDbLC47n+EdnI0KnTRYubHUXhCwGgLk7sMJOWdP7oRICP8injX8stQ3vGtCShszhZCim
	 YLgGpWDIUIMIJ9ki4fbneyIqe46jOyh0pRiCodZtedXQ/nJjbKm23m0Vs0wUc8qsn66HN
	 TwCZV+SXOyq+fl2LUU428SuWzc2YQ1DFqvqj9CL30DqMONDpV1/M3zfZ9zDBBYHe/kMj7
	 0QRfBAB2te+u9yLCnOb/5dSSlhFzyJ6m6sXcFMlUHWAtmoyJIcAlPDwFkBEGn+1PxQg==
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=20251104 header.b="EYbV/uZn";
	arc=none smtp.remote-ip=74.125.82.180
X-Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180])
	(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 5176B606A31E
	for <git@vger.kernel.org>; Sun, 25 Oct 2026 20:25:29 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5176B606A31E
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-dy1-f180.google.com with SMTP id 5a478bee46e88-35f036b17easo6284224eec.1
        for <git@vger.kernel.org>; Sun, 25 Oct 2026 13:25:29 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792959928; x=1793564728; 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=eeEeIh6RGxgGnQ1M/hXIkUZ9QO/4BOzBPOxSHWSbkPk=;
        b=EYbV/uZnoOIHS82Yp1QiOeTbbAzmMiDCk+clJ9RLK99Y75Tp8rtGVCzLrmVqV0ZYfO
         kLUkXd1O3wLWiiCz95CAZWtCXxCb75T/zue2dw69IeE3OJppX0a2Mkuj4IFz1HawGIM2
         lTtPoDTElbVgiPSjVwPgzPIIjmF8RTDOe3b3PUVoZZNy37bbD2vEd8Nx7CgI6sK/sUop
         3t5bZuPJPlJobitsrg2+qnq9ziGiFQltgaAqel8/+KdwhD6jnwG1qhnvATWBxybh9HtJ
         UBe5ZIyvbXOb7avfHpT8C1S6mkbUb3lJiEZ4YK6GmtUbTHC/fhN8+dTWGdCt2LGmswQM
         QXAg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792959928; x=1793564728;
        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=eeEeIh6RGxgGnQ1M/hXIkUZ9QO/4BOzBPOxSHWSbkPk=;
        b=dyPO8BTwsMPYhzBICy/CWela4H37XiEJ4ArG3KBxaG5Bah0v0RkE0Paz2PwY9v4uwh
         CECaQFBLTv1WrD4X5VP/A5hPDPSC2eIO7A3C6nHQYahSd3VZ61OtZNuVoLZ/PPDiquWK
         qTJ1J6hXQPpbomP96eQArO8Vjt53dh1RCGVbKMBr4Gb9E8eDYWtf0BGmSV/Ba949Zmld
         GTVYakH4/XcQ05kZNsFv94JkluBrEX5JO8STXyFNWGGwuL2Ji9COIH5xvJZbzdbzq5EB
         VHgzbokT37t+nU6vWTJEr27tkb36dEI+6RfL3r5Mo7H+4AGSFTTV2P6Zb6aEj2DgDVLS
         UZmw==
X-Gm-Message-State: AFq9FYLbm5+ArFSnZ/eWdHQzqwuDTbRWALkM58NH3DagNi1tZ98iyVwJ
	9Fp9S9snfXtu8RciToLQTSSos+7HwtXEWVutvuZboeLl+sQpjoht2suQmo5mX5rdFMc=
X-Gm-Gg: AYBFou3IGxrJTPgan9YGrCiz8zzCWpr9sGo09+yqz37QRvABsSiKsF/SpedYmTSFOmL
	POUXtSLd8yidMTWZD4KIGBYAdRTIhWH+G7vps1v1eOoL8quJci+mIplULTa1f1bowLukpfFTONQ
	QfSYEm5cdI7+vCEQpiMyqxV9F+LVqN1I9ojfbMdj3hD98QVzx7/G72/ViHfAN3OE7dvGLBYQ4b4
	Fjp0r7bBPdhz8Aep7ix91GwvX7UrRlKrkO8FEDbLLEaiM0eTUuFwAmGKNcVhlPtfntH6svRGTVv
	W/kG9xzckI16IbG439CWJozzD58/6sKYQXgbdHxE7LCmZUt3vy3uBt1QGSutKMrTTI/5v9Wlkiq
	QyzJk13OxWHQftQrYYGPxjOWzyilYfrbNri40Rn3b6XgGH2ziNt3IgSi314PdrlCfenO0ariq3t
	/DrV9peZN5WZdTweeslh1we8IsrVn7sdlbkW1NraVgzxEyb2MJ6UQST5ETGKH+yL9v/IDUhYWuC
	21qkquW/B+gqYFKnlQMhRvDDG+5xgYt1TQp8RM1/BdUhnEnAzDZNX9e
X-Received: by 2002:a05:7300:2301:b0:347:8d01:164f with SMTP id 5a478bee46e88-369e84b15ccmr11938059eec.19.1792959928267;
        Sun, 25 Oct 2026 13:25:28 -0700 (PDT)
X-Received: from [127.0.0.1] ([4.242.195.32])
        by smtp.gmail.com with ESMTPSA id 5a478bee46e88-369e8ee72c0sm28361533eec.29.2026.10.25.13.25.27
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 25 Oct 2026 13:25:27 -0700 (PDT)
X-In-Reply-To: <pull.2412.v11.git.git.1792959921.gitgitgadget@gmail.com>
X-Fcc: Sent
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
X-Cc: Phillip Wood <phillip.wood123@gmail.com>,
    "D. Ben Knoble" <ben.knoble@gmail.com>,
    Harald Nordgren <haraldnordgren@gmail.com>,
    Harald Nordgren <haraldnordgren@gmail.com>