🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #855

[PATCH] branch: strip refs/heads/ from the --set-upstream-to hint

#855
From: "tsukasa-ino via GitGitGadget"
Date: Tue, 20 Oct 2026 01:15
89 lines
13843 bytes
From: tsukasa inoue <inoue.tsukasa.4@gmail.com>

When git switch fails to write the tracking config, it prints a hint
with the command to set the upstream by hand. For example, if
.git/config.lock exists:

    error: could not lock config file .git/config: File exists
    error: unable to write upstream branch configuration
    hint:
    hint: After fixing the error cause you may try to fix up
    hint: the remote tracking information by invoking:
    hint:   git branch --set-upstream-to=origin/refs/heads/feat

The hint says origin/refs/heads/feat, but the correct name is
origin/feat. Running the command as printed fails, because the full
ref name is not a valid remote-tracking branch name here.

This has been wrong since a3f40ec4b0 (branch: accept multiple upstream
branches for tracking, 2021-12-20).

Strip refs/heads/ from the hint, as the success message in the same
function already does. The git config --add line for multiple upstreams
still needs the full ref name, so it is not changed.

Signed-off-by: tsukasa inoue <inoue.tsukasa.4@gmail.com>
---
    branch: strip refs/heads/ from the --set-upstream-to hint

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2268%2FtsukasaI%2Ffix%2Fbranch-upstream-hint-shortname-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2268/tsukasaI/fix/branch-upstream-hint-shortname-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2268

 branch.c          |  8 +++++---
 t/t3200-branch.sh | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/branch.c b/branch.c
index 22f4f46b96..bb07846911 100644
--- a/branch.c
+++ b/branch.c
@@ -186,12 +186,14 @@ out_err:
 
 	advise(_("\nAfter fixing the error cause you may try to fix up\n"
 		"the remote tracking information by invoking:"));
-	if (remotes->nr == 1)
+	if (remotes->nr == 1) {
+		shortname = remotes->items[0].string;
+		skip_prefix(shortname, "refs/heads/", &shortname);
 		advise("  git branch --set-upstream-to=%s%s%s",
 			origin ? origin : "",
 			origin ? "/" : "",
-			remotes->items[0].string);
-	else {
+			shortname);
+	} else {
 		advise("  git config --add branch.\"%s\".remote %s",
 			local, origin ? origin : ".");
 		for_each_string_list_item(item, remotes)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index cdb6c6a634..ce478d85cb 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1080,6 +1080,21 @@ test_expect_success '--set-upstream-to fails on locked config' '
 	test_grep "could not lock config file .git/config" err
 '
 
+test_expect_success '--set-upstream-to hint uses short remote-tracking branch name on locked config' '
+	test_when_finished "git branch -D hint-local" &&
+	test_when_finished "git update-ref -d refs/remotes/hintremote/hintbranch" &&
+	test_config remote.hintremote.url . &&
+	test_config remote.hintremote.fetch "+refs/heads/*:refs/remotes/hintremote/*" &&
+	git update-ref refs/remotes/hintremote/hintbranch HEAD &&
+	git branch hint-local &&
+	test_when_finished "rm -f .git/config.lock" &&
+	>.git/config.lock &&
+	test_must_fail git -c core.configLockTimeout=0 \
+		branch --set-upstream-to=hintremote/hintbranch hint-local 2>err &&
+	test_grep "git branch --set-upstream-to=hintremote/hintbranch\$" err &&
+	test_grep ! "refs/heads/" err
+'
+
 test_expect_success 'use --set-upstream-to modify HEAD' '
 	test_config branch.main.remote foo &&
 	test_config branch.main.merge foo &&

base-commit: a018953688f1b10bddf91bff8747068f5f4746a4
-- 
gitgitgadget
Technical Details
Message-ID: <pull.2268.git.1792458904027.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-72474-linux-kernel-git=dewy.ru

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-72474-linux-kernel-git=dewy.ru
From: gitgitgadget@gmail.com ("tsukasa-ino via GitGitGadget")
Newsgroups: linux.kernel.git
Subject: [PATCH] branch: strip refs/heads/ from the --set-upstream-to hint
Date: Tue, 20 Oct 2026 01:15:04 +0000
Organization: Usenet Network
Message-ID: <pull.2268.git.1792458904027.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3755739"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:v7RiXL9tzSdBWCuwxJN7hL5iWmE= sha256:n1D0suijKSOD6XLFf9M42KwU2SrkJ4uMhiSlb9K+9zQ=
	sha1:chZuXF+HDFDBE5z0S9w5p3hWS8A= sha256:iw8/QypiZwqpFKTED95J60kWDom/uE9md8bwsepyxak=
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 DBCA3110BA7; Tue, 20 Oct 2026 04:16:01 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: 0.51
X-Spam-Status: No, score=0.51 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, RCVD_IN_SBL_CSS=3.558,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=no 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 QQ4Vp8XKH7BK;
	Tue, 20 Oct 2026 04:15:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72474-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 7452C110BA4; Tue, 20 Oct 2026 04:15:50 +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 E9DE929B18; Tue, 20 Oct 2026 01:15:09 +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=1792458909;
	b=jALGIrk2h07X8MGimLco4fSm17G02CZHLkXRr/Ke6I2aFTm18rqqV3/H+Tv+TXtCt7M/
	 ISfCRqhNHmjo8mUGprdOCPvXIo/5Ehs4eJWzzX+9QzpFVDSMBGN/5fgzb4n3vi2nTBwcm
	 HnUhNWa5ZLr2xmwU06uwQkpMfnDBNb0uA/8iEc79aM/wI3pBWwiuasG50ohNS8yPkWc3Y
	 2ySg2LbDeLtSC9Xkhxs0f5+bEgpp5fHOTGPWa59xJf7XqLHkFSQxm/jXg1KDphXeho+Iw
	 6+t5hz8OfIuuJwhwTj2Y+yBkkXtd0EMk0/7SRpnGwJ8xtcbo+azF+Nn8H5oET8vKISA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792458909;
	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: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=ozyBrXK2ZWzjGttmA5hDsJ+vFAm136TmVFPcrxuOzqo=;
	b=mPQZT0K4hhryy/F9QiXzZcb3lwkwkZ++uIZbKerOlrs5noAAUff15UFSnu1zOXqURWO8
	 voupRqPQwh5GFdQaa/05qph6BNS8KSo11ALVWigkHMBq5C03jgYUCKvapnj9Uog/RzpQT
	 CNYfuDzVjxFu30KVEcNNwZI5a2m6z21lCkbJUEFwgfHaRwftwmBbQCzUEG4mfflFRXYp0
	 Y2qdNAxZBN27qtpZQyTEM/J9iH0D+wH0+DGcN3Fudg9WrFCQyaW1TQg7jYdN+cyD/cMMb
	 33dm+wIAEsud0FePB8olPedU3RZJ9QRhAli1HL2Tn8imLEUwWAeZqAbIpF/9/Hq38AQ==
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=bHvFJxaI;
	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 C171C606A322;
	Tue, 20 Oct 2026 01:15: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=20251104 header.b=bHvFJxaI
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.46
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792458908;
	b=0E+mljOrH5VTEwTI6Ou4VQyO7lH72d5kALHVWOiW6gA2ivxEPt29FQ2mElILoDNxcOsJ
	 o9GjLbz8p3vlI5kew13t8Nz4kpQg3oAhbNEBsadq/+zPhCXmRhJ65YbnH6pKXMaKY1HOi
	 RWY3+wPIiZ1Gm4ej64gHHsCYqWcDJiuB46q2eMwhPtmHwMGDKd6cvk0snehHhEuV5BV42
	 Qqyvk0ychYh0EmDp32TwYaAccmIJlbwUelFZrQWjeXr7j/VRvL7e1+s+Hp8zIDQSFBRXM
	 EJWxWJft6Cl1DLeCBR0IKRV1AVd9QJxEeo3qVoX8UvEv3seCVWM+i37qgKwcFCW5SnA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792458908;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:From:Date:
	 Subject:Fcc:Content-Type:Content-Transfer-Encoding:MIME-Version:To:
	 Cc;
	bh=ozyBrXK2ZWzjGttmA5hDsJ+vFAm136TmVFPcrxuOzqo=;
	b=1Q+CvBklznkb2F/VmXHScOQpJoITbRKRoLuwlF923Dqrw9SYB5aO9t1riylgaJ3ADqt+
	 NstQo2uxr6AAS1mM5DfL6/IIPrBeX0t36QJ0HjuUNygJy8Tiy/+bII7k3ym5c46nvEWgu
	 vHp00J8W4hZezkuH2TT7Y1jEOCDIBEcSrF1lBLCne4WqEB0M8pMB36wxq+bUxwd/TQ5gn
	 AJTNiCsFuvgwAcr/52dw/A9aFwyNcpOHSNj3qS8NZqb0Ir6Ab5FlMvieWqNLcwZ615gFr
	 itl4d69B5jzfhKnkGPR72p3BEXZCxELBBJiWsd8LIzQIlNo2PLzV34qt9lV+GcWFNMQ==
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=bHvFJxaI;
	arc=none smtp.remote-ip=209.85.160.46
X-Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46])
	(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 83254606A31B
	for <git@vger.kernel.org>; Tue, 20 Oct 2026 01:15:08 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 83254606A31B
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-oa1-f46.google.com with SMTP id 586e51a60fabf-49e08af5fd4so1132717fac.1
        for <git@vger.kernel.org>; Mon, 19 Oct 2026 18:15:08 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792458907; x=1793063707; darn=vger.kernel.org;
        h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
         :subject:date:from:message-id:from:to:cc:subject:date:message-id
         :reply-to:content-type;
        bh=ozyBrXK2ZWzjGttmA5hDsJ+vFAm136TmVFPcrxuOzqo=;
        b=bHvFJxaIbpSLmh/15Zr5kePYnQAjUHNhN2mRxlJiQteGWJtIZbR6K6Kr36KtgJqEvE
         9Y9AsZTmsnd4zh2Ct67L1WHbGkat3h3klt4GR9CTMCuAaJuX77Z5PkRQUnaZK5DTOJ7k
         IrWVjXvwnP7whdZOEBFOQ5g5tltDS6fcT4JbkhQ1fHv/Waie/wOhESo2TK1KukN5bHlI
         RWlUsmxBU0vXWorOZYcXKLTE5YyvSCfnpdCLXJ5nR7i77Az4cGDrF0D4ab7gFkIlfICG
         88YKSWu6sxdZa4cxFYJAVgYTRe/9LFzvspaf0Dio0XrJa9MQmoOBdpIyhr+gLIhqjbOx
         BIGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792458907; x=1793063707;
        h=cc:to:mime-version:content-transfer-encoding:content-type:fcc
         :subject:date:from:message-id:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=ozyBrXK2ZWzjGttmA5hDsJ+vFAm136TmVFPcrxuOzqo=;
        b=W0U1zjRh3Hy8QwWZsrocYPoc4ToBfmjctIiEO3j1Rf/LmQ3H7+NibNmrsuxgRFJiCz
         dWEzJwUJOx63y+nMLCAF37zusfjZrWltWoYHRQJMPQX1GWewqfR1NGYQSKJZHfJk9gx4
         OOM+H8QxDyVsUkPWxjBIIghdAwxoLg11LWOfYNsbt9brV/CyOW60T6fHri68di/NTpO2
         DcTD3mY3YY8U6lTeqGZOxqD0LDtM+0hsQEDstnKiGpbDRIERKADrIfsW2/UBxLr2kd3q
         23QGxFUK7TomAoXQG9K+HPlmqd7sZS+XyxIJ4NKTs5uEh/eeubFC25vZ0bwdvXt0fc9t
         xglA==
X-Gm-Message-State: AFq9FYJr5j0L0JAMhB3Bp0tSdMY4NkdIqT/SBaBwm0DDJ53Ujoam5eXM
	S/gDvCJUZZjqEc8CBtsLBpgHovDtBNyxvgOl32A6P8s1EKL4TECsrqq5bl+pk9xF
X-Gm-Gg: AYBFou2MaAOQfFGUUMXfKZNA57MksWBHMAqptXpgM588MBR8QQ/1KtRCE7dDhvU6EzT
	Gl+leb7X+WU4vo8l4ssrvVV9YBb4y3rNUNFrTa4jD5x8s7jY3LwlW/sewVkdhu8H2RUAJmszIDL
	9q5AZ0LesLBl74R18u2Xnk3gByC5BGT8AXbgOeo7j4etHO9qDomIlQ0GcbFeew1S4TT+v1IXOGp
	nXZemBctLXp/CljVdYj2JZu9vXUyEc52poUDL1GFnle2INwP06IriMlxGT++f02JN2lLYqD9Zco
	grFcwQJoEaVCMI7ZL3K8LOAzKD9Kj4gQF4bs2V2fsK+Un+br22oW3VyPriGycZjwS+j8AFh1nbG
	czsua5PzD8SCZa9U0Rfk8yZQ0ZokJpH6ONAWbkJq/hZ1d1MhlmsdSLfJqQ6VEWMLiK0/Xd7eEQY
	7eWN0CCgIx4xYUBtJ2mr3y5PLT3Ci3ix1O0rMRJm8zqaMKrRVa5Ky6EhpqADTsswF77Gm2KLbd8
	wHw
X-Received: by 2002:a05:6870:96a9:b0:4a7:4324:1807 with SMTP id 586e51a60fabf-4a757897322mr8095798fac.12.1792458907073;
        Mon, 19 Oct 2026 18:15:07 -0700 (PDT)
X-Received: from [127.0.0.1] ([172.212.206.123])
        by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4a73b5b4278sm9040382fac.6.2026.10.19.18.15.04
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 19 Oct 2026 18:15:06 -0700 (PDT)
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: tsukasa-ino <inoue.tsukasa.4@gmail.com>,
    tsukasa inoue <inoue.tsukasa.4@gmail.com>