From patchwork Mon Aug 9 17:56:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kim Altintop X-Patchwork-Id: 12426993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41D7EC4338F for ; Mon, 9 Aug 2021 17:57:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AB8861159 for ; Mon, 9 Aug 2021 17:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235739AbhHIR5v (ORCPT ); Mon, 9 Aug 2021 13:57:51 -0400 Received: from mail1.protonmail.ch ([185.70.40.18]:17121 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235715AbhHIR5O (ORCPT ); Mon, 9 Aug 2021 13:57:14 -0400 Date: Mon, 09 Aug 2021 17:56:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eagain.st; s=protonmail; t=1628531811; bh=rWb19kpNbJ6bceLXacmyKg333Ak1I2jLiQ9teztIrUQ=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=ed1dkB2ZSI935It/a1OauOXirVPZpgx5NpuUfOG8ZnAH/JumjQGt4vwpkqkEMeKE9 W4uHUoLY58drF/856F0OepLk8CQ6OgIsxqecP0BLL4VGj8crO7w7NQKFBwc640aH5E vfaAlxUuyCu2FfUsAbTzoVy5NbYYhtV9Gzlks3QQcq+Wl3GeQWKJc5lfSIfP7mL/U/ rn4wJo6nydrQKSvXG7Flbd/uzyxl/9ONxloK0Ool55l+O1dg1sRNa3VXSSR/DNAs/x Lx989raHXwAqFLqOmwgcIzNe15kppPsjebJv8zZRLmQePJ1TaOZx2lMRhuIbr8X2fx WFjXs6IH6Gz6w== To: git@vger.kernel.org From: Kim Altintop Cc: kim@eagain.st, gitster@pobox.com, jonathantanmy@google.com, bwilliams.eng@gmail.com Reply-To: Kim Altintop Subject: [PATCH 1/3] t5730: introduce fetch command helper Message-ID: <20210809175530.75326-2-kim@eagain.st> In-Reply-To: <20210809175530.75326-1-kim@eagain.st> References: <20210730135845.633234-1-kim@eagain.st> <20210731203415.618641-1-kim@eagain.st> <20210804203829.661565-1-kim@eagain.st> <20210804205951.668140-1-kim@eagain.st> <20210809175530.75326-1-kim@eagain.st> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Assembling a "raw" fetch command to be fed directly to "test-tool serve-v2" is extracted into a test helper. Suggested-by: Junio C Hamano Signed-off-by: Kim Altintop --- t/t5703-upload-pack-ref-in-want.sh | 107 ++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 33 deletions(-) -- 2.32.0 diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index e9e471621d..cd4744b016 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -40,6 +40,54 @@ write_command () { fi } +# Write a complete fetch command to stdout, suitable for use with `test-tool +# pkt-line`. "want-ref", "want", and "have" values can be given in this order, +# with sections separated by "--". +# +# Examples: +# +# write_fetch_command refs/heads/main +# +# write_fetch_command \ +# refs/heads/main \ +# -- \ +# -- \ +# $(git rev-parse x) +# +# write_fetch_command \ +# -- +# $(git rev-parse a) \ +# -- +# $(git rev-parse b) +write_fetch_command () { + write_command fetch && + echo "0001" && + echo "no-progress" || return + while : + do + case $# in 0) break ;; esac && + case "$1" in --) shift; break ;; esac && + echo "want-ref $1" && + shift || return + done && + while : + do + case $# in 0) break ;; esac && + case "$1" in --) shift; break ;; esac && + echo "want $1" && + shift || return + done && + while : + do + case $# in 0) break ;; esac && + case "$1" in --) shift; break ;; esac && + echo "have $1" && + shift || return + done && + echo "done" && + echo "0000" +} + # c(o/foo) d(o/bar) # \ / # b e(baz) f(main) @@ -97,15 +145,13 @@ test_expect_success 'basic want-ref' ' EOF git rev-parse f >expected_commits && - oid=$(git rev-parse a) && test-tool pkt-line pack >in <<-EOF && - $(write_command fetch) - 0001 - no-progress - want-ref refs/heads/main - have $oid - done - 0000 + $(write_fetch_command \ + refs/heads/main \ + -- \ + -- \ + $(git rev-parse a) \ + ) EOF test-tool serve-v2 --stateless-rpc >out expected_commits && - oid=$(git rev-parse b) && test-tool pkt-line pack >in <<-EOF && - $(write_command fetch) - 0001 - no-progress - want-ref refs/heads/o/foo - want-ref refs/heads/o/bar - have $oid - done - 0000 + $(write_fetch_command \ + refs/heads/o/foo \ + refs/heads/o/bar \ + -- \ + -- \ + $(git rev-parse b) \ + ) EOF test-tool serve-v2 --stateless-rpc >out expected_commits && test-tool pkt-line pack >in <<-EOF && - $(write_command fetch) - 0001 - no-progress - want-ref refs/heads/main - want $(git rev-parse e) - have $(git rev-parse a) - done - 0000 + $(write_fetch_command \ + refs/heads/main \ + -- \ + $(git rev-parse e) \ + -- \ + $(git rev-parse a) \ + ) EOF test-tool serve-v2 --stateless-rpc >out expected_commits && - oid=$(git rev-parse c) && test-tool pkt-line pack >in <<-EOF && - $(write_command fetch) - 0001 - no-progress - want-ref refs/heads/o/foo - have $oid - done - 0000 + $(write_fetch_command \ + refs/heads/o/foo \ + -- \ + -- \ + $(git rev-parse c) \ + ) EOF test-tool serve-v2 --stateless-rpc >out X-Patchwork-Id: 12426995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 366D7C4338F for ; Mon, 9 Aug 2021 17:59:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A1A361153 for ; Mon, 9 Aug 2021 17:59:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234844AbhHISAL (ORCPT ); Mon, 9 Aug 2021 14:00:11 -0400 Received: from mail-0201.mail-europe.com ([51.77.79.158]:53987 "EHLO mail-0201.mail-europe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235306AbhHIR6T (ORCPT ); Mon, 9 Aug 2021 13:58:19 -0400 Date: Mon, 09 Aug 2021 17:57:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eagain.st; s=protonmail; t=1628531840; bh=H7MkQaKJvT7+plVxYRS0OeDRqWCXDsG23RQXMDCzisg=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=db422gGpZLKMcJ9PPUfq87W1Odme0GhnXaFbgZaJkySOfCksEt1GcZ/jBS7hMPgCs d0D8SVQsch5iUR1BXnhsllzpl59zz8kguo86RvV1UFXda1Ggic/p30jtd64VKjBVJk MBF7ZOI4aQVcg1dkt+LfGbhfOogs2rfCJVMVnBxeGoYn0s8ItcmZZAcU8WvRZ/y3SN Jz0rB0LdxPMYjBmUl5/cNpTO1alPXgtFxBUrK3jNX+PGd/7bTbhg5bWzVaUS35uwci ehgn4tlB1ChmpX/mGkdGBsUMsTGj3zfo2gxs4pyPkpXQ4ezvFGflqEsQzA2m6tIX2p vrAyDb/h6UQOg== To: git@vger.kernel.org From: Kim Altintop Cc: kim@eagain.st, gitster@pobox.com, jonathantanmy@google.com, bwilliams.eng@gmail.com Reply-To: Kim Altintop Subject: [PATCH 2/3] upload-pack.c: treat want-ref relative to namespace Message-ID: <20210809175530.75326-3-kim@eagain.st> In-Reply-To: <20210809175530.75326-1-kim@eagain.st> References: <20210730135845.633234-1-kim@eagain.st> <20210731203415.618641-1-kim@eagain.st> <20210804203829.661565-1-kim@eagain.st> <20210804205951.668140-1-kim@eagain.st> <20210809175530.75326-1-kim@eagain.st> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When 'upload-pack' runs within the context of a git namespace, treat any 'want-ref' lines the client sends as relative to that namespace. Also check if the wanted ref is hidden via 'hideRefs'. If it is hidden, respond with an error as if the ref didn't exist. Helped-by: Jonathan Tan Signed-off-by: Kim Altintop --- t/t5703-upload-pack-ref-in-want.sh | 129 +++++++++++++++++++++++++++++ upload-pack.c | 18 ++-- 2 files changed, 140 insertions(+), 7 deletions(-) -- 2.32.0 diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index cd4744b016..3e1e0b8fe1 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -339,6 +339,135 @@ test_expect_success 'fetching with wildcard that matches multiple refs' ' grep "want-ref refs/heads/o/bar" log ' +REPO="$(pwd)/repo-ns" + +test_expect_success 'setup namespaced repo' ' + ( + git init -b main "$REPO" && + cd "$REPO" && + test_commit a && + test_commit b && + git checkout a && + test_commit c && + git checkout a && + test_commit d && + git update-ref refs/heads/ns-no b && + git update-ref refs/namespaces/ns/refs/heads/ns-yes c && + git update-ref refs/namespaces/ns/refs/heads/hidden d + ) && + git -C "$REPO" config uploadpack.allowRefInWant true +' + +test_expect_success 'with namespace: want-ref is considered relative to namespace' ' + wanted_ref=refs/heads/ns-yes && + + oid=$(git -C "$REPO" rev-parse "refs/namespaces/ns/$wanted_ref") && + cat >expected_refs <<-EOF && + $oid $wanted_ref + EOF + cat >expected_commits <<-EOF && + $oid + $(git -C "$REPO" rev-parse a) + EOF + + test-tool pkt-line pack >in <<-EOF && + $(write_fetch_command $wanted_ref) + EOF + + GIT_NAMESPACE=ns test-tool -C "$REPO" serve-v2 --stateless-rpc >out in <<-EOF && + $(write_fetch_command $wanted_ref) + EOF + + test_must_fail env GIT_NAMESPACE=ns \ + test-tool -C "$REPO" serve-v2 --stateless-rpc >out expected_refs <<-EOF && + $oid $wanted_ref + EOF + cat >expected_commits <<-EOF && + $oid + $(git -C "$REPO" rev-parse a) + EOF + + test-tool pkt-line pack >in <<-EOF && + $(write_fetch_command $wanted_ref) + EOF + + test-tool -C "$REPO" serve-v2 --stateless-rpc >out in <<-EOF && + $(write_fetch_command $wanted_ref) + EOF + + test_must_fail env GIT_NAMESPACE=ns \ + test-tool -C "$REPO" serve-v2 --stateless-rpc >out