From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.44 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== 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== 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 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 ; Mon, 30 Nov 2026 13:46:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2ABB606A320 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=KwP+xBb+ Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-921276742e3so92018036d6.2 for ; Mon, 30 Nov 2026 05:46:19 -0800 (PST) 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) 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) Message-Id: In-Reply-To: References: From: "Harald Nordgren via GitGitGadget" Date: Mon, 30 Nov 2026 13:46:10 +0000 Subject: [PATCH v17 1/7] fetch: do not apply --refmap to a refspec with a destination 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: Phillip Wood , "D. Ben Knoble" , Matt Hunter , Kristoffer Haugsbakk , Harald Nordgren , Harald Nordgren From: Harald Nordgren "git fetch --refmap= :" stores the fetched ref twice, once at and once where sends . 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 , which is what a bare is shorthand for. A refspec with a non-empty is stored there and nowhere else. The opportunistic update of remote-tracking branches through remote..fetch is left alone, so "git fetch origin main:tmp" still updates origin/main. Signed-off-by: Harald Nordgren --- 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..fetch` configuration variables for the remote - repository. Providing an empty __ to the + repository. A ref fetched with a refspec `:` with + non-empty `` is stored only there and is not mapped. + Providing an empty __ 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