From patchwork Wed Feb 7 16:44:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13548733 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7439A81AD0 for ; Wed, 7 Feb 2024 16:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707324606; cv=none; b=gl3/oyAyzs3IgPRIDnPaU5mtpCvaa9NgzjPCOCWN52NAfj9V7gkgmgGHjOLhOARAZoGgc6YYO4LtTQaR1G+1NUJXDWvKbIlPQrycGsFcfdfDCDXNHs3Ki0qSrqVzlmp7rmuVuLGoUKr6NYjqw/ATBMaRxOkUyqdahIOzxvhxRo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707324606; c=relaxed/simple; bh=qgaCTcaCONfClr99VBhYoiILbaY6HRx47+FyShzOq4I=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Uw8LzIzOGMHwjmUVCIASY9Op1dmrVR7YxgRyj/4tU+mUpdyCK4mM4E6KfXagJgxANiVW/z/aJDgT8U5GVR3RzAvNnHlS2w2Da4GcBvV5H5wCCM8twAw9zg4EEhM8NjJAyoU+z/Bkv/7NWq2c0+LhYK6N/6tsspYDwjilFbxxbc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=APztVwO7; arc=none smtp.client-ip=209.85.208.43 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.b="APztVwO7" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-55a035669d5so1137266a12.2 for ; Wed, 07 Feb 2024 08:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707324601; x=1707929401; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=9cmSjmEwSf4IcLLAiT/MjedmxtuGZLWacEhH+jTj75w=; b=APztVwO7rxzlOkg3eNULtP/q8vO95Xf5+as0l9gj3/4sqckwFfl+viEMDMR1KnRcm4 FjiE8jkyl/qRMgyJqqiJOUwv02uqySP4txLM07wAYShG23qDVnG7HVhj3lUzCcwH70va 64cJG5tk8KE2Bqs0KiOOyjUkI9luowFXmmQaGGWwYODvGqnpxSfys3uD1M8py399NUhN wtU4N8MxHZF1hAX07qEZlOBndpRfC6DPy4KefU4oCgmBwrMnV+P0k/IDfAWUKFTx8bv3 kcp8hs8/nCmlL09sB/ohhkIP5MyqKBmL5PkuLMVV4qrA5e9IMNUtkE678EjF/BCwADKx pcKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707324601; x=1707929401; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9cmSjmEwSf4IcLLAiT/MjedmxtuGZLWacEhH+jTj75w=; b=eE3p9yIP4inQ4w5DXxpP/Ow32yuDApryq9Ptvo9LFNjGau0Z056in9jB3ZWVmXDAiL azuvmZEzvJU8fnCYVc83lFIehq8AScBH5pr7Th8FHOVWZSEHGOEkN1l1i8/Dqa2673hU gbVRaVdGAJL79utuCo5rtNg7wUZ/4+RiStwcTtxKXlea/nVJZLZPsfgPwvXpPVwHn5Wi +ZBV9JxiLxbK4rf8b4iga2CubjYuJlhsGfmOs6LhbLXftZRlWggVvMR9fGOzmiiMxLIo nLYyqYk+KRudi9nzdJAxFM/PxQCjH7OyjBBoo8SkKo6ZaWEIOK9+eUrDKpuxxFuNyOGM bmOQ== X-Gm-Message-State: AOJu0YzDDoNUEWur0qpNBc7bGmkvzGWZato+rHzAt0uo2ePiWFFeA72Y SNFCh/MEr+v/cfqoKi6ybfL978JKIB8AuRYgZCDjlXmB82HPu+XGi4y4n5kw X-Google-Smtp-Source: AGHT+IHm+F/VdMHnW8GHTsensPKAqArASEHtYJbXP6WwfMHt0bIoryHU2eyhwS+pbYcEUNsgchLIUA== X-Received: by 2002:a05:600c:4ecf:b0:40f:d25c:41d0 with SMTP id g15-20020a05600c4ecf00b0040fd25c41d0mr4997991wmq.29.1707324278711; Wed, 07 Feb 2024 08:44:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWaaDjnZiX7RpuzvyOLBNnPlIkzn4+whVyM5QYUV4/0vG/5dwH3GM/nIcDygfS1a1BZ30thTG1V6o90vGvYn8K40hRRX6IFRX5Qyg== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z17-20020a056000111100b0033b50344a97sm1410534wrw.7.2024.02.07.08.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:44:38 -0800 (PST) Message-ID: <4dedc5704c3af6ab4ec8cc7503dc826480775b8e.1707324277.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 07 Feb 2024 16:44:35 +0000 Subject: [PATCH 1/2] show-ref --verify: accept pseudorefs Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Phillip Wood , Phillip Wood From: Phillip Wood From: Phillip Wood "git show-ref --verify" is useful for scripts that want to look up a fully qualified refname without falling back to the DWIM rules used by "git rev-parse" rules when the ref does not exist. Currently it will only accept "HEAD" or a refname beginning with "refs/". Running git show-ref --verify CHERRY_PICK_HEAD will always result in fatal: 'CHERRY_PICK_HEAD' - not a valid ref even when CHERRY_PICK_HEAD exists. By calling refname_is_safe() instead of comparing the refname to "HEAD" we can accept all one-level refs that contain only uppercase ascii letters and underscores. Signed-off-by: Phillip Wood --- builtin/show-ref.c | 2 +- t/t1403-show-ref.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 79955c2856e..1c15421e600 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -172,7 +172,7 @@ static int cmd_show_ref__verify(const struct show_one_options *show_one_opts, while (*refs) { struct object_id oid; - if ((starts_with(*refs, "refs/") || !strcmp(*refs, "HEAD")) && + if ((starts_with(*refs, "refs/") || refname_is_safe(*refs)) && !read_ref(*refs, &oid)) { show_one(show_one_opts, *refs, &oid); } diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh index d0a8f7b121c..33fb7a38fff 100755 --- a/t/t1403-show-ref.sh +++ b/t/t1403-show-ref.sh @@ -174,6 +174,14 @@ test_expect_success 'show-ref --verify HEAD' ' test_must_be_empty actual ' +test_expect_success 'show-ref --verify pseudorefs' ' + git update-ref CHERRY_PICK_HEAD HEAD $ZERO_OID && + test_when_finished "git update-ref -d CHERRY_PICK_HEAD" && + git show-ref -s --verify HEAD >actual && + git show-ref -s --verify CHERRY_PICK_HEAD >expect && + test_cmp actual expect +' + test_expect_success 'show-ref --verify with dangling ref' ' sha1_file() { echo "$*" | sed "s#..#.git/objects/&/#" From patchwork Wed Feb 7 16:44:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13548734 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BB9F81ABA for ; Wed, 7 Feb 2024 16:51:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707324675; cv=none; b=YECJdDpL18Uule/kCXfwzgKc70r92glAX6CDLICokAqSN3I/l2YyVDTeoVl4ME8w51KPiYBCMZ7X+ZTMLkjJfHgJWfeY7/jjTNbQgwRy+uuI7Aa0urURPK9O4SuunGvcbS2ylJVJe/dHJ7x8AgAC5GWoY4DxOJ697XKedZes51s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707324675; c=relaxed/simple; bh=/MltqnnCkbZ9/7zF6FXwonkrB9mr/KU9njk+BG5JZ0I=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=IBJIqSIfdnricwP3MfTBcUo5zQ5YS05Q0p9R9UbzM//QiLfz2eUsI6FpGOtnfvM0rjODxMAz7dS74fttIkmd6GeQ+8qlBn/h0dbtePjuhKSzQOiu1VSV7+Xrdjfpc0OQVwWK6BAzCFS9b1z/4+LCqe1VT4v3VATAAKt1SE9DIuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HCqrguFn; arc=none smtp.client-ip=209.85.218.48 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.b="HCqrguFn" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a3916c1f9b0so1513566b.1 for ; Wed, 07 Feb 2024 08:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707324670; x=1707929470; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=DJM0XwCSR0s9gXTxQ2VsBsPLR5Gx5SnZJB+l0g+fPgQ=; b=HCqrguFn3KQ4rBjjc554tWZTT/xsuvR0U7CrPN1D29N/Y7HfV08OOSQCv//X5K2oE0 3jStbaKXzDcIjfZzIAVNlvVPk7hsJ98NE3wE7OIzIFPSPCYkAwsV75rIKodJ96q5Mqjn qYKRgY8hBjLululjIjGFf+1cnyFMeNkEuNKT45vMF653seaYLZ1JfGtUOWVL7a7q1F65 DIvKY/NYwrZ+GwqcfOvlY/XNYh3+fcnhWvuZTy7ld6prysvZjniz6lvNKSydEiDL7r+Y hZXYd/yQEVSmfcsgiv5TH+jHOJVOKN1NsmsDYQLKaGgm77WsagI6+jQkqmdq50lCVyuK VzFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707324670; x=1707929470; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DJM0XwCSR0s9gXTxQ2VsBsPLR5Gx5SnZJB+l0g+fPgQ=; b=qUjo8ldhYT4WqdEUJQGYgaSNXIoFn9+Ul/p2FdEy6uJ3c9c9zIqyDFyzJI+rT4vMO1 vCVdY7MJsT7UX8etJjKeR6Dqt9zG/hDVNnD9m9jksTGfxmf0x9KPhteRtgRltQ1pF3eq 2VFdn+4CrMoLQ0G9K7XzLRAqHznV3EnFx2mkns0NnJxLE4/3CQWLU70SbxldRekwm0v6 ZKjUlBxoaf1TZ04wU0YzzWzT1HCPZ9zkC1um/hzgPG3k2bLtAD2ovKpOmXMFmg/mn5WQ 8IoT1ro4BFh1GtTD0DmNvRab2J/DBko8XWjlKvkztK76phlAr0+2ow3Fe2GdGvN273SJ FDwQ== X-Gm-Message-State: AOJu0YzedA4nIcOse7O/kFoiK4AD7L0LkIpfilRlF6Lr9gMK/e9WHA3K 2u0ZSzfPxfGJDLQoMX8gNsaJLtIL+QwVwlRXB5tK8hV+qcJWk+8kGRRnxvS6 X-Google-Smtp-Source: AGHT+IEAq0WhdepgQjm8z9nC2tXniwEOJIppZrhWb018XJ3RS5D97zWzAzNNHELTHRWLDO500Mc0vQ== X-Received: by 2002:a05:600c:3512:b0:40f:ddbb:73ae with SMTP id h18-20020a05600c351200b0040fddbb73aemr5179892wmq.27.1707324279498; Wed, 07 Feb 2024 08:44:39 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXNEvgyuTmUn8Cj0sqoH5wJrRj7we52N8MvuDRnTxJ0+Io7RRIcFwCrJTV3+I8maDpMtiU+0zECy0rDztNpQjIts9e7N91XwZUqbw== Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m37-20020a05600c3b2500b0040ec66021a7sm2608061wms.1.2024.02.07.08.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:44:39 -0800 (PST) Message-ID: In-Reply-To: References: Date: Wed, 07 Feb 2024 16:44:36 +0000 Subject: [PATCH 2/2] t1400: use show-ref to check pseudorefs Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Phillip Wood , Phillip Wood From: Phillip Wood From: Phillip Wood Now that "git show-ref --verify" accepts pseudorefs use that in preference to "git rev-parse" when checking pseudorefs as we do when checking branches etc. Signed-off-by: Phillip Wood --- t/t1400-update-ref.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index f18843bf7aa..78a09abc35e 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -524,51 +524,51 @@ test_expect_success 'given old value for missing pseudoref, do not create' ' test_expect_success 'create pseudoref' ' git update-ref PSEUDOREF $A && - test $A = $(git rev-parse PSEUDOREF) + test $A = $(git show-ref -s --verify PSEUDOREF) ' test_expect_success 'overwrite pseudoref with no old value given' ' git update-ref PSEUDOREF $B && - test $B = $(git rev-parse PSEUDOREF) + test $B = $(git show-ref -s --verify PSEUDOREF) ' test_expect_success 'overwrite pseudoref with correct old value' ' git update-ref PSEUDOREF $C $B && - test $C = $(git rev-parse PSEUDOREF) + test $C = $(git show-ref -s --verify PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && - test $C = $(git rev-parse PSEUDOREF) && + test $C = $(git show-ref -s --verify PSEUDOREF) && test_grep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref' ' git update-ref -d PSEUDOREF && - test_must_fail git rev-parse PSEUDOREF + test_must_fail git show-ref -s --verify PSEUDOREF ' test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && - test $A = $(git rev-parse PSEUDOREF) && + test $A = $(git show-ref -s --verify PSEUDOREF) && test_grep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref with correct old value' ' git update-ref -d PSEUDOREF $A && - test_must_fail git rev-parse PSEUDOREF + test_must_fail git show-ref -s --verify PSEUDOREF ' test_expect_success 'create pseudoref with old OID zero' ' git update-ref PSEUDOREF $A $Z && - test $A = $(git rev-parse PSEUDOREF) + test $A = $(git show-ref -s --verify PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with old OID zero' ' test_when_finished git update-ref -d PSEUDOREF && test_must_fail git update-ref PSEUDOREF $B $Z 2>err && - test $A = $(git rev-parse PSEUDOREF) && + test $A = $(git show-ref -s --verify PSEUDOREF) && test_grep "already exists" err '