From patchwork Tue Jan 17 10:32:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 13104475 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 BCA2DC63797 for ; Tue, 17 Jan 2023 10:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236750AbjAQKg5 (ORCPT ); Tue, 17 Jan 2023 05:36:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236205AbjAQKgb (ORCPT ); Tue, 17 Jan 2023 05:36:31 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184D020055 for ; Tue, 17 Jan 2023 02:32:52 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id g10so21848009wmo.1 for ; Tue, 17 Jan 2023 02:32:52 -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=N86R8x7tY/jVkXj4il9Y0qauIyFiObIhfQ6ZH6WJC3o=; b=QfPJAHZx63xXCH6QLdrOxbSeeq5fp8Vp4nyHgfcb/NH9P0e6evv0OQ7thaDbz98ma0 Bn5DD/gBrLi1hZLnTRKVFjvP0G5zFZSo/DKOpBUmGVZ5vuRPhclKkSdga+2orKJY3iVu 6CVGkfkvTuh742gyqHZChNQjFLwoUuGryo61lxVUnvFCM4QMqlZEp9xLfRqoMG54B1ee 3BUER26NgVMHS0QDhdaAXrWHxc3/TLBRpnieMays87p/bgNIk+pmt2aAdCJGfdleeGuV tqHyONxDyGDUNvVkFC24OFM9TeP/RsO3RMKwWoKS5GChmkgTQxsqoHJx0q+ynb75aSgA 2ohQ== 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=N86R8x7tY/jVkXj4il9Y0qauIyFiObIhfQ6ZH6WJC3o=; b=Uq6bLo8EpiP5fp0G5YgtmUAJ/Ivd+DnFIJf4UZ8SMjwWqcMRRvCBern+vIp6eGg3Zb TuxPi387TiS+7yp6/Z4kH9EKgQ6P02PjJLlTPHeliCB2VufN/LrbPVkv1Bdgv0bysAtC /n33bFkY3HSU/b7t1c/bbIgLq2GLEo0nlWPu0g+RX82d4PBZCxqTz31psjGoGBPsp3Sg Zg7LjY+a6sbfQcU4KXiWCSrXJbEYARa0hvXfJlDSGFuyzx4RcKlAadW/r1CWSopvqBGK MSrayQLUYZwzQ6CZsNzwmuOc2XQtYvmB+qzj+zZUE53rkb56DA6DupzYw1b1l3FA/PyO UGXQ== X-Gm-Message-State: AFqh2kpASb/JXkj6pHQnFQksa62aSPQWkqYADZriLAMZU4Fv2ldQ0DM2 /aLdSxZreRo9eT8BaxToMAUkIzgxA0o= X-Google-Smtp-Source: AMrXdXsHn8SMwFp1v7PiRLsc7W1BH1yOP9Q1QMQxdKMsquvl3LqusPjDm0FNrgxOh/DIEiG/2XfTzg== X-Received: by 2002:a7b:c4ca:0:b0:3da:17f5:57b9 with SMTP id g10-20020a7bc4ca000000b003da17f557b9mr2768018wmk.5.1673951563944; Tue, 17 Jan 2023 02:32:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e13-20020a05600c218d00b003daf672a616sm7922160wme.22.2023.01.17.02.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 02:32:43 -0800 (PST) Message-Id: <214a2b662e3f8d6826a916b88cd3162e2d110e0a.1673951562.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 17 Jan 2023 10:32:40 +0000 Subject: [PATCH 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 a90af303630..13ff9fae3ba 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 Tue Jan 17 10:32:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 13104477 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 295D8C3DA78 for ; Tue, 17 Jan 2023 10:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236745AbjAQKhN (ORCPT ); Tue, 17 Jan 2023 05:37:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236724AbjAQKgf (ORCPT ); Tue, 17 Jan 2023 05:36:35 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED7A13867A for ; Tue, 17 Jan 2023 02:32:55 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id d2so9961663wrp.8 for ; Tue, 17 Jan 2023 02:32:55 -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=KubJKxpshjTvR5pLQ0gCsn4YDWIvsMwSSfeYsfYWJYc=; b=h3wPhply0em9Vqr5R0U01oz6voHEgJ6mTsMZyZMpRt9J8iqhEcOMmZMp6ah8MX7aqd p9uxNwHnwOgRVUb3Iu74Emtcyz0rWrdXaZNIgGQb16/vFyzzJ1nwbIuLEPEw4/EyUvPH V0cAB9DLvdUrWMtDv6bZdKg4G9lftbbbZV1H2C6cH+5KwU14+Elq2dnFmk2TjboPb01a dDhSemJdXdqTYkOkw6RtYOXHAeuLsZXsBreWN1kvVejUbf6t8MMaJMRwvWNUGGObUjKv 3bLeUSf6OYKsh9/sVhhwI2FF39DtsnJpbgPHrBS4YmMPB/9OuSXi7d0SQDqiwEYr42nT x6Gw== 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=KubJKxpshjTvR5pLQ0gCsn4YDWIvsMwSSfeYsfYWJYc=; b=pwmGyRXHo8tN0i605U6jCnxWe2c6D5BhH/bblmjNEknw/GpFQLjZ6Kh13Gnxli4fVU 4qIdAxglXfG41bARaWEMD+dLY4mFX2hSE/r8CZbHC4lUAU/nKaJLX2bwpaKqO5y2dD5N u9IqDscdU8fhUaXOGXDfDokOoWoU4RaMEsniho7fWoaWl741SJvaUbm8ri+WTxzqxiKS 8JyoUkCk9PQss7fnA0Ny9GDAQ4kRSSqcZomkT/Kvf+omnGmY0Qh1iQkn3Cka8jAjBvoA ivRRAGDyq8lhhL6YA9a5ELmFqOJpMNzqmgomuDgSRCrlP4a9UYBg/8NZYgWL+fN/3rL2 Vglg== X-Gm-Message-State: AFqh2kpgfLTDXzqzezlQMAygfstcziD4s958j9fCOy875Ftq+z/sFQR9 v17cxLAetrWY03r6lG9twO+8X/xaDWY= X-Google-Smtp-Source: AMrXdXtrwzQQUpFJrUJ/CSV9+YslwkYgUP3R97LoU1EnjMafwYOjeHvhf7teMQoRKkIOdczgjPpm2A== X-Received: by 2002:a5d:5484:0:b0:2bd:e150:bf54 with SMTP id h4-20020a5d5484000000b002bde150bf54mr10809594wrv.60.1673951564701; Tue, 17 Jan 2023 02:32:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b13-20020a05600003cd00b002be07cbefb2sm5341505wrg.18.2023.01.17.02.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 02:32:44 -0800 (PST) Message-Id: <605b95bf8ab6f1fb5b1ec5b75cd4dcaefbb7f3b6.1673951562.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 17 Jan 2023 10:32:41 +0000 Subject: [PATCH 2/2] [RFC] push: allow delete one 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 Git will reject the deletion of one level refs e,g. "refs/foo" through "git push -d", however, some users want to be able to clean up these branches that were created unexpectedly on the remote. 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 one level refs. This avoids creating/updating such one level branches, but allows them to be deleted. On the client side, "git push" also does not properly fill in the old-oid of one level refs, which causes the server-side "git receive-pack" to think that the ref's old-oid has changed when deleting one level refs, this causes the push to be rejected. So the solution is to fix the client to be able to delete one level refs by properly filling old-oid. Signed-off-by: ZheNing Hu --- builtin/receive-pack.c | 5 ++++- connect.c | 2 +- t/t5516-fetch-push.sh | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 13ff9fae3ba..ad21877ea1b 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1463,7 +1463,10 @@ 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..b841ae58e03 100644 --- a/connect.c +++ b/connect.c @@ -30,7 +30,7 @@ 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..dec8950a392 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -903,6 +903,19 @@ 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 && + ( + cd testrepo && + git update-ref refs/onelevel refs/heads/main + ) && + git push testrepo --delete refs/onelevel && + ( + cd testrepo && + test_must_fail git rev-parse --verify refs/onelevel + ) +' + test_expect_success 'warn on push to HEAD of non-bare repository' ' mk_test testrepo heads/main && (