From patchwork Wed Mar 1 10:20:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 13155807 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 CAA70C64ED6 for ; Wed, 1 Mar 2023 10:20:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229568AbjCAKUg (ORCPT ); Wed, 1 Mar 2023 05:20:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjCAKUe (ORCPT ); Wed, 1 Mar 2023 05:20:34 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59DD1199D1 for ; Wed, 1 Mar 2023 02:20:33 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id j2so12638529wrh.9 for ; Wed, 01 Mar 2023 02:20:33 -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=4N8cOaOsyFzLmyRhD0NMlgD3QIcbgjdgzAcYJbr6p+Q=; b=RbQXZZWVW7mFrA2Z+kbVS3cwLwuBZnNK67f8iyEvp5MEqtQJkFyv1MhsnYkIDnmc2/ LXX278ht6Z+JLaBkXoiMt7eR1eLWXqHNeqDU+x+w7q9Cu5zmopKwK7tP/LlawNHM9vql 4ATVzNff/7lAf4pxpdhUC6RUSU0+sS8IMmN9icvmVHzaSmYQRIJ8WmSS8HQ/HBeCtblj q1GAhcIqRSbYGaYO83EkSfEBzRNTl9801oeBEarOdhxqHtC6QlsOpA4ogO3dM4m7c4nT NFrdUEMDJaz7ZbcN20Wf2Khi1B0O2K2p3Yk6ZETZEt3gc7cCSXCMwgolGhkLxdL5GIqJ bpew== 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=4N8cOaOsyFzLmyRhD0NMlgD3QIcbgjdgzAcYJbr6p+Q=; b=ik9N/EBGdwnARw0uDZebuc3MuQbX0njn4kWdJbThGJmKLcVcNbTf2aKBl+0I8ZOR5Z gepXfTEnCfU8ToiA2UawmK03YGxYR9+HJN6RUJvtRSH8vowYbG2LbmpG76JMujNPBIZ9 rZsc7wc0MNXk4RybQ89kJBJ1Wl7RxINTKpNU/XrVANKg4ILfdBSdqjDkmSevoDAw9xDN 4ahDYRdh9jOWIR2UTogVFZkkHeiPsMSSpgeFVzmFJGvSk5nEIUTaK4ZO/Cq65E4GiE/G 1HshGKEjzlKXJn0HWlneK311il7Yq64MSv1Vm3r3b2jlk24V+L34JSe3mjme9BuBv0Co OHGA== X-Gm-Message-State: AO0yUKVn942qv1NwF2tBc1wDYd6dCSREvHglXkW7rBKmbQvGFS8C1Y0N RbE1FUwfhLHgljYSmVwF6UwvJ0st5p8= X-Google-Smtp-Source: AK7set9QHIWq2oMB88yc5ITp7Xv4NJdSWYPbnHFzIWyuzRqf2K+zh5CTkC2dHRqTV+MgNVkOiJ7yBQ== X-Received: by 2002:adf:e68f:0:b0:2cb:a82c:2523 with SMTP id r15-20020adfe68f000000b002cba82c2523mr4908655wrm.35.1677666031598; Wed, 01 Mar 2023 02:20:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m4-20020a05600c4f4400b003e209b45f6bsm20204002wmq.29.2023.03.01.02.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 02:20:31 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 01 Mar 2023 10:20:28 +0000 Subject: [PATCH v4 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 +- 1 file changed, 1 insertion(+), 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; } From patchwork Wed Mar 1 10:20:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 13155808 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 61303C7EE2D for ; Wed, 1 Mar 2023 10:20:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbjCAKUi (ORCPT ); Wed, 1 Mar 2023 05:20:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbjCAKUf (ORCPT ); Wed, 1 Mar 2023 05:20:35 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9022312BD7 for ; Wed, 1 Mar 2023 02:20:34 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id d41-20020a05600c4c2900b003e9e066550fso7493674wmp.4 for ; Wed, 01 Mar 2023 02:20:34 -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=B2SpxY5V72QCigE9NmI/7YatY7OyQ1Myu+A0oI2O9Jo=; b=iw6CYMOlf+3fWP8Eg1JU6g5NEdMXUcglqqIfhN7xGcv8DSo9hNjkTew/DzygUl2rWB yuB314IKYReY7Ag0chaQM5FcstjI/TlzI4K8esg2Zp+0zk1kiYHqH7vd5YIFOmRaVOsS ScofxeItyKD4cQACLx9IOXg2+MU6iGFSPmw1W0fXItMSPHhyBWnGBrYd72TWy8JVAsP1 LSPUspP5aL3cGI+XC5BMbR3dUqdQHjUy+JTthF+BrH74rxmg8QT7tE5OrdIZK1N6Q31u pwDaz7l/YFb68GbaZI94SEZbEpCN4uLzNps7u29V+MGvP43fDzr4LJuZ5l2M9p29x2lj KeGA== 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=B2SpxY5V72QCigE9NmI/7YatY7OyQ1Myu+A0oI2O9Jo=; b=ztKNUT8vrxoQLLhIywkKEw3ScOqDcenb61Pu7GxsuUYjI7B5WQ9Ld8tRrzsFYFb+nL FrS5/ISbvLzobIl5HYy3c4QZ5Mve665cpLJVf4LujRUXaaOcOVuEkjT8WOzgBdvrAfVY PWnfYcf7Ufh9dUwDuQ8j47A8XJvEFQtC/WtGN5Dze6/YJeSB6dlHL2sEyBUWbWi1q4c7 AieHD0MZyEd9dgbdS/J0Clmp7uYMR7Yj8g0Y5j2NwsPevRC7QaMf2wjSfA2lTw3SvfcE oblIB5Za0kX0mVzvrWkYmBnq/LBhDP1kvLGAqbsz3G6ojrAf9icyNL3IxZ6QrH34n0Kd oJ6Q== X-Gm-Message-State: AO0yUKW5ZQdjucm0LM0Sv1bF/HVnED6ugwDE/2BDDVPSCEWY5Gtdx/oH /zFuZZkV/ryzY0NNgzVKahndSenCM/U= X-Google-Smtp-Source: AK7set8XeZ8hL2JfBrw/ApxPtaaJsUgpHOke9CwpQGhx9oT9IvJwTERfhIfqVLGY/wNUJbUypwb8pQ== X-Received: by 2002:a05:600c:3093:b0:3eb:3104:efef with SMTP id g19-20020a05600c309300b003eb3104efefmr4400705wmn.31.1677666032367; Wed, 01 Mar 2023 02:20:32 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id iv16-20020a05600c549000b003e0238d9101sm17453294wmb.31.2023.03.01.02.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 02:20:31 -0800 (PST) Message-Id: <022818f0e9f130b62e856722d0db9818c0a1bcdd.1677666029.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 01 Mar 2023 10:20:29 +0000 Subject: [PATCH v4 2/2] 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 | 12 ++++++++++++ 3 files changed, 17 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 98a27a2948b..19ebefa5ace 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 && @@ -898,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 && (