Article View: linux.kernel.git
Article #1986[PATCH v2 2/2] remote: resolve "simple" @{push} when pushing to another remote
From: "Harald Nordgren via GitGitGadge...
Date: Sat, 31 Oct 2026 08:04
Date: Sat, 31 Oct 2026 08:04
114 lines
15148 bytes
15148 bytes
From: Harald Nordgren <haraldnordgren@gmail.com>
With push.default left at "simple", a branch whose upstream is on one
remote and whose push remote is another gets pushed by "git push" to a
branch of the same name on the push remote. But @{push} for that
branch fails with "cannot resolve 'simple' push to a single
destination". As a result "git status" shows the "git push" hint under
the comparison with the upstream, even though "git push" goes
elsewhere, and leaves out the comparison with the push branch when
status.compareBranches asks for it.
"git push" learned to handle "simple" this way in ed2b18292b (push:
change `simple` to accommodate triangular workflows, 2013-06-19). When
@{push} was added in e291c75a95 (remote.c: add branch_get_push,
2015-05-21), its "simple" case only covered pushing back to the remote
the branch is fetched from, where the upstream must have the same name.
Make @{push} follow "git push". When the push remote is not the remote
of the branch, resolve to the branch of the same name on the push
remote, as "current" does.
The test added in 9bf9eed093 (remote: fix leak in branch_get_push_1()
with invalid "simple" config, 2026-01-19) relied on a different push
remote being invalid for "simple". Use an upstream with a different
name on the same remote instead, so that it still exercises the error
path.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
remote.c | 13 ++++++++-----
t/for-each-ref-tests.sh | 4 +++-
t/t1514-rev-parse-push.sh | 13 ++++++++++++-
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/remote.c b/remote.c
index d15d34aad7..98665a3085 100644
--- a/remote.c
+++ b/remote.c
@@ -1972,16 +1972,19 @@ static char *branch_get_push_simple(struct repository *repo,
struct branch *branch,
struct strbuf *err)
{
- const char *up;
+ const char *up = NULL;
char *cur;
- up = branch_get_upstream(branch, err);
- if (!up)
- return NULL;
+ if (!strcmp(remote->name,
+ remotes_remote_for_branch(repo->remote_state, branch, NULL))) {
+ up = branch_get_upstream(branch, err);
+ if (!up)
+ return NULL;
+ }
cur = tracking_for_push_dest(repo, remote, branch->refname, err);
if (!cur)
return NULL;
- if (strcmp(cur, up)) {
+ if (up && strcmp(cur, up)) {
free(cur);
return error_buf(err,
_("cannot resolve 'simple' push to a single destination"));
diff --git a/t/for-each-ref-tests.sh b/t/for-each-ref-tests.sh
index b1a10dd933..4991a82b91 100644
--- a/t/for-each-ref-tests.sh
+++ b/t/for-each-ref-tests.sh
@@ -1745,9 +1745,11 @@ test_expect_success ':remotename and :remoteref' '
'
test_expect_success '%(push) with an invalid push-simple config' '
+ test_when_finished "git config branch.main.merge refs/heads/main" &&
+ git config branch.main.merge refs/heads/not-main &&
echo "refs/heads/main " >expect &&
git -c push.default=simple \
- -c remote.pushdefault=myfork \
+ -c remote.pushdefault=origin \
for-each-ref \
--format="%(refname) %(push)" refs/heads/main >actual &&
test_cmp expect actual
diff --git a/t/t1514-rev-parse-push.sh b/t/t1514-rev-parse-push.sh
index 5a4f16867a..dc2df7eb80 100755
--- a/t/t1514-rev-parse-push.sh
+++ b/t/t1514-rev-parse-push.sh
@@ -39,7 +39,7 @@ test_expect_success '@{push} with default=simple' '
resolve main@{pUSh} refs/remotes/origin/main
'
-test_expect_success 'triangular @{push} fails with default=simple' '
+test_expect_success '@{push} with default=simple fails when upstream has a different name' '
test_config push.default simple &&
test_must_fail git rev-parse topic@{push}
'
@@ -60,6 +60,17 @@ test_expect_success '@{push} with pushremote defined' '
resolve topic@{push} refs/remotes/other/topic
'
+test_expect_success 'triangular @{push} with default=simple and remote.pushdefault' '
+ test_config push.default simple &&
+ test_config remote.pushdefault other &&
+ test_when_finished "git checkout main" &&
+ git checkout topic &&
+ test_commit simple-triangular &&
+ git push &&
+ resolve topic@{push} refs/remotes/other/topic &&
+ test_cmp_rev topic topic@{push}
+'
+
test_expect_success '@{p} is short for @{push}' '
test_config push.default current &&
test_config branch.topic.pushremote other &&
--
gitgitgadget
Technical Details
Message-ID:
<c58afcc4b166d33489feee41d57e65738581a0da.1793433841.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-73984-linux-kernel-git=dewy.ruReferences:
<pull.2466.git.git.1793105039624.gitgitgadget@gmail.com> <pull.2466.v2.git.git.1793433841.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-73984-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("Harald Nordgren via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH v2 2/2] remote: resolve "simple" @{push} when pushing to
another remote
Date: Sat, 31 Oct 2026 08:04:01 +0000
Organization: Usenet Network
Message-ID: <c58afcc4b166d33489feee41d57e65738581a0da.1793433841.git.gitgitgadget@gmail.com>
References: <pull.2466.git.git.1793105039624.gitgitgadget@gmail.com>
<pull.2466.v2.git.git.1793433841.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2406386"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Nbfa3gu714Xhb21/RMseBZ6RO0g= sha256:1klQfO3vIG7fW2cTdR8LxXFgJ85IOMxAse+UPKk545k=
sha1:9O1UbBlwR7bTVU6khEXiKLZgc0k= sha256:F5bVMz4X11wQP89SzxnDOWB3S+aoqqe/zPXv3Ni7Q/w=
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 C808D125CB6; Sat, 31 Oct 2026 11:04:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, 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 LtL9s5nLD8Yu;
Sat, 31 Oct 2026 11:04: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-73984-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 1A343125CB2; Sat, 31 Oct 2026 11:04:29 +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 04F5E2A95F; Sat, 31 Oct 2026 08:04:10 +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=1793433849;
b=be5ib3UjkNaIiWpzHwAAB1LWK8sDUd1QjoF40MuOHeK1i544TfAeB1u95BsHvJaQgdNw
P8CvXt/rxmKwoi7oe7hqGjSOelghev4DABfZYKz4QxJQgFIS+kGI5LUmRdTf8cmhEmm7v
bZrfs6ACXMs/i1yWYCOvJ+JoPy8zeCa/hd3wg5r6b8mIcSqo9YXvCvglCkpivkdWEV/pO
coETXjukuw3AbZQDjSKt+fE9WuTOJB7jYOtPyFYP3CgTPDANlJ9Mp1IZgj4Yq10UUlHw8
ZYfl/nTjvh3FZdqYZ7ZIr//m8SS2vxLa1Hs+P2/sZaglAJycvAuph8kQBypxR418mKQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793433849;
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=W3Lf7J7cS0JWq4lihEaDpQQyKgxvs533xxklAJLyVm4=;
b=fs5Exs08QYF9wsQUsrCscMLyWy4NV91+Zv2UBmcu+jZCKZSYh6Dei9bBCgls0ugBBBkx
i31WS/hNzbvt6YZHXS5jGrOTPaZxTpHVkUySsXg0aPRK8P3yru5eXo0jbBTC58XNs8kKz
FXqhWvwS+1NRAyM/QTnzJ4C3UXeJxQPX8R37gOAfZtqcyuNhpFkiFh/JwHBFMXlLcStzH
0vo5aGpLo5pMppQj5bv5fXg8vvVQTdWcdZ8Ad3hLNpOdSc24HUJ3GiopgQEhvGT89cSCR
yOmf0jI/ZQ6/jplvpAs9BxadDl4ZXU8C7JGXFrt8aEWTTRTScaMuUwaoI+BoynkH1uw==
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=ez0QUXAY;
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 CD439606A31A;
Sat, 31 Oct 2026 08:04:09 +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=ez0QUXAY
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.42
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793433849;
b=mCSBrjnru8F+4kr/JmAcaHPmwjN/Wc82rVn+Pg/m5dTPCm/Gw/Iz3ShC2x2g062YDfXh
ZmLQl7b+txhNgH8UMgt+TaunVL7zKCM8ktMPiQONECelkWqSSyaAn97efzL0vP+NqYm8j
qKi8flG3Pv/XosZvmzr80PiJ2uiYwyHnTkV3J/Jzvk4s5v+YWtGroYzfDG9BNh5yQ7OVV
JRqm21T8CPlY9bQbp7R/WasQs//SP2cfBFIx8cBWk9hjF/ZB+KetinMHwehjWXfapBzqL
HaijBDIOKPmaegS5TWcUt455IKdvZzEJmg4TRz1zsDrQxg5lrW8UDJHLvx7RAPd+HwQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793433849;
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=W3Lf7J7cS0JWq4lihEaDpQQyKgxvs533xxklAJLyVm4=;
b=zvTW30zVt7HzHE5C24atTlyz9nJdCP5PLuQxsTB6zhK7yc8YHb30Pr81svjFFScqv01F
Wv3xv1uiSx0b5QONKvgZk3BTlrt9/pwZwV4dWz+It4t3zcd+TGY+DSimn/AstZ2CNsMzo
n7/8V9zQBMYIiIR+WNyanhML//JLf5p8eJhmo4SxANSwg1KJCFmwgb54aHZyMpFgGoDnw
Urt3m6YotVdVP6oUCutcKw8OAtSuHaAbaKrtKAAhgKFwUAZ7Rbq8MJiIYXZmuqUH1XaFq
cAmukBYtrnG60e/OefncHJpvHkMJ3eLp+hlgE4nhg67IH24D4wpqByQ8h1LqreinyiA==
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=ez0QUXAY;
arc=none smtp.remote-ip=209.85.219.42
X-Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42])
(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 98F9E606A31F
for <git@vger.kernel.org>; Sat, 31 Oct 2026 08:04:08 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 98F9E606A31F
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-f42.google.com with SMTP id 6a1803df08f44-91c847584b8so20400946d6.0
for <git@vger.kernel.org>; Sat, 31 Oct 2026 01:04:08 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793433847; x=1794038647; 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=W3Lf7J7cS0JWq4lihEaDpQQyKgxvs533xxklAJLyVm4=;
b=ez0QUXAYGDNVHFq5w+tEgO0iupmxQkLkmJU9pKhP4IaOYTW8227wdzpjyHMqx5QeL0
WDZeuyfPXH6U6z+20r6Pi2c5SgQmjjFqvHwEMlxTAReLxly8GwBNcYEIkCP/lEUHEfYc
o988fwyni28wC90h9asdU75vpSBvyyK8CAindWDmSjQgSe54i2TIY0PM/W7crMhYMdCX
J1JSUBdT42JRA9eX3lePxJ/2AHOYumRhvEBbNN4saf+eSfx6T+tzpw89wrZqQ6iUmw8J
tk0Olm7FpEqyWcErraInGyCYZsJrNd0YDGx+gVaN3HRRwstw9ZQH/Q88WtRJDJdgocfv
cvng==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793433847; x=1794038647;
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=W3Lf7J7cS0JWq4lihEaDpQQyKgxvs533xxklAJLyVm4=;
b=YIaZW7evxiUtUQ0TN7RON/LLvGiwa0RDeD+XFfVgZ/SmEq9QghlJB6WXK5tWinmuQD
mg6n4YM9gHWQGU4CNW94hRBAP1ib+pfJWe5iyHHUPPlorjPWK0WfrIpN5atfyb5SACIo
nhP7inVtdArRh+3SiifASdgmA70/A7mSpodM4UKvJQQfFTlh7SriA0aTU07/GsZl6tg+
/VIECyMoilTsqgIkqQkQgfwW+8O/AHsphPYP2e1r741xWu4upEMKlXpFitW2m5XuY+BS
k7KQpK67d7Zia/B0x8DALQwOUjd3ZNWGVJ8i2gWD4FpETFNEonHgz3H7NvJ5Yn8d35xM
6rjg==
X-Gm-Message-State: AFq9FYIX4s0pXEeZzspjfYv7PcCeyZn4STBiq89IuoiIA4iWyEY1//Or
JUXh0FUVmd7xVaeHXTWReWxYq8DzEqB1kVoD6HcsjwQiJ6kumBdOTJAEBBnnv3LFsGs=
X-Gm-Gg: AYBFou00HdIgXHbHbcmFfYWTuSytUfEVvW945N2KM6m9SRzfiDs3xO91kuEYex0NR06
HPcrJL+cKpgxpqqlL2a9SNt56EUoZvQL9dE4SPKBaZ6cZyKhkV/Wufg3bK0TGll1dRH0oxGpMMw
va4S5JMoBnOHwW3ro7+K1LMEsw9KwDimupd+3rHaQRJoPOp9cbmoUR2b1rLOi5BSyvY3BRkMrW1
jsl6hb18/E7AdYDdkejrNstnZhKS4Rk3x6eH0/98qbNOY3csqn8EMG65UdUC2dcKHVHwixB1z5g
MziRZodK8UsDXdqMgS2wZ9Vx/hpiH2aQPKUi0xj+8YOPNbtCjalFGnj0wi1ncQQGtg1f9U5YyMw
rDlF7lu2C49WNUDXN2GM9lWI+jgNBfOAN713o1d51M01rpt4pIi9CA+YjdUIVmWOcfixCk34SyO
q2ftcnaLpyRjqF/R5FqTBhTo5QicN5q9WkBlzeoyDfXsyVWfNbKTna+UkLfUxCX+BT96DcDJXyi
NoVgCFqKga0bw7aizJfdv6q+99j4zBW14oIUeLKcB+yU+tlEHh3QmqfBoACOMtYRxJvIv8iGOnv
FAowoMx5TlxYbJYFPJC+Qkc5dK2mVjz++Q==
X-Received: by 2002:a05:6214:c46:b0:917:c04c:77b5 with SMTP id 6a1803df08f44-91c90409713mr134676136d6.3.1793433847523;
Sat, 31 Oct 2026 01:04:07 -0700 (PDT)
X-Received: from [127.0.0.1] ([20.127.239.240])
by smtp.gmail.com with ESMTPSA id 6a1803df08f44-91cb4478981sm6792236d6.35.2026.10.31.01.04.06
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 31 Oct 2026 01:04:06 -0700 (PDT)
X-In-Reply-To: <pull.2466.v2.git.git.1793433841.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: "D. Ben Knoble" <ben.knoble@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>