Article View: linux.kernel.git
Article #4116[PATCH v17 1/7] fetch: do not apply --refmap to a refspec with a destination
From: "Harald Nordgren via GitGitGadge...
Date: Mon, 30 Nov 2026 13:46
Date: Mon, 30 Nov 2026 13:46
124 lines
15497 bytes
15497 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>
"git fetch --refmap=<map> <remote> <src>:<dst>" stores the fetched
ref twice, once at <dst> and once where <map> sends <src>. That is
harmless while --refmap has to be typed on the same command line,
but a later commit lets a remote configure a default for --refmap,
and then a refspec that names its own destination would have no way
to say "store it only here".
Apply --refmap only to refspecs with an empty <dst>, which is what a
bare <src> is shorthand for. A refspec with a non-empty <dst> is
stored there and nowhere else.
The opportunistic update of remote-tracking branches through
remote.<name>.fetch is left alone, so "git fetch origin main:tmp"
still updates origin/main.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
Documentation/fetch-options.adoc | 4 +++-
builtin/fetch.c | 31 ++++++++++++++++++++++++-------
t/t5510-fetch.sh | 12 ++++++++++++
3 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/Documentation/fetch-options.adoc b/Documentation/fetch-options.adoc
index 47dea1de8e..54c5c8f671 100644
--- a/Documentation/fetch-options.adoc
+++ b/Documentation/fetch-options.adoc
@@ -239,7 +239,9 @@ endif::git-pull[]
specified refspec (can be given more than once) to map the
refs to remote-tracking branches, instead of the values of
`remote.<name>.fetch` configuration variables for the remote
- repository. Providing an empty _<refspec>_ to the
+ repository. A ref fetched with a refspec `<src>:<dst>` with
+ non-empty `<dst>` is stored only there and is not mapped.
+ Providing an empty _<refspec>_ to the
`--refmap` option causes Git to ignore the configured
refspecs and rely entirely on the refspecs supplied as
command-line arguments. See section on "Configured Remote-tracking
diff --git a/builtin/fetch.c b/builtin/fetch.c
index c646bc6698..0ee252e353 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -274,6 +274,23 @@ static void add_merge_config(struct ref **head,
}
}
+static void map_refs_without_dst(const struct ref *ref_map,
+ const struct refspec *refmap,
+ struct ref ***tail)
+{
+ struct ref *unmapped = NULL, **unmapped_tail = &unmapped;
+
+ for (const struct ref *rm = ref_map; rm; rm = rm->next) {
+ if (rm->peer_ref)
+ continue;
+ *unmapped_tail = copy_ref(rm);
+ unmapped_tail = &(*unmapped_tail)->next;
+ }
+ for (int i = 0; i < refmap->nr; i++)
+ get_fetch_map(unmapped, &refmap->items[i], tail, 1);
+ free_refs(unmapped);
+}
+
static void create_fetch_oidset(struct ref **head, struct oidset *out)
{
struct ref *rm = *head;
@@ -530,8 +547,6 @@ static struct ref *get_ref_map(struct remote *remote,
filter_prefetch_refspec(&remote->fetch);
if (rs->nr) {
- struct refspec *fetch_refspec;
-
for (i = 0; i < rs->nr; i++) {
get_fetch_map(remote_refs, &rs->items[i], &tail, 0);
if (rs->items[i].dst && rs->items[i].dst[0])
@@ -560,14 +575,16 @@ static struct ref *get_ref_map(struct remote *remote,
* which has FETCH_HEAD_NOT_FOR_MERGE, is not removed
* by ref_remove_duplicates() in favor of one of these
* opportunistic entries with FETCH_HEAD_IGNORE.
+ *
+ * A refspec that names its own destination is not
+ * mapped through --refmap.
*/
if (refmap.nr)
- fetch_refspec = &refmap;
+ map_refs_without_dst(ref_map, &refmap, &oref_tail);
else
- fetch_refspec = &remote->fetch;
-
- for (i = 0; i < fetch_refspec->nr; i++)
- get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1);
+ for (i = 0; i < remote->fetch.nr; i++)
+ get_fetch_map(ref_map, &remote->fetch.items[i],
+ &oref_tail, 1);
} else if (refmap.nr) {
die("--refmap option is only meaningful with command-line refspec(s)");
} else {
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 5b27f1d5bb..38185e192d 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -927,6 +927,18 @@ test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
)
'
+test_expect_success '--refmap is not applied to a refspec with a destination' '
+ git branch -f side &&
+ (
+ cd three &&
+ git fetch --refmap="refs/heads/*:refs/remotes/mapped/*" origin \
+ main:refs/remotes/custom/main side: &&
+ git rev-parse --verify refs/remotes/custom/main &&
+ test_must_fail git rev-parse --verify refs/remotes/mapped/main &&
+ git rev-parse --verify refs/remotes/mapped/side
+ )
+'
+
test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
git branch -f side &&
(
--
gitgitgadget
Technical Details
Message-ID:
<c6d650df3a5ce03ff574923df9b7b627bd2a2481.1796046376.git.gitgitgadget@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76673-linux-kernel-git=dewy.ruReferences:
<pull.2412.git.git.1789829246437.gitgitgadget@gmail.com> <pull.2412.v17.git.git.1796046376.gitgitgadget@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76673-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v17 1/7] fetch: do not apply --refmap to a refspec with a
destination
Date: Mon, 30 Nov 2026 13:46:10 +0000
Organization: Usenet Network
Message-ID: <c6d650df3a5ce03ff574923df9b7b627bd2a2481.1796046376.git.gitgitgadget@gmail.com>
References: <pull.2412.git.git.1789829246437.gitgitgadget@gmail.com>
<pull.2412.v17.git.git.1796046376.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1437507"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7ECPiKD6hRYaWaQzoEbi3HUAppM= sha256:3sI7wwhZguFdNa+KemBlRSbtxYg+4Wl6kviSSz7fOfg=
sha1:oUbKspEL22cP9rynifH0Wli1f98= sha256:HtV5zKgfs4tRtDEfbdZvYiTCXt0vIAH6XrKNTxb7c8w=
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 8EB6C125FF1; Mon, 30 Nov 2026 16:46:40 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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.249,
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 dwhaYneeZgZh;
Mon, 30 Nov 2026 16:46:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76673-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 02BBB125FF3; Mon, 30 Nov 2026 16:46:27 +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 275692C44C; Mon, 30 Nov 2026 13:46:22 +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=1796046381;
b=RE9mMdRMTuw+J+yacAqDaqn2UZFyw4y0k/0hnjYrZ13OQlmwoiZlwZL0lzUQzQh5a1hs
jApBmrQPtcvDBUDf/mHC3iKvjiOo9ICowV7UBPSbF0ooY9hnHsoXf9GzIOLh6EYFClSPx
79p1oVAuNxh2udFRwlpUxV1zFZa+jEHiVZbf1HYk7IAwKQMrKx8QPaXeUB99daPWpHnPD
6AVb7A3fyVwyLyDw6GDn4+e8QkMU7ZURCuBOGhugBcVn29sqQ4uqa4cudEXzUxw1XUSeu
vwMNQgHDcSProHkndi/Q2gyvKqw1e7EJaIBkOmKrZK8bdwarWLZF/hR9IOdOwWAgfRg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796046381;
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=q4LZdSn7vOGFs2G+Bg0sik22RyimpXv3uhxkKqDfEWk=;
b=0/zMxJok2y67/Fzf8Gte2d9i/J6cLt0QT+8tfYnwownXsAXoxTkiChJthyJUeZgdLyeI
/pA8+h3kbo6xLMMDy3V7al9KKf0Ek1KY8dUpxmX/35lkMnhArZsuyvkW6MMF1zg/itJy7
fDqnAnert0Sop3m0KwXlTYzygni/jI8JI22TEXA/3ZOvkkBdNrT+W/K4ZgeQ3PHeYQmSV
U2UaiTVI8hZdlLNNYs4RQxBFHiXm9FaiErRN+5XepAKLXMwQVJKq3i1C88U+vjnmT7zoE
R8IF4Fs3wukxNe4z945aHXSNge5y87lg9ta0qyewzqFKzeFcMkJfXN4Y8wGhnW2s13g==
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=KwP+xBb+;
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 0960C606A336;
Mon, 30 Nov 2026 13:46:21 +0000 (UTC)
X-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=KwP+xBb+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796046380;
b=LTbpyGCpGh0JOufmE3kwNUot8GDBIGGoE1jJYImRCdutRA96f8PRoBjcxVQ2zHVKjmkN
saegMsHUx6CDItbBn+pBd9l87THOb/ppX+bRds6p5h3vRKoKF2ZR3Up1d/KvPedSe9I2w
QigmP6s4+u5IJCaW4ljQdVD0kgzJjCupZT6R4CimLt/f1qIjBJl+4Fp4xikSt5HFcQkLl
1fahNlO07MUa+BRUHiCsuw0mkzrqQ1riAGsI/uqrrQneBPszL8tEIGxQD3jONGGWJHZ0E
fSTzbCy9MH+9WDfXi5YCXtQwMOMhfTV+xtnaISyzlAZCljq7EDaigQnI4XCvAaA1sLw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796046380;
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=q4LZdSn7vOGFs2G+Bg0sik22RyimpXv3uhxkKqDfEWk=;
b=CbjOy6DdK2gGrjdd/uvmFoiwvp34I8clGl0EeKAVSDW3rPuSEm12byYmnd+eqRX3kmc4
eugEnvK8mZFTAXCsVbLQD6lQfWCgZbse4vdqVSTcROwlgWRoHTkBuEK99Zuj5pFIgxGlx
csFSgChtFv8rclZXhBMKU0fk7vGuAwSyZX15jzZGEjlKrrX9b1M+q4ND0G81RIHp2Jw9H
R48Tirf5OrHqbYaRp2Xznq4dCEurbUsfp2ykIaTi5Xizq57J8ip0i+Gvae5irTAOY1ybV
CyCYmLWqaICb9Y1r7psrWe7KBTYP4C8F3lMPA73DxiAYovelFH3vrxHv5i3MPLfE6HA==
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=KwP+xBb+;
arc=none smtp.remote-ip=209.85.219.44
X-Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44])
(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 D2ABB606A320
for <git@vger.kernel.org>; Mon, 30 Nov 2026 13:46:19 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2ABB606A320
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-qv1-f44.google.com with SMTP id 6a1803df08f44-921276742e3so92018036d6.2
for <git@vger.kernel.org>; Mon, 30 Nov 2026 05:46:19 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796046379; x=1796651179; 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=q4LZdSn7vOGFs2G+Bg0sik22RyimpXv3uhxkKqDfEWk=;
b=KwP+xBb+3ikGjtholQMCpWwMe6AZ6+w1rXtJtORIZoZnPttMyiu3GeUdWoGjtzIw6P
X8BA2H1RKVQ5zorhFubQeZsBBSDjP3+ALMKotGGQGoRTDu1sU/9tNhw0daN4BZsr6w5w
wtzkRWyY6BnbTOL66KCrAGcLRyEXZw9OO+D3QjtI6mnSQk/x5dSaLA46qRg7h4UfDyey
1Ti73k8jNJUhlocUnVzHgt2oyrg7kIr1MunDwK5yt+7Luus0RCS+JU5UfYnFqPpjNgZY
JHXHowW1PxjCFYbop3mLP34KgU9A1gi4K5kOS9KMMbqREM77BTUufRddVeWV5a1lobrn
Icnw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796046379; x=1796651179;
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=q4LZdSn7vOGFs2G+Bg0sik22RyimpXv3uhxkKqDfEWk=;
b=DWcJ01+gw+vEFPOjb3fvi2GaK9OUPLFbDBLFLu17bepyagj33egDwlO68CNUsQz9cs
0SVnMBjIrmPHhivNB4gw5UAJmCFVitIJq6yZ6RQ9q8+vTaT0w4y5bFWg7euvKJ3xAdfk
jUyPelg4EYevNLbPH4eC/UYR6rGLpjK+QfZ/b1ht41SrUpkA+M45LsvhT8DRZyzq6tg0
Iet0nL/9t8mo1dLjN3xItao8OCu0N1FdJfTCvfhwAYUGqcizn64GWysHL1A2DhEWxVBs
/Q7olxDL+KvlnS3/u1verneFXRB8jZLgKaGDe+8GBMkaLvlez96KCguWktJO5tkGV9tt
XwYw==
X-Gm-Message-State: APuU4Z9kwpPzi4moBceeGH1PlpRklQ++quupGumz7RI1sJf0iGTjUY5r
FrqF9TgvELZTv4uLUuGGVOYnKQUZ4O0yUR+KjLvwbCRgBiyto7sY8zEBetTwGLoY
X-Gm-Gg: AZFdTZe2PKPIyP3zUWTVnr9xqA2m/9q5Ayb80AYBB8VbQcDP9vUjN+ejFAUrXNcYPBe
evFP2FfROfDLgL7cfAD8aoscjhfYVKq0Gpxg3SCNblZ+h/19OFLNDOtWhhJNiMGicBbe2ZyDXlY
R3WbrZsaPL3MAhmVHjvab3qGl/DQQ/DsRdVFUSEYqpM9sDhxM9txhfXJOXKoJt/FINTM5+yFO71
vH08vBd7ntchabZ3kZBG6WjboIQ2KeIkz5B4Xpkuk5HjxWWamVgXXw3i7Wu2N+khDfXruvLu18b
aqM10ijSG/g7+RGhFLT5ys7yorAbemtuimEKfg0uAhIGRPFB741ha1YkrG+8blR2byHUgzyexSh
K3mEmGIWpOahhwtlBSITYs5NBWaOSOw3njJb99j7Y1+C1u26f0NFOhEAjhUn/CBB0fAk3oD35ut
AjdAHxm7rOhvrjO9J/ZCKFDq85BmL7m0UIyfwRkyuDFrm1SdUpzzCF1wk5kp9CsJ+0BvP1CJ1zK
PMwH9/+KF+NYbJoKMaJx8Gu9evnNlfahB+RqyVbntDZ78ukjz8bE8cMJBrucf83rPFAFqJ5r/Gi
X55P86GGaRFt3ttKaXS+FpDnk72l4E8H
X-Received: by 2002:a05:6214:495:b0:921:2fb5:2fe6 with SMTP id 6a1803df08f44-92134a861d9mr643244606d6.34.1796046378674;
Mon, 30 Nov 2026 05:46:18 -0800 (PST)
X-Received: from [127.0.0.1] ([20.49.63.207])
by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921349d14d1sm296858986d6.18.2026.11.30.05.46.18
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 30 Nov 2026 05:46:18 -0800 (PST)
X-In-Reply-To: <pull.2412.v17.git.git.1796046376.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>,
Matt Hunter <m@lfurio.us>,
Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>