From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9367E30E828 for ; Sun, 30 Aug 2026 20:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788122922; cv=none; b=laDOlaWIqAS6qHRxdfJtc0YBLrwEdX5VuW66ynRyTWVUnYt3ulcIMJzqKwLVzoVONkiL95lre4MytuY8yaPewG9al44bsrX2YEDZz+UH9uamI6VgOKkH/VnEaOH8UcNN3gidhVNwt0/bvtLfL9uwmdhd0Q/6UbQKU6f/JmUgjkc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788122922; c=relaxed/simple; bh=9fOKEHxvcqyNDycSbcgN3L2rWfrP1sLM7oH8o5T7VUs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rxsI9++ERgfHQOQox5krt8ARe/PgkYD38QfPRoU0wN/q/xgz7J0FfgJ4jcoro1VGJii2ZA/f+QzHjgJ2AV2ZBWNL5bJFWpfAdELAC10WWzwraiswvwfmDLJZNuZjwVvlXmj7g7fdixMsFtNIqjCDEf9rZg0R5c7TjTFsZiiuVyI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=m/TUV3Rj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mPZGA5y5; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="m/TUV3Rj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mPZGA5y5" Received: from phl-compute-09.internal (phl-compute-09.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id DA92EEC0141; Sun, 30 Aug 2026 16:48:39 -0400 (EDT) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-09.internal (MEProxy); Sun, 30 Aug 2026 16:48:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1788122919; x= 1788209319; bh=w1YCSaBiXuZlIv8ea7IHcfxCBrqtDESa/nCwyGAe5SA=; b=m /TUV3RjIWaP7AP08NaDm6YlRtsYmPgESqgRh/if+PWRd6TEEmmu9CkvlUIe2NIkP QhmviNHTAYR041/o3iPGreUoOenw9QRCKEFgCMHUN6ZlRK3kziqi5EeKWPdkTyTq A2/BSEvyXuYmkWh1WEWFoyUK28iLJAn0Xhn/dFd2ySTl1ia1u/EfAA3/4fvJT2TX o9V3jyvFKxh7seK/Tuat5NtZC2uDF6DiebH8nnif6uQTw/kU4gOHz+Iq8Y1hqho7 EzmEJA1BqITGYSNcyfLQ7/g3RPuP4nhHpOPAFGH5kLyBFJQzknviflrGBtO+9rjZ 5sZA7f517lztQcl5uC7vw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1788122919; x=1788209319; bh=w1YCSaBiXuZlIv8ea7IH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UUZRjg8nw X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 30 Aug 2026 16:48:39 -0400 (EDT) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 2/8] checkout: validate new branch name in checkout_branch() Date: Sun, 30 Aug 2026 13:48:29 -0700 Message-ID: <20260830204835.1040408-3-gitster@pobox.com> X-Mailer: git-send-email 2.55.0-884-g76cf8659c2 In-Reply-To: <20260830204835.1040408-1-gitster@pobox.com> References: <20260828225206.310500-1-gitster@pobox.com> <20260830204835.1040408-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In checkout_main(), new branch name validation is performed before dispatching to checkout_branch() or checkout_paths(). Checking out paths does not create new branches, so this validation only belongs in checkout_branch(). Move the validate_branchname() and validate_new_branchname() calls from checkout_main() into checkout_branch(). checkout_paths() checks and fails if '.new_branch' is set before doing anything, which indicates that this change is safe and makes good sense. Signed-off-by: Junio C Hamano --- builtin/checkout.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 774e4fd5b3..14542626e9 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1734,6 +1734,17 @@ static int checkout_branch(struct checkout_opts *opts, free(full_ref); } + if (opts->new_branch) { + struct strbuf buf = STRBUF_INIT; + + if (opts->new_branch_force) + opts->branch_exists = validate_branchname(opts->new_branch, &buf); + else + opts->branch_exists = + validate_new_branchname(opts->new_branch, &buf, 0); + strbuf_release(&buf); + } + if (!new_branch_info->commit && opts->new_branch) { struct object_id rev; int flag; @@ -2062,17 +2073,6 @@ static int checkout_main(int argc, const char **argv, const char *prefix, die(_("you must specify path(s) to restore")); } - if (opts->new_branch) { - struct strbuf buf = STRBUF_INIT; - - if (opts->new_branch_force) - opts->branch_exists = validate_branchname(opts->new_branch, &buf); - else - opts->branch_exists = - validate_new_branchname(opts->new_branch, &buf, 0); - strbuf_release(&buf); - } - if (opts->patch_mode || opts->pathspec.nr) ret = checkout_paths(opts, &new_branch_info); else -- 2.55.0-884-g76cf8659c2