From patchwork Wed Mar 2 13:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12765997 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 B7F9DC433FE for ; Wed, 2 Mar 2022 13:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242141AbiCBNXX (ORCPT ); Wed, 2 Mar 2022 08:23:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242134AbiCBNXV (ORCPT ); Wed, 2 Mar 2022 08:23:21 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08EE91125 for ; Wed, 2 Mar 2022 05:22:37 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id m42-20020a05600c3b2a00b00382ab337e14so2066159wms.3 for ; Wed, 02 Mar 2022 05:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4iYHtH6wEucn9NO8wlPK2l0j8Cz3wOFSZ/d+hbUAQoQ=; b=j8a0kFN1y9Jyqs3LcpnLuuSXiqooPmNKUyZIbOwb6KbuiZjVvJC1VWDthTSbo56zY0 WHSkTewTu0mYS1wMlJ0yVp3nyfYo3TXdoiEJok9o8qSvWjgPLmhLkKQHfPog0RQLEW1z wvugLeLH8BgXZOpZlhn89eEpbUvy418ieffzm9V6nqkfuq0M3CG7MDsLYhR+vA0yNxZE mCylT0rTw686TqoOBD31n0IEsHwSEM4C7mifR664L7EB8OMngpprNqoJYAM0RahPdApT TVmgNHMnUlb/MD0IQNE7lx3C+slyQDTwjQ++LWS1GLLjEoiieztdIC3KDebpvtdOCia4 u1WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4iYHtH6wEucn9NO8wlPK2l0j8Cz3wOFSZ/d+hbUAQoQ=; b=VL+HCbhsF4Qxs+3oLe8jsJPV0cJPrvLGFgSiFYSPfXOLiYCQE2U79wgR/t7vKTFtUQ /llEulWAURbyes8WjMWC1Y49E4kRoM3kyJPHIG9m+FxhHkUnQtD+oGvDdoivQ1rNVbET ePWPFY1H1/G14qWykRSR2GiYuAVN3vcngp0EaY8JWGFpYa4AuigmvGB6FbVNp3d2CFh4 CokzcNy433RiGem9Fz5ScLKFR46l/A/iE89bcICMfq1vMvR8O2alva5HMxTqvITYwgfW 8Rjf9dy/k6+iFb9GFlMtm/ffbuXIq9mTq3VuPaRpm8ZwZyUV1w7YD6D3sjy7G5oZ52hP bRMA== X-Gm-Message-State: AOAM530ZOwclDY6eyEE6hDw4ap1aZuTvTob04GBs+kpBOQfCT+tPJfLG LJ7jtjdZrzJhWr0BQchfAH9ae8LHklcxbw== X-Google-Smtp-Source: ABdhPJxfFnyddAfbttD2ADb4cuuxTkp+kbmymzgZaOFDzaBrY7Em5notLsDVnHw5PzuBAiNSjtuv7Q== X-Received: by 2002:a7b:c0d8:0:b0:381:3901:ab92 with SMTP id s24-20020a7bc0d8000000b003813901ab92mr19878744wmh.139.1646227355409; Wed, 02 Mar 2022 05:22:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:34 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 01/10] hook tests: turn exit code assertions into a loop Date: Wed, 2 Mar 2022 14:22:20 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Amend a test added in 96e7225b310 (hook: add 'run' subcommand, 2021-12-22) to use a for-loop instead of a copy/pasting the same test for the four exit codes we test. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1800-hook.sh | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 29718aa9913..ff64597e959 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -53,31 +53,16 @@ test_expect_success 'git hook run: stdout and stderr both write to our stderr' ' test_must_be_empty stdout.actual ' -test_expect_success 'git hook run: exit codes are passed along' ' - write_script .git/hooks/test-hook <<-EOF && - exit 1 - EOF - - test_expect_code 1 git hook run test-hook && - - write_script .git/hooks/test-hook <<-EOF && - exit 2 - EOF - - test_expect_code 2 git hook run test-hook && - - write_script .git/hooks/test-hook <<-EOF && - exit 128 - EOF - - test_expect_code 128 git hook run test-hook && - - write_script .git/hooks/test-hook <<-EOF && - exit 129 - EOF - - test_expect_code 129 git hook run test-hook -' +for code in 1 2 128 129 +do + test_expect_success "git hook run: exit code $code is passed along" ' + write_script .git/hooks/test-hook <<-EOF && + exit $code + EOF + + test_expect_code $code git hook run test-hook + ' +done test_expect_success 'git hook run arg u ments without -- is not allowed' ' test_expect_code 129 git hook run test-hook arg u ments From patchwork Wed Mar 2 13:22:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12765996 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 4EA0BC433EF for ; Wed, 2 Mar 2022 13:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242137AbiCBNXW (ORCPT ); Wed, 2 Mar 2022 08:23:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242135AbiCBNXV (ORCPT ); Wed, 2 Mar 2022 08:23:21 -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 E68E11137 for ; Wed, 2 Mar 2022 05:22:37 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id b5so2794313wrr.2 for ; Wed, 02 Mar 2022 05:22:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qiT/ZFJzI5gxqe7i0GcAGxq0NF6Q6YjCHESnLDeHntc=; b=gGgEaV7y2qonPyW7Bi56HTrNfF6Oo/cr3mwZdPA1mnkWicR8Qkh5q+WYdZHn+lQ+IA pJFmyosZV4/0gYUOnWZ8dLFlBEesb9K8Sy8CTC5XZstT9YVnN9bSfjdPbVM1imj/bwAV Fwk5wSN3xt9s+vesW03IYTpJZkd70uju68bE7OpVbSauZyf+aGOBgrjesX8Hk6Pe/KUV gpwHHLGh5cawF+OZtowxZOCggt0onFNAIxUJwHseSMvw8o1V38enbamdCJyOGsHh/zqg x2eJMa5duJnytWdJPKPDBclyoc4bXzcnE0AIX/58Pl+jm7uTqyjIagZl1TY0T3Iqan1c z5NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qiT/ZFJzI5gxqe7i0GcAGxq0NF6Q6YjCHESnLDeHntc=; b=ZZ6vVX7gJgvtUTJXtlfA84cP5pwLDiXjcJkpoYJdfzbWA05eK3NthU+eiMoIRwj4P5 unNLfv+LaxeJnhJZGo+uhd2dOGc76DQnAOIxeVlB5q2WXahnSi52F0bDH+9pk8ckLSM/ IuLSsmMXvgRyXbhN2/NfSFTQaxz4QXuWTveuxuWxziLaCdKz/0+p2u4n7LoP+0tcMcMw ++FTg5mtvcEkTkHnFWAxX/fQfgLiQg+3/hRvmFM+jbjvT73MQfNY+Au5tXV8Eea3ss0c esMHYFlxrRUbHrVJ86E8WCcOTJIRrwRfM/bdg/0B+YEYRyo0+3zeapFz9Z3A06SxyZA9 z37g== X-Gm-Message-State: AOAM531QZiliRyTlukzhh4Jn4gzuz3lilaBf6BuPF5GixWIu6WzwvivE zC6JO+UnrZn2eLpiTSwY7vqBgU0fqPr/0g== X-Google-Smtp-Source: ABdhPJw1M+Lb1DM+kluRnCXj1JFWXLDTAcn0sCdHL6QcX8+Zs3UjHvf0h8XiTXqDImop4h7a7GD0PQ== X-Received: by 2002:adf:e5d0:0:b0:1f0:22ee:5828 with SMTP id a16-20020adfe5d0000000b001f022ee5828mr4357130wrn.516.1646227356251; Wed, 02 Mar 2022 05:22:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:35 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 02/10] t5540: don't rely on "hook/post-update.sample" Date: Wed, 2 Mar 2022 14:22:21 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code added in a87679339c0 (test: rename http fetch and push test files, 2014-02-06) to stop relying on the "exec git update-server-info" in "templates/hooks--post-update.sample", let's instead inline the expected hook in the test itself. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5540-http-push-webdav.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/t/t5540-http-push-webdav.sh b/t/t5540-http-push-webdav.sh index b0dbacf0b9b..380e97c1762 100755 --- a/t/t5540-http-push-webdav.sh +++ b/t/t5540-http-push-webdav.sh @@ -42,7 +42,9 @@ test_expect_success 'setup remote repository' ' git clone --bare test_repo test_repo.git && cd test_repo.git && git --bare update-server-info && - mv hooks/post-update.sample hooks/post-update && + write_script hooks/post-update <<-\EOF && + exec git update-server-info + EOF ORIG_HEAD=$(git rev-parse --verify HEAD) && cd - && mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" From patchwork Wed Mar 2 13:22:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12765998 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 C478AC433EF for ; Wed, 2 Mar 2022 13:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242147AbiCBNXd (ORCPT ); Wed, 2 Mar 2022 08:23:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242138AbiCBNXW (ORCPT ); Wed, 2 Mar 2022 08:23:22 -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 C499F10A6 for ; Wed, 2 Mar 2022 05:22:38 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so1229550wmp.5 for ; Wed, 02 Mar 2022 05:22:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=59QAL6uD0ZwwSFvb/G4QuJN+OGihBCcNKvMvlH8MtZw=; b=l2q+JPpSnrjAabrE4CBkPBDpi4yvxi8uctoBHeyVlnZ+7LicXxoDinR1u2Ob/dX7eA po2iDs9IvCVfdv7tjg8p0/395CQdXE1p9pUV+UiERTqDFaoUF2FJDRJShzdm3yTWPQ// SQlZmSXYwIjiyUTaizwGWfsMqccbb+rFm1GaxD2xAOWJwsX8+B5s5NEHghW3v796mWLv yxyGvrprUrCNK6wsbBJlaofwqQplUKbdsBcpb99D9VGYCjnK9DtU7UJuJGTvcxU0hLoK qHPMrHAi7VuDLdMFkQyHiVIlhrSVQ9hmx72V56qivaO3V7x83i3nHw2Ot8bDXJx4DmUv 5gWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=59QAL6uD0ZwwSFvb/G4QuJN+OGihBCcNKvMvlH8MtZw=; b=yUHyOXME/0BpLWaDXfoQu6plLzEsaE8H3+wV6uW0GQ1pk/t/uWE7oSme99faX9oZTK jA02zM78NYgZIuhwzdDuh+nxQVZ7b2bm0FdykOnpwsxg+a/qLbkF/zBrv3XRjuJHtS0m 9Frk2qiJ8Ypaynb7XdmXs77NrwKbhe5RI9pVIicaeLOQBe0vl30Ii/JOXIn3ns3JxceF YFbDfJYnNv95ll4TbnnYJoj3A5rwzo2jBIzqlvkikg9w0wNK0afnXwO+unnEaaobNR+G 8NPJDR/IX/QuTCFT6vt08bj1vbwWK19OMi5a1vWXEzJcMl12Rph7Fb8oDY1wqfIr4edm 1q4A== X-Gm-Message-State: AOAM532iMWDrtUI97X4+rHvPl/WtNwPJ/Kvz4cJch4m/fQr77VfcmnVD 1tjanGWnLpqJmV+e8HiPdMst+vP8RAwxJg== X-Google-Smtp-Source: ABdhPJwMcIIVzMDgIAJl6N9N1IQLSGgphxPat89hyth4MaJMMxWO7QYOm3e8VaBm0CUALRqF04Q8LA== X-Received: by 2002:a05:600c:35d1:b0:37c:d45c:af57 with SMTP id r17-20020a05600c35d100b0037cd45caf57mr20926189wmq.149.1646227357101; Wed, 02 Mar 2022 05:22:37 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:36 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 03/10] tests: assume the hooks are disabled by default Date: Wed, 2 Mar 2022 14:22:22 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Stop moving the .git/hooks directory out of the way, or creating it during test setup. Instead assume that it will contain harmless *.sample files. That we can assume that is discussed in point #4 of f0d4d398e28 (test-lib: split up and deprecate test_create_repo(), 2021-05-10). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1416-ref-transaction-hooks.sh | 1 - t/t5516-fetch-push.sh | 3 +-- t/t7519-status-fsmonitor.sh | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index 4e1e84a91f3..d21dd5e5df0 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -8,7 +8,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh test_expect_success setup ' - mkdir -p .git/hooks && test_commit PRE && PRE_OID=$(git rev-parse PRE) && test_commit POST && diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 3137eb8d4d2..1a20e54adc1 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -28,8 +28,7 @@ mk_empty () { ( cd "$repo_name" && git init && - git config receive.denyCurrentBranch warn && - mv .git/hooks .git/hooks-disabled + git config receive.denyCurrentBranch warn ) } diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index a6308acf006..63a0f609866 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -56,7 +56,6 @@ test_lazy_prereq UNTRACKED_CACHE ' ' test_expect_success 'setup' ' - mkdir -p .git/hooks && : >tracked && : >modified && mkdir dir1 && @@ -322,7 +321,6 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' test_create_repo dot-git && ( cd dot-git && - mkdir -p .git/hooks && : >tracked && : >modified && mkdir dir1 && From patchwork Wed Mar 2 13:22:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12765999 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 EFFA1C433F5 for ; Wed, 2 Mar 2022 13:22:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242165AbiCBNXf (ORCPT ); Wed, 2 Mar 2022 08:23:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242140AbiCBNXX (ORCPT ); Wed, 2 Mar 2022 08:23:23 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB7DB218A for ; Wed, 2 Mar 2022 05:22:39 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id r10so2797681wrp.3 for ; Wed, 02 Mar 2022 05:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KFBqj4yqMLkzCfZqq3O6PsdGFjsb2eRhVwzE0/LsbN4=; b=lbIhD6oS/u0sML4reYxTozYbcY36MXWfQmU4uXMQPApla4FO1TInLWe5VEANmb9sIL siDv/XLtEwj6KrY8h+ULjhzC5PEn/mnkF808mYFAICwGkiSORsoOUAF8QDONztYY60ER G9JOuGubhKmrUa6QD7fDFPYvNRN10ebjL/WD1w3CrIsQjkCH/yYoW5maMOBXv8DlWXDV eUjpsW+RYJEqlNEANogqilh67ysvCdnUWvYGhZ6728wXq+s3QaDKUL8i+SwJNFC8r+Q+ /BxMUwqYehWK6sOobi8o8JoHhNGePcZ5KQSX54PMVnbzGDsIrtwv386bPx+8uX8XeSpF aOWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KFBqj4yqMLkzCfZqq3O6PsdGFjsb2eRhVwzE0/LsbN4=; b=eFWtbpcrpntEqyfsWXJYnBw0hlN6yqxvlaGj0d8gn5zQHCHOGWdtcTeZ0GR4iYDhEv Orna6UnoVNXeJ/innYBFnMLCq9LeJ1GWbRuOWCcj1oHQ3I7JQ6ToaHmsmLKoCqwKSoBp +tPu00VtSIjbpy3haPCgB/xqSQToQWVBPvIiNTOu0we1J0zQllexesgCD6PrnXnG28dI Q7foTZNy8St0oWJ9o1m5GLEHNI+WOLOhWo3GT5SO4JT0dyGluRIXiJOO3sW/ObL2+d2Z RTdJoiWJiI8DuQp9S194LkM9tyKhW/uGcZgBlTpAX9OIyrAO5lNWrp2jtMQ+E/eRkT1c YgTg== X-Gm-Message-State: AOAM530vR9+mzPAIPs2dXr7eR1WT/4c9H6qCUH+xjkxXeQ2UIQl10BRF j7AiF+buAgwd3JKdLXz94JG32+2/SEgGag== X-Google-Smtp-Source: ABdhPJxC2UqBTVdW/kleI0wZLPdFyzKNErVvznUV2HxIRRhYfivRNQxCosTviI6xlSYaxNBUSaCqlw== X-Received: by 2002:a5d:47c8:0:b0:1ef:8e97:2b8c with SMTP id o8-20020a5d47c8000000b001ef8e972b8cmr15172348wrc.545.1646227358045; Wed, 02 Mar 2022 05:22:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:37 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 04/10] bugreport tests: tighten up "git bugreport -s hooks" test Date: Wed, 2 Mar 2022 14:22:23 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Amend a test added in 788a776069b (bugreport: collect list of populated hooks, 2020-05-07) to make more sense. As noted in a preceding commit our .git/hooks directory already contains *.sample hooks, so we have no need to clobber the prepare-commit-msg.sample hook in particular. Instead we should assert that those *.sample hooks are not included in the output, and for good measure let's add a new "unknown-hook", to check that we only look through our own known hooks. See cfe853e66be (hook-list.h: add a generated list of hooks, like config-list.h, 2021-09-26) for how we generate that data. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0091-bugreport.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh index eeedbfa9193..3025e685aaa 100755 --- a/t/t0091-bugreport.sh +++ b/t/t0091-bugreport.sh @@ -60,18 +60,18 @@ test_expect_success 'can create leading directories outside of a git dir' ' test_expect_success 'indicates populated hooks' ' test_when_finished rm git-bugreport-hooks.txt && - test_when_finished rm -fr .git/hooks && - rm -fr .git/hooks && - mkdir .git/hooks && - for hook in applypatch-msg prepare-commit-msg.sample - do - write_script ".git/hooks/$hook" <<-EOF || return 1 - echo "hook $hook exists" - EOF - done && + + write_script .git/hooks/applypatch-msg <<-\EOF && + true + EOF + write_script .git/hooks/unknown-hook <<-\EOF && + true + EOF git bugreport -s hooks && + grep applypatch-msg git-bugreport-hooks.txt && - ! grep prepare-commit-msg git-bugreport-hooks.txt + ! grep unknown-hook git-bugreport-hooks.txt && + ! grep -F .sample git-bugreport-hooks.txt ' test_done From patchwork Wed Mar 2 13:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12766000 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 CADEFC433EF for ; Wed, 2 Mar 2022 13:22:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242142AbiCBNXh (ORCPT ); Wed, 2 Mar 2022 08:23:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242134AbiCBNXY (ORCPT ); Wed, 2 Mar 2022 08:23:24 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ED92219C for ; Wed, 2 Mar 2022 05:22:40 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id n14so2772099wrq.7 for ; Wed, 02 Mar 2022 05:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R+H1rvKBrSCyGKPtOv4WwqwWGhFLDlDHbpXDQqBmcUM=; b=YGAyp2gax0/NFyBGL/mjKtX+MxwTfnv8X8w9NDp8TOx2d24tPkBoU/l2k5MVPGQQFS JQucz+mIHLbfsqhJoBIocOChUnjZjk9THRYt1zeyCnoU6MeUyayoNQkeHqQi/5mQDXl4 Bc0krZQScj0CpUAGuUUB0f9yTmDb2TyZnTRlqVWOCiwu6a2KFec1NpByBM9MNXFffFFB p2Z4VsaE2KSTefC3HBnsCcO8oG1VkpIo7r8eV1XZV+sgDH6B8HM6KIChkKPW3D2iv2WU l6IcTmrbecmzIWL38ped0PvB3lH7bMB/TjuKGD0l3Gb3JR++DoSbeyJSTUNMOJlS0BXM rTOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R+H1rvKBrSCyGKPtOv4WwqwWGhFLDlDHbpXDQqBmcUM=; b=LXXElAJ5iRnXQZXpQ80AX8q3RL0gW/eIo8smOag+MnpNhL3FRgUqKpped++iSvbvpQ fG0nWyX90jrPaQF1VdKeB0cIIuDtdHeZbDd0tjcpzlUTxyQiYfFAhD9ED8LWmqfnsuoS MVw9T+LB+3Azh5aNAQEnM7gQcP4UykmiLcUz+91hIRWpP/V5X9puCbCsa30gfR+4Kn6S k92yuZT280CO15FZ42cK7oaVNkfaKbvsfkV+aDSnqTiziJqwNvno1DauUwktSyrREcLI IIf0e3gud+ZkWR6SL/AQZyKa7IU+gM1fIy4MJwm/M2dBa7JMaahD1rdbdoioL3elwm0R 1Msw== X-Gm-Message-State: AOAM532K1fvRrUIei+j5rVotEN7A8QyQRIbE1kPLeOrJFQtejsJ4oJ4F 7Nnh/bnW+poNqBsC08KO1fBoHQoQxj7s9Q== X-Google-Smtp-Source: ABdhPJx47NQ/8lifNxEPUndQHGGcCCGMrpUJYz7pVWfIEq6w3OaQn5Lr5GgcB3zgYmgNhFK0O0y21A== X-Received: by 2002:adf:bac5:0:b0:1f0:2233:5dd6 with SMTP id w5-20020adfbac5000000b001f022335dd6mr4586360wrg.474.1646227358925; Wed, 02 Mar 2022 05:22:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:38 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 05/10] tests: indent and add hook setup to "test_expect_success" Date: Wed, 2 Mar 2022 14:22:24 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Indent various hook setup code in the test suite that's using a manual "cat && chmod" pattern. These should also consistently use "#!$SHELL_PATH" instead of "#!/bin/sh", i.e. "test_script". Let's fix that in a subsequent commit, which will be easier to review after this smaller change. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3412-rebase-root.sh | 16 ++++---- t/t3413-rebase-hook.sh | 16 ++++---- t/t5401-update-hooks.sh | 76 ++++++++++++++++++------------------ t/t5407-post-rewrite-hook.sh | 16 ++++---- t/t5541-http-push-smart.sh | 24 ++++++------ 5 files changed, 75 insertions(+), 73 deletions(-) diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh index 1e9f7833dd6..239a9343d34 100755 --- a/t/t3412-rebase-root.sh +++ b/t/t3412-rebase-root.sh @@ -32,10 +32,10 @@ test_expect_success 'rebase --root fails with too many args' ' test_expect_success 'setup pre-rebase hook' ' mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <.git/PRE-REBASE-INPUT -EOF + cat >.git/hooks/pre-rebase <<-EOF && + #!$SHELL_PATH + echo "\$1,\$2" >.git/PRE-REBASE-INPUT + EOF chmod +x .git/hooks/pre-rebase ' cat > expect <.git/hooks/pre-rebase <.git/hooks/pre-rebase <<-EOF && + #!$SHELL_PATH + false + EOF chmod +x .git/hooks/pre-rebase ' diff --git a/t/t3413-rebase-hook.sh b/t/t3413-rebase-hook.sh index b4acb3be5cf..bb241b26b2e 100755 --- a/t/t3413-rebase-hook.sh +++ b/t/t3413-rebase-hook.sh @@ -42,10 +42,10 @@ test_expect_success 'rebase -i' ' test_expect_success 'setup pre-rebase hook' ' mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <.git/PRE-REBASE-INPUT -EOF + cat >.git/hooks/pre-rebase <<-EOF && + #!$SHELL_PATH + echo "\$1,\$2" >.git/PRE-REBASE-INPUT + EOF chmod +x .git/hooks/pre-rebase ' @@ -103,10 +103,10 @@ test_expect_success 'pre-rebase hook gets correct input (6)' ' test_expect_success 'setup pre-rebase hook that fails' ' mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <.git/hooks/pre-rebase <<-EOF && + #!$SHELL_PATH + false + EOF chmod +x .git/hooks/pre-rebase ' diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 6012cc8172a..6392f71795d 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -20,46 +20,46 @@ test_expect_success setup ' git clone --bare ./. victim.git && GIT_DIR=victim.git git update-ref refs/heads/tofail $commit1 && git update-ref refs/heads/main $commit1 && - git update-ref refs/heads/tofail $commit0 + git update-ref refs/heads/tofail $commit0 && + + cat >victim.git/hooks/pre-receive <<-\EOF && + #!/bin/sh + printf %s "$@" >>$GIT_DIR/pre-receive.args + cat - >$GIT_DIR/pre-receive.stdin + echo STDOUT pre-receive + echo STDERR pre-receive >&2 + EOF + chmod u+x victim.git/hooks/pre-receive && + + cat >victim.git/hooks/update <<-\EOF && + #!/bin/sh + echo "$@" >>$GIT_DIR/update.args + read x; printf %s "$x" >$GIT_DIR/update.stdin + echo STDOUT update $1 + echo STDERR update $1 >&2 + test "$1" = refs/heads/main || exit + EOF + chmod u+x victim.git/hooks/update && + + cat >victim.git/hooks/post-receive <<-\EOF && + #!/bin/sh + printf %s "$@" >>$GIT_DIR/post-receive.args + cat - >$GIT_DIR/post-receive.stdin + echo STDOUT post-receive + echo STDERR post-receive >&2 + EOF + chmod u+x victim.git/hooks/post-receive && + + cat >victim.git/hooks/post-update <<-\EOF && + #!/bin/sh + echo "$@" >>$GIT_DIR/post-update.args + read x; printf %s "$x" >$GIT_DIR/post-update.stdin + echo STDOUT post-update + echo STDERR post-update >&2 + EOF + chmod u+x victim.git/hooks/post-update ' -cat >victim.git/hooks/pre-receive <<'EOF' -#!/bin/sh -printf %s "$@" >>$GIT_DIR/pre-receive.args -cat - >$GIT_DIR/pre-receive.stdin -echo STDOUT pre-receive -echo STDERR pre-receive >&2 -EOF -chmod u+x victim.git/hooks/pre-receive - -cat >victim.git/hooks/update <<'EOF' -#!/bin/sh -echo "$@" >>$GIT_DIR/update.args -read x; printf %s "$x" >$GIT_DIR/update.stdin -echo STDOUT update $1 -echo STDERR update $1 >&2 -test "$1" = refs/heads/main || exit -EOF -chmod u+x victim.git/hooks/update - -cat >victim.git/hooks/post-receive <<'EOF' -#!/bin/sh -printf %s "$@" >>$GIT_DIR/post-receive.args -cat - >$GIT_DIR/post-receive.stdin -echo STDOUT post-receive -echo STDERR post-receive >&2 -EOF -chmod u+x victim.git/hooks/post-receive - -cat >victim.git/hooks/post-update <<'EOF' -#!/bin/sh -echo "$@" >>$GIT_DIR/post-update.args -read x; printf %s "$x" >$GIT_DIR/post-update.stdin -echo STDOUT post-update -echo STDERR post-update >&2 -EOF -chmod u+x victim.git/hooks/post-update - test_expect_success push ' test_must_fail git send-pack --force ./victim.git \ main tofail >send.out 2>send.err diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh index 6da8d760e28..64f40ff7776 100755 --- a/t/t5407-post-rewrite-hook.sh +++ b/t/t5407-post-rewrite-hook.sh @@ -17,15 +17,15 @@ test_expect_success 'setup' ' git checkout A^0 && test_commit E bar E && test_commit F foo F && - git checkout main -' + git checkout main && -cat >.git/hooks/post-rewrite < "$TRASH_DIRECTORY"/post-rewrite.args -cat > "$TRASH_DIRECTORY"/post-rewrite.data -EOF -chmod u+x .git/hooks/post-rewrite + cat >.git/hooks/post-rewrite <<-EOF && + #!/bin/sh + echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args + cat > "$TRASH_DIRECTORY"/post-rewrite.data + EOF + chmod u+x .git/hooks/post-rewrite +' clear_hook_input () { rm -f post-rewrite.args post-rewrite.data diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh index 8ca50f8b18c..0043b718f08 100755 --- a/t/t5541-http-push-smart.sh +++ b/t/t5541-http-push-smart.sh @@ -96,18 +96,20 @@ test_expect_success 'create and delete remote branch' ' test_must_fail git show-ref --verify refs/remotes/origin/dev ' -cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<-EOF && + #!/bin/sh + exit 1 + EOF + chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" && -cat >exp < dev2 (hook declined) -error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git' -EOF + cat >exp <<-EOF + remote: error: hook declined to update refs/heads/dev2 + To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git + ! [remote rejected] dev2 -> dev2 (hook declined) + error: failed to push some refs to '\''http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'\'' + EOF +' test_expect_success 'rejected update prints status' ' cd "$ROOT_PATH"/test_repo_clone && From patchwork Wed Mar 2 13:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12766001 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 A0470C433FE for ; Wed, 2 Mar 2022 13:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242168AbiCBNXj (ORCPT ); Wed, 2 Mar 2022 08:23:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242144AbiCBNXb (ORCPT ); Wed, 2 Mar 2022 08:23:31 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F67F25CF for ; Wed, 2 Mar 2022 05:22:41 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id d3so2804205wrf.1 for ; Wed, 02 Mar 2022 05:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bqkIQoy8IGKpHxwlad6S30B3tPn7r7hdgA6VXZfe+Oo=; b=O+tASzB4I7NBz5GUVyjq9OjkDc+jK+4V9+lGTd+TovV2EJXYkq02okH1KCwoKvDgQr swYs0bbIooECP+l5a6PZHcgC+Kh2+XqBmVQ5mUma/cufpWdmbFnnBM0BRRlooS1Nd5n7 DVrhDugRvwyWKl9AcxdOJsPV84qj1IbdjGP5gtrTTCNbgjr8qylQZ8XUx1CjhitjZXe6 rXZ8bI05kPW7BC/R5pc6/IJQwpSocZATyqGNKnK88P4d3sLU5jhLGE4WmOJqvj8YF7p7 7lpndVf3jG1eIXAriwIIzM5BX49bPDDqeNeKplCpK7jCN00ONvgOYU79cYqyBaIieNak IlqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bqkIQoy8IGKpHxwlad6S30B3tPn7r7hdgA6VXZfe+Oo=; b=5qB4alGp8kMWHKuFWdfzPsNeipsuCB9oXxEPKa2MjeD+pQPs5kYDt5AyS2JdmzOiNk 77aHsk0ggmiQobQ1niO43U+ZdYxnp/htwJ8XHzG84AJFJWXDdJUYNe7PsGfTRsO9+1um C2x3E/0uo8jIkcxSfFNlvmT2vIDO2lR3SlFPkETFVw3MTODLuwQ3UNyx0uYVerm4GXA/ F6RK6A3hcImsPi5xwZxJAyp39PWe1HWgs4o9A6NjuHMKB8JkFd5WpAhSfPO41L/6Xd4S oqvhNFZvg10Rb2gPgoYhdXNroM/oRax3i1LhQlLNJ/4Wm65cdcti7u2VETpnPY3keEOD oAUg== X-Gm-Message-State: AOAM532pzU1L+V5+lPHjs3JcKyPrnmZWF7mRaYrvHc1nL3rFhCcmWQiL 8ZkOQS5Zyzo2kduKtxrPvbVqCbcWz/MFuA== X-Google-Smtp-Source: ABdhPJyl2fvckMFMY4GfroO54IholuXmMf6kxbxWOFDuP1Gi6gjhxxfxlssMN/PEPAMIGnx/Bd+PFQ== X-Received: by 2002:a5d:5918:0:b0:1f0:3295:f4ec with SMTP id v24-20020a5d5918000000b001f03295f4ecmr2140638wrd.451.1646227359627; Wed, 02 Mar 2022 05:22:39 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:39 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 06/10] hook tests: get rid of unnecessary sub-shells Date: Wed, 2 Mar 2022 14:22:25 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the repository setup code for tests that test hooks the use of sub-shells when setting up the test repository and hooks. A subsequent commit will change the hook setup to use a helper that makes use of "test_when_finished", which cannot be used in sub-shells. Let's change that setup code, and the adjacent and similar "mk_empty" code. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5516-fetch-push.sh | 150 ++++++++++++++++++---------------------- t/t6500-gc.sh | 18 ++--- t/t9800-git-p4-basic.sh | 24 ++++--- 3 files changed, 94 insertions(+), 98 deletions(-) diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 1a20e54adc1..e4bb7581568 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -24,12 +24,8 @@ D=$(pwd) mk_empty () { repo_name="$1" rm -fr "$repo_name" && - mkdir "$repo_name" && - ( - cd "$repo_name" && - git init && - git config receive.denyCurrentBranch warn - ) + git init "$repo_name" && + git -C "$repo_name" config receive.denyCurrentBranch warn } mk_test () { @@ -58,36 +54,35 @@ mk_test () { mk_test_with_hooks() { repo_name=$1 mk_test "$@" && - ( - cd "$repo_name" && - mkdir .git/hooks && - cd .git/hooks && - - cat >pre-receive <<-'EOF' && - #!/bin/sh - cat - >>pre-receive.actual - EOF - cat >update <<-'EOF' && - #!/bin/sh - printf "%s %s %s\n" "$@" >>update.actual - EOF - - cat >post-receive <<-'EOF' && - #!/bin/sh - cat - >>post-receive.actual - EOF - - cat >post-update <<-'EOF' && - #!/bin/sh - for ref in "$@" - do - printf "%s\n" "$ref" >>post-update.actual - done - EOF - - chmod +x pre-receive update post-receive post-update - ) + cat >"$repo_name"/.git/hooks/pre-receive <<-'EOF' && + #!/bin/sh + cat - >>pre-receive.actual + EOF + + cat >"$repo_name"/.git/hooks/update <<-'EOF' && + #!/bin/sh + printf "%s %s %s\n" "$@" >>update.actual + EOF + + cat >"$repo_name"/.git/hooks/post-receive <<-'EOF' && + #!/bin/sh + cat - >>post-receive.actual + EOF + + cat >"$repo_name"/.git/hooks/post-update <<-'EOF' && + #!/bin/sh + for ref in "$@" + do + printf "%s\n" "$ref" >>post-update.actual + done + EOF + + chmod +x \ + "$repo_name"/.git/hooks/pre-receive \ + "$repo_name"/.git/hooks/update \ + "$repo_name"/.git/hooks/post-receive \ + "$repo_name"/.git/hooks/post-update } mk_child() { @@ -667,7 +662,6 @@ test_expect_success 'push does not update local refs on failure' ' mk_test testrepo heads/main && mk_child testrepo child && - mkdir testrepo/.git/hooks && echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && chmod +x testrepo/.git/hooks/pre-receive && ( @@ -1679,24 +1673,21 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' ' test_expect_success 'updateInstead with push-to-checkout hook' ' rm -fr testrepo && git init testrepo && - ( - cd testrepo && - git pull .. main && - git reset --hard HEAD^^ && - git tag initial && - git config receive.denyCurrentBranch updateInstead && - write_script .git/hooks/push-to-checkout <<-\EOF - echo >&2 updating from $(git rev-parse HEAD) - echo >&2 updating to "$1" - - git update-index -q --refresh && - git read-tree -u -m HEAD "$1" || { - status=$? - echo >&2 read-tree failed - exit $status - } - EOF - ) && + git -C testrepo pull .. main && + git -C testrepo reset --hard HEAD^^ && + git -C testrepo tag initial && + git -C testrepo config receive.denyCurrentBranch updateInstead && + write_script testrepo/.git/hooks/push-to-checkout <<-\EOF && + echo >&2 updating from $(git rev-parse HEAD) + echo >&2 updating to "$1" + + git update-index -q --refresh && + git read-tree -u -m HEAD "$1" || { + status=$? + echo >&2 read-tree failed + exit $status + } + EOF # Try pushing into a pristine git push testrepo main && @@ -1741,33 +1732,30 @@ test_expect_success 'updateInstead with push-to-checkout hook' ' # push into void rm -fr void && git init void && - ( - cd void && - git config receive.denyCurrentBranch updateInstead && - write_script .git/hooks/push-to-checkout <<-\EOF - if git rev-parse --quiet --verify HEAD - then - has_head=yes - echo >&2 updating from $(git rev-parse HEAD) - else - has_head=no - echo >&2 pushing into void - fi - echo >&2 updating to "$1" - - git update-index -q --refresh && - case "$has_head" in - yes) - git read-tree -u -m HEAD "$1" ;; - no) - git read-tree -u -m "$1" ;; - esac || { - status=$? - echo >&2 read-tree failed - exit $status - } - EOF - ) && + git -C void config receive.denyCurrentBranch updateInstead && + write_script void/.git/hooks/push-to-checkout <<-\EOF && + if git rev-parse --quiet --verify HEAD + then + has_head=yes + echo >&2 updating from $(git rev-parse HEAD) + else + has_head=no + echo >&2 pushing into void + fi + echo >&2 updating to "$1" + + git update-index -q --refresh && + case "$has_head" in + yes) + git read-tree -u -m HEAD "$1" ;; + no) + git read-tree -u -m "$1" ;; + esac || { + status=$? + echo >&2 read-tree failed + exit $status + } + EOF git push void main && ( diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index c2021267f2c..a6b0db22867 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -101,12 +101,12 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' ' EOF git init pre-auto-gc-hook && + write_script "pre-auto-gc-hook/.git/hooks/pre-auto-gc" <<-\EOF && + echo >&2 no gc for you && + exit 1 + EOF ( cd pre-auto-gc-hook && - write_script ".git/hooks/pre-auto-gc" <<-\EOF && - echo >&2 no gc for you && - exit 1 - EOF git config gc.auto 3 && git config gc.autoDetach false && @@ -128,12 +128,14 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' ' See "git help gc" for manual housekeeping. EOF + write_script "pre-auto-gc-hook/.git/hooks/pre-auto-gc" <<-\EOF && + echo >&2 will gc for you && + exit 0 + EOF + ( cd pre-auto-gc-hook && - write_script ".git/hooks/pre-auto-gc" <<-\EOF && - echo >&2 will gc for you && - exit 0 - EOF + git gc --auto >../out.actual 2>../err.actual ) && diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh index 806005a793a..3c1534c94d6 100755 --- a/t/t9800-git-p4-basic.sh +++ b/t/t9800-git-p4-basic.sh @@ -277,16 +277,22 @@ test_expect_success 'run hook p4-pre-submit before submit' ' git commit -m "add hello.txt" && git config git-p4.skipSubmitEdit true && git p4 submit --dry-run >out && - grep "Would apply" out && - mkdir -p .git/hooks && - write_script .git/hooks/p4-pre-submit <<-\EOF && - exit 0 - EOF + grep "Would apply" out + ) && + mkdir -p "$git"/.git/hooks && + write_script "$git"/.git/hooks/p4-pre-submit <<-\EOF && + exit 0 + EOF + ( + cd "$git" && git p4 submit --dry-run >out && - grep "Would apply" out && - write_script .git/hooks/p4-pre-submit <<-\EOF && - exit 1 - EOF + grep "Would apply" out + ) && + write_script "$git"/.git/hooks/p4-pre-submit <<-\EOF && + exit 1 + EOF + ( + cd "$git" && test_must_fail git p4 submit --dry-run >errs 2>&1 && ! grep "Would apply" errs ) From patchwork Wed Mar 2 13:22:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12766002 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 27A74C433F5 for ; Wed, 2 Mar 2022 13:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242170AbiCBNXl (ORCPT ); Wed, 2 Mar 2022 08:23:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242143AbiCBNXb (ORCPT ); Wed, 2 Mar 2022 08:23:31 -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 40484263D for ; Wed, 2 Mar 2022 05:22:42 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id u1so2748280wrg.11 for ; Wed, 02 Mar 2022 05:22:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=746Pcik37Ub57qp6a7Ps4MWcDnSlayC+wgcuwCVGfVM=; b=aNU+dg13/t96p7q3FhRLZl1KCLRgPYbz6lCTYbbK0+4ER7BjpR9QjIZvxf54ZoPjF2 F+MjVCsYS4JQ1GNkFoyJKlRVgXpzjfSYiX/U+tDnJm5a39bPalG46bNZpUelwOxKjoqa 8tcts3irZJPWTUyHn5CdEouXGW7RY58lpAV6ZjhPAuc9Mnx8KBTHQIPr95rCXgZcFAV4 RdVoqoY4Ggi19+eGT09f1osnLCvhRRb9M8fz3ok4yIRs2BP9x+WS2z4lUi/uvxwzkC+g EnxJ/Xt/MEmT4CsA0cf0QfiQ7mvVXbqKGbWrE+rElG+RRERiN2d3JEyytzpIGAHIQtdE ff8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=746Pcik37Ub57qp6a7Ps4MWcDnSlayC+wgcuwCVGfVM=; b=h1h4Ken/inWtqH/qqsDACPyHfKxr5Va6Y9SO/VCEf29v/W9/u6uBi56bf1HySQVYnx mc61NJdu+xUCQaEQYkyxKWcc80nOzCU1ooRvKQUHfhC+PyTSZLVVg80NCTqh0qpqWuyH Bd/PfXFLcrVjL6nUXaqvmY41rPbTiVILRNThhgsHiturxtgkvIvOW4/1QMBHgEUXnvS5 /o1nRK8xDfecPp0CsPERj5lxEn25EKlt3ZQjDxLV3SB0SrjtJHBFMBrJ6dl1jqUMYPKw ezlTOhO1ou2JfkWNuacs70tnjlSmJBmDRqlRroL9pIksrDwwtn5ttVisw7YvdFf+bSSM C6rA== X-Gm-Message-State: AOAM532E0BJoiHpR+fr0CCiOToOfNSAv2BF1LuG54ZuwrhcejpGfeInm ET1ydnsOmjq2Cb7CFXVIpY8aHRc0A/tETQ== X-Google-Smtp-Source: ABdhPJwX3WjrJ8FcW0k7xAU2gQg4JEIZn86SvrQk8jWkEg1ZQmY3voVoPfdx8I5XSe6aDRciAvHtIw== X-Received: by 2002:adf:90ca:0:b0:1ea:99dd:db45 with SMTP id i68-20020adf90ca000000b001ea99dddb45mr23028931wri.262.1646227360536; Wed, 02 Mar 2022 05:22:40 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:39 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 07/10] fetch+push tests: have tests clean up their own mess Date: Wed, 2 Mar 2022 14:22:26 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the "t5516-fetch-push.sh" test code to make use of "test_when_finished" to remove data instead of having tests clean up leftover data from earlier tests, which may or may not be there (e.g. depending on the --run=* option). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5516-fetch-push.sh | 50 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index e4bb7581568..fbe0a72b0b2 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -23,7 +23,8 @@ D=$(pwd) mk_empty () { repo_name="$1" - rm -fr "$repo_name" && + test_when_finished "rm -rf \"$repo_name\"" && + test_path_is_missing "$repo_name" && git init "$repo_name" && git -C "$repo_name" config receive.denyCurrentBranch warn } @@ -86,7 +87,7 @@ mk_test_with_hooks() { } mk_child() { - rm -rf "$2" && + test_when_finished "rm -rf \"$2\"" && git clone "$1" "$2" } @@ -191,32 +192,32 @@ grep_wrote () { grep 'write_pack_file/wrote.*"value":"'$1'"' $2 } -test_expect_success 'push with negotiation' ' - # Without negotiation +test_expect_success 'push without negotiation' ' mk_empty testrepo && git push testrepo $the_first_commit:refs/remotes/origin/first_commit && test_commit -C testrepo unrelated_commit && git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && - echo now pushing without negotiation && + test_when_finished "rm event" && GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main && - grep_wrote 5 event && # 2 commits, 2 trees, 1 blob + grep_wrote 5 event # 2 commits, 2 trees, 1 blob +' - # Same commands, but with negotiation - rm event && +test_expect_success 'push with negotiation' ' mk_empty testrepo && git push testrepo $the_first_commit:refs/remotes/origin/first_commit && test_commit -C testrepo unrelated_commit && git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && + test_when_finished "rm event" && GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main && grep_wrote 2 event # 1 commit, 1 tree ' test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' ' - rm event && mk_empty testrepo && git push testrepo $the_first_commit:refs/remotes/origin/first_commit && test_commit -C testrepo unrelated_commit && git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && + test_when_finished "rm event" && GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \ git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err && grep_wrote 5 event && # 2 commits, 2 trees, 1 blob @@ -1323,7 +1324,7 @@ done test_expect_success 'fetch follows tags by default' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && ( cd src && @@ -1333,6 +1334,7 @@ test_expect_success 'fetch follows tags by default' ' sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 | sort -k 3 >../expect ) && + test_when_finished "rm -rf dst" && git init dst && ( cd dst && @@ -1358,8 +1360,9 @@ test_expect_success 'peeled advertisements are not considered ref tips' ' test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1382,8 +1385,9 @@ test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' test_expect_success 'with no remote.$name.push, it is not used as refmap' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1404,8 +1408,9 @@ test_expect_success 'with no remote.$name.push, it is not used as refmap' ' test_expect_success 'with no remote.$name.push, upstream mapping is used' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1433,8 +1438,9 @@ test_expect_success 'with no remote.$name.push, upstream mapping is used' ' test_expect_success 'push does not follow tags by default' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1456,8 +1462,9 @@ test_expect_success 'push does not follow tags by default' ' test_expect_success 'push --follow-tags only pushes relevant tags' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1495,9 +1502,9 @@ EOF ' test_expect_success 'pushing a tag pushes the tagged object' ' - rm -rf dst.git && blob=$(echo unreferenced | git hash-object -w --stdin) && git tag -m foo tag-of-blob $blob && + test_when_finished "rm -rf dst.git" && git init --bare dst.git && git push dst.git tag-of-blob && # the receiving index-pack should have noticed @@ -1508,7 +1515,7 @@ test_expect_success 'pushing a tag pushes the tagged object' ' ' test_expect_success 'push into bare respects core.logallrefupdates' ' - rm -rf dst.git && + test_when_finished "rm -rf dst.git" && git init --bare dst.git && git -C dst.git config core.logallrefupdates true && @@ -1526,7 +1533,7 @@ test_expect_success 'push into bare respects core.logallrefupdates' ' ' test_expect_success 'fetch into bare respects core.logallrefupdates' ' - rm -rf dst.git && + test_when_finished "rm -rf dst.git" && git init --bare dst.git && ( cd dst.git && @@ -1547,6 +1554,7 @@ test_expect_success 'fetch into bare respects core.logallrefupdates' ' ' test_expect_success 'receive.denyCurrentBranch = updateInstead' ' + mk_empty testrepo && git push testrepo main && ( cd testrepo && @@ -1649,7 +1657,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' ' ) && # (5) push into void - rm -fr void && + test_when_finished "rm -rf void" && git init void && ( cd void && @@ -1671,7 +1679,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' ' ' test_expect_success 'updateInstead with push-to-checkout hook' ' - rm -fr testrepo && + test_when_finished "rm -rf testrepo" && git init testrepo && git -C testrepo pull .. main && git -C testrepo reset --hard HEAD^^ && @@ -1730,7 +1738,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' ' ) && # push into void - rm -fr void && + test_when_finished "rm -rf void" && git init void && git -C void config receive.denyCurrentBranch updateInstead && write_script void/.git/hooks/push-to-checkout <<-\EOF && From patchwork Wed Mar 2 13:22:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12766003 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 60B3BC433EF for ; Wed, 2 Mar 2022 13:23:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242178AbiCBNXq (ORCPT ); Wed, 2 Mar 2022 08:23:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242154AbiCBNXf (ORCPT ); Wed, 2 Mar 2022 08:23:35 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1329726CC for ; Wed, 2 Mar 2022 05:22:43 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id i8so2770382wrr.8 for ; Wed, 02 Mar 2022 05:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fBsLr3iwm0Ad8GRR+jmtCwPL5fJVrwxokEBnBHeEjb0=; b=WyPxDIuT14tu1i7NWpIMgZF2Xban1xCtERG2H9v16wOps1dtcCkp2atGkK4O7bg10O mvwH8ZbY9/oqU9O3yxtnn3CMyiXPKAOkoYRXEvymQmwrwmmFZ+zT1lVmJlO+UYIzDemi 38pdbB6G9CjIGILkDa0o2PWus+Ect+MV8HNratFfa7NfBJ0D+Y3e4tg0guZi+/kjjGJH iIWVDUO/w/PIo6Bw+sLVj19O7Yd0KGcVtjSPoDrThp2YLRlGUJPp+RRGx4tXm/tf6JGQ IqdlRb9IVQE/LtvWQQO75Of6Wy1bP6mmvAuXk+V2VHC1utSzWLPVBo21KcfeQA2BvUMn rndA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fBsLr3iwm0Ad8GRR+jmtCwPL5fJVrwxokEBnBHeEjb0=; b=hSlLeyOsyMoLuqIGx8msn8+8J5kkixAXwc8GemxIA6YL7+7HdY1ldaec7dm7r4ZWGv fu9IgicUHS7FVhRf7BRwm2iFWrCjzV7D36IOpqu38W5M/z3rILS7zoXSjzrRdSrIsq3d Eca+q7R+L+TfvsDiSoFrnrHGJJje20ng/LHbkdI7CMETIu9lPGvwMxxXLGfZEFIhJ7qU UREp3i270TczlNl5CFCtdYUdE4wcbVvyZg/GeFdw5ffRmNRIscsVzZfum3MSVjSq2oH3 vWdDI5ZGGKG32DEJlpBq4Gqc0o3+W1PBiPKuMGdCUhHMIrRifwviEGc2iQeCwb1FpGq+ 2wwg== X-Gm-Message-State: AOAM530osBURIVdiBa4Emf79nhyuoMjHhSavC2glofXFiUfSWmj/7nWY a9+wtH2b4K8fFP0++URGz3hjPNXE9cermg== X-Google-Smtp-Source: ABdhPJwiVfPTDF6FiRyPLCjCQ3kRInXtKdGoy7xCblmU2P4LOnJ35OZyIAXj/AHZz1zhiuTaV0XgEg== X-Received: by 2002:a5d:500e:0:b0:1f0:2509:ee3f with SMTP id e14-20020a5d500e000000b001f02509ee3fmr3246254wrt.381.1646227361267; Wed, 02 Mar 2022 05:22:41 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:40 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 08/10] test-lib-functions: add and use a "test_hook" wrapper Date: Wed, 2 Mar 2022 14:22:27 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a "test_hook" wrapper similar to the existing "test_config" wrapper added in d960c47a881 (test-lib: add helper functions for config, 2011-08-17). This wrapper: - Will clean up the hook with "test_when_finished", unless --setup is provided. - Will error if we clobber a hook, unless --clobber is provided. - Takes a name like "update" instead of ".git/hooks/update". - Accepts -C , like "test_config" and "test_commit". By using a wrapper we'll be able to easily change all the hook-related code that assumes that the template-created ".git/hooks" directory is created by "init", "clone" etc. once another topic follows-up and changes the test suite to stop creating trash directories using those templates. In addition this will make it easy to have the hooks configured using the "configuration-based hooks" topic, once we get around to integrating that. I.e. we'll be able to run the tests in a mode where we sometimes create a .git/hooks/, and other times create a script in another location, and point the relevant configuration snippet to it. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0091-bugreport.sh | 4 +-- t/t1416-ref-transaction-hooks.sh | 26 +++++++-------- t/t1800-hook.sh | 14 +++++--- t/t5406-remote-rejects.sh | 2 +- t/t5409-colorize-remote-messages.sh | 2 +- t/t5411-proc-receive-hook.sh | 4 +-- t/t5510-fetch.sh | 6 ++-- t/t5516-fetch-push.sh | 4 +-- t/t5521-pull-options.sh | 4 +-- t/t5540-http-push-webdav.sh | 2 +- t/t5547-push-quarantine.sh | 4 +-- t/t5548-push-porcelain.sh | 2 +- t/t6500-gc.sh | 4 +-- t/t7519-status-fsmonitor.sh | 18 +++++----- t/test-lib-functions.sh | 52 +++++++++++++++++++++++++++++ 15 files changed, 101 insertions(+), 47 deletions(-) diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh index 3025e685aaa..e4701da26aa 100755 --- a/t/t0091-bugreport.sh +++ b/t/t0091-bugreport.sh @@ -61,10 +61,10 @@ test_expect_success 'can create leading directories outside of a git dir' ' test_expect_success 'indicates populated hooks' ' test_when_finished rm git-bugreport-hooks.txt && - write_script .git/hooks/applypatch-msg <<-\EOF && + test_hook applypatch-msg <<-\EOF && true EOF - write_script .git/hooks/unknown-hook <<-\EOF && + test_hook unknown-hook <<-\EOF && true EOF git bugreport -s hooks && diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index d21dd5e5df0..085a7a46f21 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -15,9 +15,8 @@ test_expect_success setup ' ' test_expect_success 'hook allows updating ref if successful' ' - test_when_finished "rm .git/hooks/reference-transaction" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && echo "$*" >>actual EOF cat >expect <<-EOF && @@ -29,9 +28,8 @@ test_expect_success 'hook allows updating ref if successful' ' ' test_expect_success 'hook aborts updating ref in prepared state' ' - test_when_finished "rm .git/hooks/reference-transaction" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = prepared then exit 1 @@ -42,9 +40,9 @@ test_expect_success 'hook aborts updating ref in prepared state' ' ' test_expect_success 'hook gets all queued updates in prepared state' ' - test_when_finished "rm .git/hooks/reference-transaction actual" && + test_when_finished "rm actual" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = prepared then while read -r line @@ -65,9 +63,9 @@ test_expect_success 'hook gets all queued updates in prepared state' ' ' test_expect_success 'hook gets all queued updates in committed state' ' - test_when_finished "rm .git/hooks/reference-transaction actual" && + test_when_finished "rm actual" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = committed then while read -r line @@ -85,9 +83,9 @@ test_expect_success 'hook gets all queued updates in committed state' ' ' test_expect_success 'hook gets all queued updates in aborted state' ' - test_when_finished "rm .git/hooks/reference-transaction actual" && + test_when_finished "rm actual" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = aborted then while read -r line @@ -114,11 +112,11 @@ test_expect_success 'interleaving hook calls succeed' ' git init --bare target-repo.git && - write_script target-repo.git/hooks/reference-transaction <<-\EOF && + test_hook -C target-repo.git reference-transaction <<-\EOF && echo $0 "$@" >>actual EOF - write_script target-repo.git/hooks/update <<-\EOF && + test_hook -C target-repo.git update <<-\EOF && echo $0 "$@" >>actual EOF @@ -139,7 +137,7 @@ test_expect_success 'hook does not get called on packing refs' ' # Pack references first such that we are in a known state. git pack-refs --all && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && echo "$@" >>actual cat >>actual EOF @@ -165,7 +163,7 @@ test_expect_success 'deleting packed ref calls hook once' ' git update-ref refs/heads/to-be-deleted $POST_OID && git pack-refs --all && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && echo "$@" >>actual cat >>actual EOF diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index ff64597e959..26ed5e11bc8 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -27,7 +27,7 @@ test_expect_success 'git hook run: nonexistent hook with --ignore-missing' ' ' test_expect_success 'git hook run: basic' ' - write_script .git/hooks/test-hook <<-EOF && + test_hook test-hook <<-EOF && echo Test hook EOF @@ -39,7 +39,7 @@ test_expect_success 'git hook run: basic' ' ' test_expect_success 'git hook run: stdout and stderr both write to our stderr' ' - write_script .git/hooks/test-hook <<-EOF && + test_hook test-hook <<-EOF && echo >&1 Will end up on stderr echo >&2 Will end up on stderr EOF @@ -56,7 +56,7 @@ test_expect_success 'git hook run: stdout and stderr both write to our stderr' ' for code in 1 2 128 129 do test_expect_success "git hook run: exit code $code is passed along" ' - write_script .git/hooks/test-hook <<-EOF && + test_hook test-hook <<-EOF && exit $code EOF @@ -69,7 +69,7 @@ test_expect_success 'git hook run arg u ments without -- is not allowed' ' ' test_expect_success 'git hook run -- pass arguments' ' - write_script .git/hooks/test-hook <<-\EOF && + test_hook test-hook <<-\EOF && echo $1 echo $2 EOF @@ -84,7 +84,7 @@ test_expect_success 'git hook run -- pass arguments' ' ' test_expect_success 'git hook run -- out-of-repo runs excluded' ' - write_script .git/hooks/test-hook <<-EOF && + test_hook test-hook <<-EOF && echo Test hook EOF @@ -105,6 +105,10 @@ test_expect_success 'git -c core.hooksPath= hook run' ' Hook ran four EOF + test_hook test-hook <<-EOF && + echo Test hook + EOF + # Test various ways of specifying the path. See also # t1350-config-hooks-path.sh >actual && diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh index 5c509db6fc3..dcbeb420827 100755 --- a/t/t5406-remote-rejects.sh +++ b/t/t5406-remote-rejects.sh @@ -5,7 +5,7 @@ test_description='remote push rejects are reported by client' . ./test-lib.sh test_expect_success 'setup' ' - write_script .git/hooks/update <<-\EOF && + test_hook update <<-\EOF && exit 1 EOF echo 1 >file && diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh index 9f1a483f426..fa5de4500a4 100755 --- a/t/t5409-colorize-remote-messages.sh +++ b/t/t5409-colorize-remote-messages.sh @@ -5,7 +5,7 @@ test_description='remote messages are colorized on the client' . ./test-lib.sh test_expect_success 'setup' ' - write_script .git/hooks/update <<-\EOF && + test_hook --setup update <<-\EOF && echo error: error echo ERROR: also highlighted echo hint: hint diff --git a/t/t5411-proc-receive-hook.sh b/t/t5411-proc-receive-hook.sh index 98b0e812082..92cf52c6d4a 100755 --- a/t/t5411-proc-receive-hook.sh +++ b/t/t5411-proc-receive-hook.sh @@ -36,7 +36,7 @@ setup_upstream_and_workbench () { TAG=$(git -C workbench rev-parse v123) && # setup pre-receive hook - write_script upstream.git/hooks/pre-receive <<-\EOF && + test_hook --setup -C upstream.git pre-receive <<-\EOF && exec >&2 echo "# pre-receive hook" while read old new ref @@ -46,7 +46,7 @@ setup_upstream_and_workbench () { EOF # setup post-receive hook - write_script upstream.git/hooks/post-receive <<-\EOF && + test_hook --setup -C upstream.git post-receive <<-\EOF && exec >&2 echo "# post-receive hook" while read old new ref diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index ef0da0a63b5..4620f0ca7fa 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -273,7 +273,7 @@ test_expect_success 'fetch --atomic executes a single reference transaction only EOF rm -f atomic/actual && - write_script atomic/.git/hooks/reference-transaction <<-\EOF && + test_hook -C atomic reference-transaction <<-\EOF && ( echo "$*" && cat ) >>actual EOF @@ -306,7 +306,7 @@ test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' EOF rm -f atomic/actual && - write_script atomic/.git/hooks/reference-transaction <<-\EOF && + test_hook -C atomic/.git reference-transaction <<-\EOF && ( echo "$*" && cat ) >>actual exit 1 EOF @@ -334,7 +334,7 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' ' test_line_count = 2 atomic/.git/FETCH_HEAD && cp atomic/.git/FETCH_HEAD expected && - write_script atomic/.git/hooks/reference-transaction <<-\EOF && + test_hook -C atomic reference-transaction <<-\EOF && exit 1 EOF diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index fbe0a72b0b2..b689baf01a9 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1685,7 +1685,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' ' git -C testrepo reset --hard HEAD^^ && git -C testrepo tag initial && git -C testrepo config receive.denyCurrentBranch updateInstead && - write_script testrepo/.git/hooks/push-to-checkout <<-\EOF && + test_hook -C testrepo push-to-checkout <<-\EOF && echo >&2 updating from $(git rev-parse HEAD) echo >&2 updating to "$1" @@ -1741,7 +1741,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' ' test_when_finished "rm -rf void" && git init void && git -C void config receive.denyCurrentBranch updateInstead && - write_script void/.git/hooks/push-to-checkout <<-\EOF && + test_hook -C void push-to-checkout <<-\EOF && if git rev-parse --quiet --verify HEAD then has_head=yes diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh index 66cfcb09c55..264de29c35c 100755 --- a/t/t5521-pull-options.sh +++ b/t/t5521-pull-options.sh @@ -233,7 +233,7 @@ test_expect_success 'git pull --no-verify flag passed to merge' ' git init src && test_commit -C src one && git clone src dst && - write_script dst/.git/hooks/commit-msg <<-\EOF && + test_hook -C dst commit-msg <<-\EOF && false EOF test_commit -C src two && @@ -245,7 +245,7 @@ test_expect_success 'git pull --no-verify --verify passed to merge' ' git init src && test_commit -C src one && git clone src dst && - write_script dst/.git/hooks/commit-msg <<-\EOF && + test_hook -C dst commit-msg <<-\EOF && false EOF test_commit -C src two && diff --git a/t/t5540-http-push-webdav.sh b/t/t5540-http-push-webdav.sh index 380e97c1762..37db3dec0c5 100755 --- a/t/t5540-http-push-webdav.sh +++ b/t/t5540-http-push-webdav.sh @@ -42,7 +42,7 @@ test_expect_success 'setup remote repository' ' git clone --bare test_repo test_repo.git && cd test_repo.git && git --bare update-server-info && - write_script hooks/post-update <<-\EOF && + test_hook --setup post-update <<-\EOF && exec git update-server-info EOF ORIG_HEAD=$(git rev-parse --verify HEAD) && diff --git a/t/t5547-push-quarantine.sh b/t/t5547-push-quarantine.sh index faaa51ccc56..1876fb34e51 100755 --- a/t/t5547-push-quarantine.sh +++ b/t/t5547-push-quarantine.sh @@ -5,7 +5,7 @@ test_description='check quarantine of objects during push' test_expect_success 'create picky dest repo' ' git init --bare dest.git && - write_script dest.git/hooks/pre-receive <<-\EOF + test_hook --setup -C dest.git pre-receive <<-\EOF while read old new ref; do test "$(git log -1 --format=%s $new)" = reject && exit 1 done @@ -60,7 +60,7 @@ test_expect_success 'push to repo path with path separator (colon)' ' test_expect_success 'updating a ref from quarantine is forbidden' ' git init --bare update.git && - write_script update.git/hooks/pre-receive <<-\EOF && + test_hook -C update.git pre-receive <<-\EOF && read old new refname git update-ref refs/heads/unrelated $new exit 1 diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh index f11ff57e549..6282728eaf3 100755 --- a/t/t5548-push-porcelain.sh +++ b/t/t5548-push-porcelain.sh @@ -168,7 +168,7 @@ run_git_push_porcelain_output_test() { ' test_expect_success "prepare pre-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/pre-receive" <<-EOF + test_hook --setup -C "$upstream" pre-receive <<-EOF exit 1 EOF ' diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index a6b0db22867..39871b9901e 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -101,7 +101,7 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' ' EOF git init pre-auto-gc-hook && - write_script "pre-auto-gc-hook/.git/hooks/pre-auto-gc" <<-\EOF && + test_hook -C pre-auto-gc-hook pre-auto-gc <<-\EOF && echo >&2 no gc for you && exit 1 EOF @@ -128,7 +128,7 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' ' See "git help gc" for manual housekeeping. EOF - write_script "pre-auto-gc-hook/.git/hooks/pre-auto-gc" <<-\EOF && + test_hook -C pre-auto-gc-hook --clobber pre-auto-gc <<-\EOF && echo >&2 will gc for you && exit 0 EOF diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 63a0f609866..d8b0fc4681c 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -26,7 +26,7 @@ dirty_repo () { } write_integration_script () { - write_script .git/hooks/fsmonitor-test<<-\EOF + test_hook --setup --clobber fsmonitor-test<<-\EOF if test "$#" -ne 2 then echo "$0: exactly 2 arguments expected" @@ -107,7 +107,7 @@ EOF # test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook fsmonitor-test<<-\EOF && printf "last_update_token\0" EOF git update-index --fsmonitor && @@ -168,7 +168,7 @@ EOF # test that newly added files are marked valid test_expect_success 'newly added files are marked valid' ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --setup --clobber fsmonitor-test<<-\EOF && printf "last_update_token\0" EOF git add new && @@ -209,7 +209,7 @@ EOF # test that *only* files returned by the integration script get flagged as invalid test_expect_success '*only* files returned by the integration script get flagged as invalid' ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --clobber fsmonitor-test<<-\EOF && printf "last_update_token\0" printf "dir1/modified\0" EOF @@ -230,7 +230,7 @@ test_expect_success 'refresh_index() invalidates fsmonitor cache' ' dirty_repo && write_integration_script && git add . && - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --clobber fsmonitor-test<<-\EOF && EOF git commit -m "to reset" && git reset HEAD~1 && @@ -279,7 +279,7 @@ do # Make sure it's actually skipping the check for modified and untracked # (if enabled) files unless it is told about them. test_expect_success "status doesn't detect unreported modifications" ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --clobber fsmonitor-test<<-\EOF && printf "last_update_token\0" :>marker EOF @@ -405,14 +405,14 @@ test_expect_success 'status succeeds with sparse index' ' git -C sparse sparse-checkout init --cone --sparse-index && git -C sparse sparse-checkout set dir1 dir2 && - write_script .git/hooks/fsmonitor-test <<-\EOF && + test_hook --clobber fsmonitor-test <<-\EOF && printf "last_update_token\0" EOF git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test && git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test && check_sparse_index_behavior ! && - write_script .git/hooks/fsmonitor-test <<-\EOF && + test_hook --clobber fsmonitor-test <<-\EOF && printf "last_update_token\0" printf "dir1/modified\0" EOF @@ -430,7 +430,7 @@ test_expect_success 'status succeeds with sparse index' ' # This one modifies outside the sparse-checkout definition # and hence we expect to expand the sparse-index. - write_script .git/hooks/fsmonitor-test <<-\EOF && + test_hook --clobber fsmonitor-test <<-\EOF && printf "last_update_token\0" printf "dir1a/modified\0" EOF diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 85385d2ede7..0bef5913100 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -551,6 +551,58 @@ write_script () { chmod +x "$1" } +# Usage: test_hook [options] <<-\EOF +# +# -C : +# Run all git commands in directory +# --setup +# Setup a hook for subsequent tests, i.e. don't remove it in a +# "test_when_finished" +# --clobber +# Overwrite an existing , if it exists. Implies +# --setup (i.e. the "test_when_finished" is assumed to have been +# set up already). +test_hook () { + setup= && + clobber= && + indir= && + while test $# != 0 + do + case "$1" in + -C) + indir="$2" && + shift + ;; + --setup) + setup=t + ;; + --clobber) + clobber=t + ;; + -*) + BUG "invalid argument: $1" + ;; + *) + break + ;; + esac && + shift + done && + + git_dir=$(git -C "$indir" rev-parse --absolute-git-dir) && + hook_dir="$git_dir/hooks" && + hook_file="$hook_dir/$1" && + if test -z "$clobber" + then + test_path_is_missing "$hook_file" + fi && + if test -z "$setup$clobber" + then + test_when_finished "rm \"$hook_file\"" + fi && + write_script "$hook_file" +} + # Use test_set_prereq to tell that a particular prerequisite is available. # The prerequisite can later be checked for in two ways: # From patchwork Wed Mar 2 13:22:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12766005 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 88032C433EF for ; Wed, 2 Mar 2022 13:23:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242223AbiCBNX6 (ORCPT ); Wed, 2 Mar 2022 08:23:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238642AbiCBNXf (ORCPT ); Wed, 2 Mar 2022 08:23:35 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B7412AD7 for ; Wed, 2 Mar 2022 05:22:43 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id t11so2776236wrm.5 for ; Wed, 02 Mar 2022 05:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=phmtKEOi6GXvwW/B1MnkDZzak6pq3h6qR8WN2dUReqw=; b=iiP7BkuD//4HfQwcmupuuFI8KsGoy6Bj6le3w6Za7cgcVWXA1aaBCKuRRl2VvGZuXb ixR+nsqLR9Td6sU23l+YsAhzVvn9P/o/F+mB1ap+VqUbE+/ZvzPoWTgVUhJn94pTc4zQ vfVSVVr1xIuoIzXeB6JgG9hPn1rVsQFFWJ5vRLqOmaqRdVeACSxQT1goj8Ku4nDvMi9S qnHtdyad2jVlNn+emNPIpWIpgvnv6ORksAf9s6esypRng8MeeeWPCh6/QGZlw4Ii5qR2 YPbr1kbqRk2rDsUGYXlLbB1CeLgsfzVEiI/egT5ZsfmOCEQUAreBC2vCWCfImEdupbtN jfmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=phmtKEOi6GXvwW/B1MnkDZzak6pq3h6qR8WN2dUReqw=; b=A2YhQyKbpI0mEHpepat2oxybgtvttmK8p7mIS8J9cCDZUijMbwQ09W2YmPOKO4OKPc /qI+kdpxBtrlEE0+8C61+kpVGykSoIiKJm0eayjIRegu1jUCMVb6E8Rt01fuV1iBDZkK bRE3staRtFQB1C6XOhHbNBtIFOgZnvjjxG4pehYanUXEm8Dea0on7n4xiwi/G07LU3BV PDSZICQexruobPqcg5hI9ijZfEW3ooLEXp/XIwoWwaTdTCWOqqa7RR2IuN3GD8np3HSZ IuAO0wX4dmqlkrR7M5F7GkdhtdiZvORf7a3qLSxQ3imv0UoketTtuR7yZyd2kGa07lt0 /SNA== X-Gm-Message-State: AOAM533vpwoE7dysBu7GTijc85bI1sQvcVpL1MfydwmZ5BjDWOfKyBUN RZ2nfPWH6NGvuXj1zhZx9LICFIE0Hd96qA== X-Google-Smtp-Source: ABdhPJzFEtuYXdK8GNcDLK9xfkqqsYDyPVpxaKEh85BUyqQD5vcnxwzQjp6u8kHrptXmvlPmiZ2YIQ== X-Received: by 2002:adf:eb81:0:b0:1e3:2bf5:132 with SMTP id t1-20020adfeb81000000b001e32bf50132mr23551959wrn.246.1646227361924; Wed, 02 Mar 2022 05:22:41 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:41 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 09/10] tests: change "mkdir -p && write_script" to use "test_hook" Date: Wed, 2 Mar 2022 14:22:28 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change tests that used a "mkdir -p .git/hooks && write_script" pattern to use the new "test_hook" helper instead. The new helper does not create the .git/hooks directory, rather we assume that the default template will do so for us. An upcoming series[1] will extend "test_hook" to operate in a "--template=" mode, but for now assuming that we have a .git/hooks already is a safe assumption. If that assumption becomes false in the future we'll only need to change 'test_hook", instead of all of these callsites. 1. https://lore.kernel.org/git/cover-00.13-00000000000-20211212T201308Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0029-core-unsetenvvars.sh | 3 +-- t/t1350-config-hooks-path.sh | 4 ++-- t/t3404-rebase-interactive.sh | 10 ++-------- t/t3430-rebase-merges.sh | 6 +++--- t/t4150-am.sh | 24 ++++++------------------ t/t5403-post-checkout-hook.sh | 3 +-- t/t5534-push-signed.sh | 26 ++++++++------------------ t/t7113-post-index-change-hook.sh | 7 +++---- t/t9001-send-email.sh | 4 +--- t/t9800-git-p4-basic.sh | 5 ++--- 10 files changed, 29 insertions(+), 63 deletions(-) diff --git a/t/t0029-core-unsetenvvars.sh b/t/t0029-core-unsetenvvars.sh index b138e1d9cbc..4e8e90dd982 100755 --- a/t/t0029-core-unsetenvvars.sh +++ b/t/t0029-core-unsetenvvars.sh @@ -12,8 +12,7 @@ then fi test_expect_success 'setup' ' - mkdir -p "$TRASH_DIRECTORY/.git/hooks" && - write_script "$TRASH_DIRECTORY/.git/hooks/pre-commit" <<-\EOF + test_hook --setup pre-commit <<-\EOF echo $HOBBES >&2 EOF ' diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh index fa9647a7c0b..f6dc83e2aab 100755 --- a/t/t1350-config-hooks-path.sh +++ b/t/t1350-config-hooks-path.sh @@ -6,11 +6,11 @@ test_description='Test the core.hooksPath configuration variable' test_expect_success 'set up a pre-commit hook in core.hooksPath' ' >actual && - mkdir -p .git/custom-hooks .git/hooks && + mkdir -p .git/custom-hooks && write_script .git/custom-hooks/pre-commit <<-\EOF && echo CUSTOM >>actual EOF - write_script .git/hooks/pre-commit <<-\EOF + test_hook --setup pre-commit <<-\EOF echo NORMAL >>actual EOF ' diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index a38f2da7691..f31afd4a547 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -619,9 +619,7 @@ test_expect_success 'rebase a detached HEAD' ' ' test_expect_success 'rebase a commit violating pre-commit' ' - - mkdir -p .git/hooks && - write_script .git/hooks/pre-commit <<-\EOF && + test_hook pre-commit <<-\EOF && test -z "$(git diff --cached --check)" EOF echo "monde! " >> file1 && @@ -636,8 +634,6 @@ test_expect_success 'rebase a commit violating pre-commit' ' ' test_expect_success 'rebase with a file named HEAD in worktree' ' - - rm -fr .git/hooks && git reset --hard && git checkout -b branch3 A && @@ -1688,10 +1684,8 @@ test_expect_success 'valid author header when author contains single quote' ' ' test_expect_success 'post-commit hook is called' ' - test_when_finished "rm -f .git/hooks/post-commit" && >actual && - mkdir -p .git/hooks && - write_script .git/hooks/post-commit <<-\EOS && + test_hook post-commit <<-\EOS && git rev-parse HEAD >>actual EOS ( diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 43c82d9a33b..f351701fec2 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -292,9 +292,9 @@ test_expect_success 'post-rewrite hook and fixups work for merges' ' git commit --fixup HEAD same2.t && fixup="$(git rev-parse HEAD)" && - mkdir -p .git/hooks && - test_when_finished "rm .git/hooks/post-rewrite" && - echo "cat >actual" | write_script .git/hooks/post-rewrite && + test_hook post-rewrite <<-\EOF && + cat >actual + EOF test_tick && git rebase -i --autosquash -r HEAD^^^ && diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 159fae8d016..cdad4b68807 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -315,12 +315,10 @@ test_expect_success 'am --patch-format=hg applies hg patch' ' ' test_expect_success 'am with applypatch-msg hook' ' - test_when_finished "rm -f .git/hooks/applypatch-msg" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/applypatch-msg <<-\EOF && + test_hook applypatch-msg <<-\EOF && cat "$1" >actual-msg && echo hook-message >"$1" EOF @@ -335,12 +333,10 @@ test_expect_success 'am with applypatch-msg hook' ' ' test_expect_success 'am with failing applypatch-msg hook' ' - test_when_finished "rm -f .git/hooks/applypatch-msg" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/applypatch-msg <<-\EOF && + test_hook applypatch-msg <<-\EOF && exit 1 EOF test_must_fail git am patch1 && @@ -350,12 +346,10 @@ test_expect_success 'am with failing applypatch-msg hook' ' ' test_expect_success 'am with pre-applypatch hook' ' - test_when_finished "rm -f .git/hooks/pre-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/pre-applypatch <<-\EOF && + test_hook pre-applypatch <<-\EOF && git diff first >diff.actual exit 0 EOF @@ -368,12 +362,10 @@ test_expect_success 'am with pre-applypatch hook' ' ' test_expect_success 'am with failing pre-applypatch hook' ' - test_when_finished "rm -f .git/hooks/pre-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/pre-applypatch <<-\EOF && + test_hook pre-applypatch <<-\EOF && exit 1 EOF test_must_fail git am patch1 && @@ -383,12 +375,10 @@ test_expect_success 'am with failing pre-applypatch hook' ' ' test_expect_success 'am with post-applypatch hook' ' - test_when_finished "rm -f .git/hooks/post-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/post-applypatch <<-\EOF && + test_hook post-applypatch <<-\EOF && git rev-parse HEAD >head.actual git diff second >diff.actual exit 0 @@ -403,12 +393,10 @@ test_expect_success 'am with post-applypatch hook' ' ' test_expect_success 'am with failing post-applypatch hook' ' - test_when_finished "rm -f .git/hooks/post-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/post-applypatch <<-\EOF && + test_hook post-applypatch <<-\EOF && git rev-parse HEAD >head.actual exit 1 EOF diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index d1181816906..978f240cdac 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -10,8 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh test_expect_success setup ' - mkdir -p .git/hooks && - write_script .git/hooks/post-checkout <<-\EOF && + test_hook --setup post-checkout <<-\EOF && echo "$@" >.git/post-checkout.args EOF test_commit one && diff --git a/t/t5534-push-signed.sh b/t/t5534-push-signed.sh index 24d374adbae..7c0a148e73c 100755 --- a/t/t5534-push-signed.sh +++ b/t/t5534-push-signed.sh @@ -35,8 +35,7 @@ test_expect_success setup ' test_expect_success 'unsigned push does not send push certificate' ' prepare_dst && - mkdir -p dst/.git/hooks && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -52,8 +51,7 @@ test_expect_success 'unsigned push does not send push certificate' ' test_expect_success 'talking with a receiver without push certificate support' ' prepare_dst && - mkdir -p dst/.git/hooks && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -69,22 +67,19 @@ test_expect_success 'talking with a receiver without push certificate support' ' test_expect_success 'push --signed fails with a receiver without push certificate support' ' prepare_dst && - mkdir -p dst/.git/hooks && test_must_fail git push --signed dst noop ff +noff 2>err && test_i18ngrep "the receiving end does not support" err ' test_expect_success 'push --signed=1 is accepted' ' prepare_dst && - mkdir -p dst/.git/hooks && test_must_fail git push --signed=1 dst noop ff +noff 2>err && test_i18ngrep "the receiving end does not support" err ' test_expect_success GPG 'no certificate for a signed push with no update' ' prepare_dst && - mkdir -p dst/.git/hooks && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && if test -n "${GIT_PUSH_CERT-}" then git cat-file blob $GIT_PUSH_CERT >../push-cert @@ -96,9 +91,8 @@ test_expect_success GPG 'no certificate for a signed push with no update' ' test_expect_success GPG 'signed push sends push certificate' ' prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -139,10 +133,9 @@ test_expect_success GPG 'signed push sends push certificate' ' test_expect_success GPGSSH 'ssh signed push sends push certificate' ' prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -223,9 +216,8 @@ test_expect_success GPG 'inconsistent push options in signed push not allowed' ' test_expect_success GPG 'fail without key and heed user.signingkey' ' prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -273,9 +265,8 @@ test_expect_success GPG 'fail without key and heed user.signingkey' ' test_expect_success GPGSM 'fail without key and heed user.signingkey x509' ' test_config gpg.format x509 && prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -326,10 +317,9 @@ test_expect_success GPGSM 'fail without key and heed user.signingkey x509' ' test_expect_success GPGSSH 'fail without key and heed user.signingkey ssh' ' test_config gpg.format ssh && prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate diff --git a/t/t7113-post-index-change-hook.sh b/t/t7113-post-index-change-hook.sh index a21781d68a1..58e55a7c779 100755 --- a/t/t7113-post-index-change-hook.sh +++ b/t/t7113-post-index-change-hook.sh @@ -17,8 +17,7 @@ test_expect_success 'setup' ' ' test_expect_success 'test status, add, commit, others trigger hook without flags set' ' - mkdir -p .git/hooks && - write_script .git/hooks/post-index-change <<-\EOF && + test_hook post-index-change <<-\EOF && if test "$1" -eq 1; then echo "Invalid combination of flags passed to hook; updated_workdir is set." >testfailure exit 1 @@ -63,7 +62,7 @@ test_expect_success 'test status, add, commit, others trigger hook without flags ' test_expect_success 'test checkout and reset trigger the hook' ' - write_script .git/hooks/post-index-change <<-\EOF && + test_hook post-index-change <<-\EOF && if test "$1" -eq 1 && test "$2" -eq 1; then echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure exit 1 @@ -106,7 +105,7 @@ test_expect_success 'test checkout and reset trigger the hook' ' ' test_expect_success 'test reset --mixed and update-index triggers the hook' ' - write_script .git/hooks/post-index-change <<-\EOF && + test_hook post-index-change <<-\EOF && if test "$1" -eq 1 && test "$2" -eq 1; then echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure exit 1 diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 84d0f40d76a..42694fe5841 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -2288,9 +2288,7 @@ test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' ' ' test_expect_success $PREREQ 'invoke hook' ' - mkdir -p .git/hooks && - - write_script .git/hooks/sendemail-validate <<-\EOF && + test_hook sendemail-validate <<-\EOF && # test that we have the correct environment variable, pwd, and # argument case "$GIT_DIR" in diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh index 3c1534c94d6..8b30062c0cf 100755 --- a/t/t9800-git-p4-basic.sh +++ b/t/t9800-git-p4-basic.sh @@ -279,8 +279,7 @@ test_expect_success 'run hook p4-pre-submit before submit' ' git p4 submit --dry-run >out && grep "Would apply" out ) && - mkdir -p "$git"/.git/hooks && - write_script "$git"/.git/hooks/p4-pre-submit <<-\EOF && + test_hook -C "$git" p4-pre-submit <<-\EOF && exit 0 EOF ( @@ -288,7 +287,7 @@ test_expect_success 'run hook p4-pre-submit before submit' ' git p4 submit --dry-run >out && grep "Would apply" out ) && - write_script "$git"/.git/hooks/p4-pre-submit <<-\EOF && + test_hook -C "$git" --clobber p4-pre-submit <<-\EOF && exit 1 EOF ( From patchwork Wed Mar 2 13:22:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12766004 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 5F00CC433F5 for ; Wed, 2 Mar 2022 13:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242172AbiCBNXm (ORCPT ); Wed, 2 Mar 2022 08:23:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242150AbiCBNXe (ORCPT ); Wed, 2 Mar 2022 08:23:34 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CD5C26C1 for ; Wed, 2 Mar 2022 05:22:45 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id p9so2736581wra.12 for ; Wed, 02 Mar 2022 05:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GjRPcNPw3B+dJmRtuGj9hpzK6tbF0BlxBqrpr+4VoQg=; b=NZMQbRDKWOztw3cd9sdrKPQAIZBLian0mrhAM1erat1G04OcN842LnBLXjGNpXd5oH laqAn81tGyXODQd6LPjf3eoq7V6B+z8MsnrWQcf/B9dTvg++pJW5vS5tvUkDHVr6whLH PQ9H0jIoLemZSLG4UikPsFrO8zeVo+A6OizuOkIxgjkbWL1A2SOre20zAFz3bPiz1jIJ 7zGb6dLwfwe+1QqPEPSWERDct/lB9bzycBnxSBXiqXiicIjyQvrJlFPV/ruaGYl20k/v ZZ6fgS6IF9rT21Mhstkz5F3nyyxz/jFjHIhqZqgBjDHS3yMnc1gR8BcP3Z+DqW2nxU0m 0z3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GjRPcNPw3B+dJmRtuGj9hpzK6tbF0BlxBqrpr+4VoQg=; b=ac+pNUG2pT5ez4j6SYdSmZky5DLMvXyR2Bqs461bl58sM0DaeheG3NbHub6HW/BWSk Obk9QHYIDxEK6YL8j44JhtixecbMvSqya4kGWG+vXUYxH5/dveeSuxUKITvcIRUZ6jhl TDM7PbHzeHH6/OdBo1P2LpIAL9hOMklRdJpndmN2it1HA96xf0uQGOuOOVG2wEjTdwRc X0k9Vuza1b1MwGsCAbyRnotnp7dzWPVue3RMObnl6h7xNlvvMojYgNVXQufpDIb8FycM 0s8BYR11uV/wRef+5UUbZir/Y7IJZme/eQP48NmPo45ndD47aWWlxN4jT+rBl5XddG5V dFlg== X-Gm-Message-State: AOAM53021SNzit4QwZqHyWdgFapAFGhrVLhL/BBlLWSw35PLbtBn4RQm EjicBXYudz97hEMoS6C7cjruK2fTdhTRqw== X-Google-Smtp-Source: ABdhPJyA386p0/gahUEJn3ry58fxQ/PR53WIhmQ6PmASQOCW0V2/zeMnBSvDVuYVVnVls10WrAoO1A== X-Received: by 2002:a05:6000:124b:b0:1f0:4819:fd44 with SMTP id j11-20020a056000124b00b001f04819fd44mr738777wrx.101.1646227363254; Wed, 02 Mar 2022 05:22:43 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o13-20020a5d648d000000b001efd62a840dsm10814197wri.111.2022.03.02.05.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 05:22:42 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Emily Shaffer , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 10/10] tests: change "cat && chmod +x" to use "test_hook" Date: Wed, 2 Mar 2022 14:22:29 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1228.g56895c6ee86 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor various test code to use the "test_hook" helper. This change: - Fixes the long-standing issues with those tests using "#!/bin/sh" instead of "#!$SHELL_PATH". Using "#!/bin/sh" here happened to work because this code was so simply that it e.g. worked on Solaris /bin/sh. - Removes the "mkdir .git/hooks" invocation, as explained in a preceding commit we'll rely on the default templates to create that directory for us. For the test in "t5402-post-merge-hook.sh" it's easier and more correct to unroll the for-loop into a test_expect_success, so let's do that. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3412-rebase-root.sh | 12 +++--------- t/t3413-rebase-hook.sh | 12 +++--------- t/t5401-update-hooks.sh | 16 ++++------------ t/t5402-post-merge-hook.sh | 16 +++++++++------- t/t5407-post-rewrite-hook.sh | 4 +--- t/t5516-fetch-push.sh | 19 ++++--------------- t/t5541-http-push-smart.sh | 4 +--- t/t5601-clone.sh | 4 +--- 8 files changed, 26 insertions(+), 61 deletions(-) diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh index 239a9343d34..58371d8a547 100755 --- a/t/t3412-rebase-root.sh +++ b/t/t3412-rebase-root.sh @@ -31,12 +31,9 @@ test_expect_success 'rebase --root fails with too many args' ' ' test_expect_success 'setup pre-rebase hook' ' - mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <<-EOF && - #!$SHELL_PATH - echo "\$1,\$2" >.git/PRE-REBASE-INPUT + test_hook --setup pre-rebase <<-\EOF + echo "$1,$2" >.git/PRE-REBASE-INPUT EOF - chmod +x .git/hooks/pre-rebase ' cat > expect <.git/hooks/pre-rebase <<-EOF && - #!$SHELL_PATH + test_hook --setup --clobber pre-rebase <<-\EOF false EOF - chmod +x .git/hooks/pre-rebase ' test_expect_success 'pre-rebase hook stops rebase' ' diff --git a/t/t3413-rebase-hook.sh b/t/t3413-rebase-hook.sh index bb241b26b2e..9fab0d779bb 100755 --- a/t/t3413-rebase-hook.sh +++ b/t/t3413-rebase-hook.sh @@ -41,12 +41,9 @@ test_expect_success 'rebase -i' ' ' test_expect_success 'setup pre-rebase hook' ' - mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <<-EOF && - #!$SHELL_PATH - echo "\$1,\$2" >.git/PRE-REBASE-INPUT + test_hook --setup pre-rebase <<-\EOF + echo "$1,$2" >.git/PRE-REBASE-INPUT EOF - chmod +x .git/hooks/pre-rebase ' test_expect_success 'pre-rebase hook gets correct input (1)' ' @@ -102,12 +99,9 @@ test_expect_success 'pre-rebase hook gets correct input (6)' ' ' test_expect_success 'setup pre-rebase hook that fails' ' - mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <<-EOF && - #!$SHELL_PATH + test_hook --setup --clobber pre-rebase <<-\EOF false EOF - chmod +x .git/hooks/pre-rebase ' test_expect_success 'pre-rebase hook stops rebase (1)' ' diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 6392f71795d..d5771b96114 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -22,42 +22,34 @@ test_expect_success setup ' git update-ref refs/heads/main $commit1 && git update-ref refs/heads/tofail $commit0 && - cat >victim.git/hooks/pre-receive <<-\EOF && - #!/bin/sh + test_hook --setup -C victim.git pre-receive <<-\EOF && printf %s "$@" >>$GIT_DIR/pre-receive.args cat - >$GIT_DIR/pre-receive.stdin echo STDOUT pre-receive echo STDERR pre-receive >&2 EOF - chmod u+x victim.git/hooks/pre-receive && - cat >victim.git/hooks/update <<-\EOF && - #!/bin/sh + test_hook --setup -C victim.git update <<-\EOF && echo "$@" >>$GIT_DIR/update.args read x; printf %s "$x" >$GIT_DIR/update.stdin echo STDOUT update $1 echo STDERR update $1 >&2 test "$1" = refs/heads/main || exit EOF - chmod u+x victim.git/hooks/update && - cat >victim.git/hooks/post-receive <<-\EOF && - #!/bin/sh + test_hook --setup -C victim.git post-receive <<-\EOF && printf %s "$@" >>$GIT_DIR/post-receive.args cat - >$GIT_DIR/post-receive.stdin echo STDOUT post-receive echo STDERR post-receive >&2 EOF - chmod u+x victim.git/hooks/post-receive && - cat >victim.git/hooks/post-update <<-\EOF && - #!/bin/sh + test_hook --setup -C victim.git post-update <<-\EOF echo "$@" >>$GIT_DIR/post-update.args read x; printf %s "$x" >$GIT_DIR/post-update.stdin echo STDOUT post-update echo STDERR post-update >&2 EOF - chmod u+x victim.git/hooks/post-update ' test_expect_success push ' diff --git a/t/t5402-post-merge-hook.sh b/t/t5402-post-merge-hook.sh index 3e5e19c7191..915af2de95e 100755 --- a/t/t5402-post-merge-hook.sh +++ b/t/t5402-post-merge-hook.sh @@ -25,13 +25,15 @@ test_expect_success setup ' GIT_DIR=clone2/.git git update-index --add a ' -for clone in 1 2; do - cat >clone${clone}/.git/hooks/post-merge <<'EOF' -#!/bin/sh -echo $@ >> $GIT_DIR/post-merge.args -EOF - chmod u+x clone${clone}/.git/hooks/post-merge -done +test_expect_success 'setup clone hooks' ' + test_when_finished "rm -f hook" && + cat >hook <<-\EOF && + echo $@ >>$GIT_DIR/post-merge.args + EOF + + test_hook --setup -C clone1 post-merge .git/hooks/post-rewrite <<-EOF && - #!/bin/sh + test_hook --setup post-rewrite <<-EOF echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args cat > "$TRASH_DIRECTORY"/post-rewrite.data EOF - chmod u+x .git/hooks/post-rewrite ' clear_hook_input () { diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index b689baf01a9..4dfb080433e 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -55,35 +55,24 @@ mk_test () { mk_test_with_hooks() { repo_name=$1 mk_test "$@" && - - cat >"$repo_name"/.git/hooks/pre-receive <<-'EOF' && - #!/bin/sh + test_hook -C "$repo_name" pre-receive <<-'EOF' && cat - >>pre-receive.actual EOF - cat >"$repo_name"/.git/hooks/update <<-'EOF' && - #!/bin/sh + test_hook -C "$repo_name" update <<-'EOF' && printf "%s %s %s\n" "$@" >>update.actual EOF - cat >"$repo_name"/.git/hooks/post-receive <<-'EOF' && - #!/bin/sh + test_hook -C "$repo_name" post-receive <<-'EOF' && cat - >>post-receive.actual EOF - cat >"$repo_name"/.git/hooks/post-update <<-'EOF' && - #!/bin/sh + test_hook -C "$repo_name" post-update <<-'EOF' for ref in "$@" do printf "%s\n" "$ref" >>post-update.actual done EOF - - chmod +x \ - "$repo_name"/.git/hooks/pre-receive \ - "$repo_name"/.git/hooks/update \ - "$repo_name"/.git/hooks/post-receive \ - "$repo_name"/.git/hooks/post-update } mk_child() { diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh index 0043b718f08..ab4b5cfcd11 100755 --- a/t/t5541-http-push-smart.sh +++ b/t/t5541-http-push-smart.sh @@ -97,11 +97,9 @@ test_expect_success 'create and delete remote branch' ' ' test_expect_success 'setup rejected update hook' ' - cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<-EOF && - #!/bin/sh + test_hook --setup -C "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" update <<-\EOF && exit 1 EOF - chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" && cat >exp <<-EOF remote: error: hook declined to update refs/heads/dev2 diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 83c24fc97a7..4a61f2c901e 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -79,12 +79,10 @@ test_expect_success 'clone from hooks' ' cd .. && git init r1 && cd r1 && - cat >.git/hooks/pre-commit <<-\EOF && - #!/bin/sh + test_hook pre-commit <<-\EOF && git clone ../r0 ../r2 exit 1 EOF - chmod u+x .git/hooks/pre-commit && : >file && git add file && test_must_fail git commit -m invoke-hook &&