From patchwork Mon Feb 27 01:57:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 13152596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ADABC6FA8E for ; Mon, 27 Feb 2023 01:57:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229641AbjB0B5J (ORCPT ); Sun, 26 Feb 2023 20:57:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjB0B5H (ORCPT ); Sun, 26 Feb 2023 20:57:07 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F58C12F1B for ; Sun, 26 Feb 2023 17:57:06 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id bt28so4624859wrb.8 for ; Sun, 26 Feb 2023 17:57:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Qysv65G1RU+ff6CVcJ5vqaT1N+Mc2CX4rV7gRf1A/bA=; b=IBsn36qWPa5pgv1rcz00SQ7GpCxwMJ7R+zKEWhvc8aDa7vCWhueDaPRb37jJli0RGw BJduWpuWx73AoS4ntAijBBbS62RYYPHTU4aaH0siBP09U9SyzOJajjXS3O6QdflGtH0K 9RijwOrcjH5fsMmzuizQEEWyH2F6gHgtLCb6pu2YO5LDxGu35a3uAAGj5Ypp1OQPnmgD bfOs8Ewn9a1TYskcbj8o3UZFWCAWgMVwEfBpcTj4Ay8gcoyMRRiJFYeUJ90abFV1J+ra /CHIQqgOr4xUqUKHTm4qGYaGLNPb6TkJWXT8Nx6z2Pql2QDhDTCranrTupT55hYoRvYA ceRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Qysv65G1RU+ff6CVcJ5vqaT1N+Mc2CX4rV7gRf1A/bA=; b=Gx3MQVqa7EyFAkPHzKmOUBgP4TnjN+rSbl0nRJ609kpwHTZT7RpA6N9VLBFqTrvHuX 69Q6/62e9QotU1/1CfzLs/iqVAe0yD2pGqxja+gy/JiTRK+nxQm9fhRkGW44lQcxbkZl BWmqeiPNA9006wmLtZByU0tZaRQe5pWKDPzCIXhclqoK7ncowx7IkQYrJ7J3wa7TLWsX eZpgjwhSgBLWfsr8bdBz8CcGmdd80b5JR1HtA0s9dPBsb14ud2FW4yOaYaB+8BO2W+Jz tDP5xUazFX/mT0fmCBFu8yUAgQQigje4BAASCt/uVCfGPmKxKMKZIWNW6dq/gXYQE4H5 pLmw== X-Gm-Message-State: AO0yUKWRbgDAQivHY1wbxy6JolcJ/MaBzXyWr++mio4ke7jQ5M2q5ymY H0kmCAY7POIq7cM8hSy3Kd1T40Tkw9Q= X-Google-Smtp-Source: AK7set+D9XNch8JJ/iY/DGY9bX4PIwLbMEbdLa/yP5jKPMZN6oSYsDbOHgfYQakquQDUI1Zxnahz2w== X-Received: by 2002:adf:ec11:0:b0:2c5:98f2:5b16 with SMTP id x17-20020adfec11000000b002c598f25b16mr19205844wrn.1.1677463024628; Sun, 26 Feb 2023 17:57:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m7-20020adfe947000000b002c70f5627d5sm5579943wrn.63.2023.02.26.17.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Feb 2023 17:57:04 -0800 (PST) Message-Id: <857d2435caf6211cd5a1baa6c9d77311ce7ba745.1677463022.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 27 Feb 2023 01:57:01 +0000 Subject: [PATCH v3 1/2] receive-pack: fix funny ref error messsage Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Junio C Hamano , Derrick Stolee , Elijah Newren , Michael Haggerty , Christian Couder , Jeff King , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu When the user deletes the remote one level branch through "git push origin -d refs/foo", remote will return an error: "refusing to create funny ref 'refs/foo' remotely", here we are not creating "refs/foo" instead wants to delete it, so a better error description here would be: "refusing to update funny ref 'refs/foo' remotely". Signed-off-by: ZheNing Hu --- builtin/receive-pack.c | 2 +- t/t5516-fetch-push.sh | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index cd5c7a28eff..c24616a3ac6 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1464,7 +1464,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) /* only refs/... are allowed */ if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) { - rp_error("refusing to create funny ref '%s' remotely", name); + rp_error("refusing to update funny ref '%s' remotely", name); ret = "funny refname"; goto out; } diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 98a27a2948b..f37861efc40 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -401,6 +401,11 @@ test_expect_success 'push with ambiguity' ' ' +test_expect_success 'push with onelevel ref' ' + mk_test testrepo heads/main && + test_must_fail git push testrepo HEAD:refs/onelevel +' + test_expect_success 'push with colon-less refspec (1)' ' mk_test testrepo heads/frotz tags/frotz && From patchwork Mon Feb 27 01:57:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 13152598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B8F5C6FA8E for ; Mon, 27 Feb 2023 01:57:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbjB0B5L (ORCPT ); Sun, 26 Feb 2023 20:57:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjB0B5I (ORCPT ); Sun, 26 Feb 2023 20:57:08 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D09A12F27 for ; Sun, 26 Feb 2023 17:57:07 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id r18so4653058wrx.1 for ; Sun, 26 Feb 2023 17:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=W9L9pfIRzS+uzJcyvd+DJCigPa9CEPnO6eLIcRHuPYY=; b=PiinkxdqOb/4H4XHyI3ufTzuK2PeyMQk6LnX9yUUm//1M5Ndpj7g26kY2foAZvI31S K121VffvMeB6eUDN9QbSOGNBWoZxnpSrD/WNtLfPZLDJ3paufzCViBOvOpl0MKt7u3Uj dJwjp5rASZ7vggnzJ283DL0M+5UfQ5kTSANwifKfL3YDRAHbfUXndYq9yRHvdPg2MSVO FOHx2kTUyVYkT7zGmvSocV2ZDJbF/eBqnki3YjuiYhQK6sHFjsaOPVB1Wvz8uCGQkGxF NFbuWULK+LSvqw0oxwQvJ2ALpuokf4xc1mnVlGmTg8M85/H37MfTTDRO/W6trxvMP2pK aJog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=W9L9pfIRzS+uzJcyvd+DJCigPa9CEPnO6eLIcRHuPYY=; b=rczJb/LpMnaRzhBSB2H5QGrumFPE08ydMLwOd1Mfv03N1Uge91J/2+WUVPnuhokPM6 1R8RqdJUrTPJdJ4Yb+fP0oQR+/qRnnXgdWLcoHwQxsjRtmwkwGWDILzzX6jNUxWEJf1j QiiEEgLONTtVi07pUY9YVRWmjKx1YUD+3NyVI8pMm0U9ppYbesU1gPGsUV7+lNWmBX+f dF5LtUSGuFkdlWa7hl3rC+khTHXYoYWt7ETfAsgftrEtTZqHQp1i7tFko5/Tr0Yq8NYT tIaK6JjzZ3o9roedkp4qFuNqjhAyhYFucH+AW2DOcQ8KjiThCyPsS9cVGGvzJUa7onQF mxOQ== X-Gm-Message-State: AO0yUKUjV/2ogJFuujH2VGqOE2VcUf52En/f6mEbdVzPZX3efVstq1Oi GUSe2UGGdXWb+EG3nJFXsQZASWIiWiU= X-Google-Smtp-Source: AK7set9X+UL+jA/RUPzcAQ2LAt5VbVc2fndXAyVptje0pcizqErODOK81C5H+bSZ8I22wsaK8hp/mA== X-Received: by 2002:a5d:42cc:0:b0:2c7:aed:b97b with SMTP id t12-20020a5d42cc000000b002c70aedb97bmr12689482wrr.62.1677463025511; Sun, 26 Feb 2023 17:57:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y2-20020a1c4b02000000b003e203681b26sm7204410wma.29.2023.02.26.17.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Feb 2023 17:57:05 -0800 (PST) Message-Id: <4dc75f5b9614477bf8b729af5d456e1a5531f6ac.1677463022.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 27 Feb 2023 01:57:02 +0000 Subject: [PATCH v3 2/2] [RFC] push: allow delete single-level ref Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Junio C Hamano , Derrick Stolee , Elijah Newren , Michael Haggerty , Christian Couder , Jeff King , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu We discourage the creation/update of single-level refs because some upper-layer applications only work in specified reference namespaces, such as "refs/heads/*" or "refs/tags/*", these single-level refnames may not be recognized. However, we still hope users can delete them which have been created by mistake. Therefore, when updating branches on the server with "git receive-pack", by checking whether it is a branch deletion operation, it will determine whether to allow the update of a single-level refs. This avoids creating/updating such single-level refs, but allows them to be deleted. On the client side, "git push" also does not properly fill in the old-oid of single-level refs, which causes the server-side "git receive-pack" to think that the ref's old-oid has changed when deleting single-level refs, this causes the push to be rejected. So the solution is to fix the client to be able to delete single-level refs by properly filling old-oid. Signed-off-by: ZheNing Hu --- builtin/receive-pack.c | 4 +++- connect.c | 3 ++- t/t5516-fetch-push.sh | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index c24616a3ac6..af61725a388 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1463,7 +1463,9 @@ static const char *update(struct command *cmd, struct shallow_info *si) find_shared_symref(worktrees, "HEAD", name); /* only refs/... are allowed */ - if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) { + if (!starts_with(name, "refs/") || + check_refname_format(name + 5, is_null_oid(new_oid) ? + REFNAME_ALLOW_ONELEVEL : 0)) { rp_error("refusing to update funny ref '%s' remotely", name); ret = "funny refname"; goto out; diff --git a/connect.c b/connect.c index 63e59641c0d..7a396ad72e9 100644 --- a/connect.c +++ b/connect.c @@ -30,7 +30,8 @@ static int check_ref(const char *name, unsigned int flags) return 0; /* REF_NORMAL means that we don't want the magic fake tag refs */ - if ((flags & REF_NORMAL) && check_refname_format(name, 0)) + if ((flags & REF_NORMAL) && check_refname_format(name, + REFNAME_ALLOW_ONELEVEL)) return 0; /* REF_HEADS means that we want regular branch heads */ diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index f37861efc40..19ebefa5ace 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -903,6 +903,13 @@ test_expect_success 'push --delete refuses empty string' ' test_must_fail git push testrepo --delete "" ' +test_expect_success 'push --delete onelevel refspecs' ' + mk_test testrepo heads/main && + git -C testrepo update-ref refs/onelevel refs/heads/main && + git push testrepo --delete refs/onelevel && + test_must_fail git -C testrepo rev-parse --verify refs/onelevel +' + test_expect_success 'warn on push to HEAD of non-bare repository' ' mk_test testrepo heads/main && (