From patchwork Wed Apr 27 17:06:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 12829229 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 E1350C433FE for ; Wed, 27 Apr 2022 17:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243794AbiD0RKa (ORCPT ); Wed, 27 Apr 2022 13:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243806AbiD0RK0 (ORCPT ); Wed, 27 Apr 2022 13:10:26 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3BCE12AA8 for ; Wed, 27 Apr 2022 10:07:13 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id a21so2709872edb.1 for ; Wed, 27 Apr 2022 10:07:13 -0700 (PDT) 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=HzLlNQRZqdl5/+Rl6rcO5VgO5HbPi+stSewnt84CjUw=; b=aLtxPxhVvNfuhkpTfxrHfNiVtH/scFtycwbQtAcbEpYkh8MHlbd1ePi7QEqkZpQyDL kd+oq10x+OA1NrgVKnfXkW7KBHjOr7DRxdEjEI6algcbmAxIBNnhaG9cb9mzia6DatjQ 4bDKtDwtypqiRii2h5NxlB7tq9/k1QkMXJgRQWZBlZIQCk2zLVwyIV7o1MLmoVdbIdLS G+ApQSRfnL8Y3uQOuxCI+Sqd4O9bODdGQD/Y5pzl1eWAZakH67KPza+D92Wl9xweOp/8 vSr4y2Y0V0G/7I9QML35n9fve+7YLMRA/wgirEpvaO0Y+pfKezfNpHfcFYSdqEyq8tiA Kt+w== 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=HzLlNQRZqdl5/+Rl6rcO5VgO5HbPi+stSewnt84CjUw=; b=yGSSfib2O++Z4DVbV+heFV4cecls3KQzvNqPYuFww51i4PwHiAS5PM0k06ZIQEK9yV /3Cvc+CRlyMWeT3fKV1RN2BxCZECBUSHXVP3i3Ewf632Mtl0JR7qKupUeBTUx2hOLu3L V9Jz8XBWCnBLdvK+1M4sro+I2SjzAr1pYOo6fPtB8/1kKOYcScYuUENxshFE5BqUCmyL /0reDneLovMGTvkGZd/FzUMrRjD0G0vnRMqYYb8ADHcrWeSQHjygcfQO5G6pWSR/0aRF IJ6VUT+4P27yswpMXezGqOEMMd527L+w/y5bUmcYYmNTa/+ZTNBIj1VytIrMc2upC2tE ZDLw== X-Gm-Message-State: AOAM530zEg45l8xfP1DJT5n7wpcVkeKuVLlc41rrwFxe7Ue9u65WD+WO tUdWCRp+0Idg0S6HnagLJ4aams0Adzr2eQ== X-Google-Smtp-Source: ABdhPJxYkpo3T3uc4JwWAg31a8wahxvr+OUNTHGq6i6QFqRIObX//mOc6jWNC5zK53WTk7fcTcGgHA== X-Received: by 2002:a05:6402:1e88:b0:412:fc6b:f271 with SMTP id f8-20020a0564021e8800b00412fc6bf271mr32034594edf.345.1651079232549; Wed, 27 Apr 2022 10:07:12 -0700 (PDT) Received: from buzz.local (62-165-236-195.pool.digikabel.hu. [62.165.236.195]) by smtp.gmail.com with ESMTPSA id jl5-20020a17090775c500b006f3b76a87ffsm2748849ejc.51.2022.04.27.10.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 10:07:12 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: git@vger.kernel.org Cc: Derrick Stolee , Taylor Blau , Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 1/3] t0033-safe-directory: check the error message without matching the trash dir Date: Wed, 27 Apr 2022 19:06:47 +0200 Message-Id: <20220427170649.4949-2-szeder.dev@gmail.com> X-Mailer: git-send-email 2.36.0.676.gf39b21ed98 In-Reply-To: <20220427170649.4949-1-szeder.dev@gmail.com> References: <20220427170649.4949-1-szeder.dev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since 8959555cee (setup_git_directory(): add an owner check for the top-level directory, 2022-03-02) when git finds itself in a repository owned by someone else, it aborts with a "fatal: unsafe repository ()" error message and an advice about how to set the 'safe.directory' config variable to mark that repository as safe. 't0033-safe-directory.sh' contains tests that check that this feature and handling said config work as intended. To ensure that git dies for the right reason, several of those tests check that its standard error contains the name of that config variable, but: - it only appears in the advice part, not in the actual error message. - it is interpreted as a regexp by 'grep', so, because of the dot, it matches the name of the test script and the path of the trash directory as well. Consequently, these tests could be fooled by any error message that would happen to include the path of the test repository. Tighten these checks to look for "unsafe repository" instead. Signed-off-by: SZEDER Gábor Signed-off-by: Carlo Marcelo Arenas Belón --- t/t0033-safe-directory.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh index 239d93f4d2..6f9680e8b0 100755 --- a/t/t0033-safe-directory.sh +++ b/t/t0033-safe-directory.sh @@ -9,7 +9,7 @@ export GIT_TEST_ASSUME_DIFFERENT_OWNER expect_rejected_dir () { test_must_fail git status 2>err && - grep "safe.directory" err + grep "unsafe repository" err } test_expect_success 'safe.directory is not set' ' From patchwork Wed Apr 27 17:06:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 12829230 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 79876C4332F for ; Wed, 27 Apr 2022 17:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243810AbiD0RKc (ORCPT ); Wed, 27 Apr 2022 13:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243833AbiD0RK1 (ORCPT ); Wed, 27 Apr 2022 13:10:27 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC042E9D9 for ; Wed, 27 Apr 2022 10:07:15 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id y21so2709870edo.2 for ; Wed, 27 Apr 2022 10:07:15 -0700 (PDT) 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=XmxWRJ/YvRLDS1YB5l69ff0bY2MoMfMAgwlnikl2lEw=; b=MLfsC9ivax2pUEOcnACMXksR+iFu2IJullnK4fOWBgAWxqaOdfaPlr0NbquutlYZx/ WR6YLEBPfQu3s5n8rwKrZ+yYF9rTzoMNMqV7tI2GKEnIDPfoYtwASsXCIceHC3wBmuXX rB0r5M4xpkzzSLxxK2IxVHYjRoDORg+Q6mygNqZCdrPJ8tkrPweW1p4JK02ptB347KVB WS37Y5NU8vnmsV1VZgKuNBNVbAB88gpm56iR+GZ/q24cYGp+HDMT0r/GkSFGMCXxxj7n U0IIBEX7VvG6UbQwwdvjdWhckfxW0YM/fpFVkzxCBTtPvuOzrLyFonBXxbv+BJ5cp4mN gBsg== 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=XmxWRJ/YvRLDS1YB5l69ff0bY2MoMfMAgwlnikl2lEw=; b=mcdRtEu0YYnoiICe1OiVzi1rDy31AJoE4lrHnGeyMHYejy0Dj+IcJWheEzhZ68BzwH ZyE74JIHlPHr4s/CXL/VF3OYmL/0f/CJcAqXE4DPo4MgwoEmqvwrmExQqt/29bcZc4pI 0gHdpIzDxIKSSlxFRvbUVuyodKQf1y3AK1epzJ1sG4kmMTFpsK+B2pmROnD+h/Djr/S/ nt8nxaNKTXxB8lo0zO0Eobguoi0o4EX8WX2FdhnQYy9Qkh067BS87ig5Eoli9Gt2KAeh swTLd+nm2DGkN0BIQMwDrJaEzhEaErmbhFWxrPgPc9n8J02+l/6GtTzBCfyz4ySmde9g NsLg== X-Gm-Message-State: AOAM533rc5+I40xwLeJys+y/IeDy1sW0jVU80dhFcESV4ovm+oMx5AwD jpQNFPNvKLNfwVkkzp7AjmVRSeaHL3oOkA== X-Google-Smtp-Source: ABdhPJyYrvYpCOsHDXgkukxecVPBPv2lYhuHR2tzEIVEEM/eujmz4qP101W8hvlSDCPsqghMyARdWQ== X-Received: by 2002:a05:6402:6d9:b0:425:e968:725b with SMTP id n25-20020a05640206d900b00425e968725bmr16980451edy.213.1651079233557; Wed, 27 Apr 2022 10:07:13 -0700 (PDT) Received: from buzz.local (62-165-236-195.pool.digikabel.hu. [62.165.236.195]) by smtp.gmail.com with ESMTPSA id jl5-20020a17090775c500b006f3b76a87ffsm2748849ejc.51.2022.04.27.10.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 10:07:13 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: git@vger.kernel.org Cc: Derrick Stolee , Taylor Blau , Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 2/3] t0033-safe-directory: check when 'safe.directory' is ignored Date: Wed, 27 Apr 2022 19:06:48 +0200 Message-Id: <20220427170649.4949-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.36.0.676.gf39b21ed98 In-Reply-To: <20220427170649.4949-1-szeder.dev@gmail.com> References: <20220427170649.4949-1-szeder.dev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org According to the documentation 'safe.directory' "is only respected when specified in a system or global config, not when it is specified in a repository config or via the command line option -c safe.directory=". Add tests to check that 'safe.directory' in the repository config or on the command line is indeed ignored. Signed-off-by: SZEDER Gábor --- t/t0033-safe-directory.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh index 6f9680e8b0..82dac0eb93 100755 --- a/t/t0033-safe-directory.sh +++ b/t/t0033-safe-directory.sh @@ -16,6 +16,19 @@ test_expect_success 'safe.directory is not set' ' expect_rejected_dir ' +test_expect_success 'ignoring safe.directory on the command line' ' + test_must_fail git -c safe.directory="$(pwd)" status 2>err && + grep "unsafe repository" err +' + +test_expect_success 'ignoring safe.directory in repo config' ' + ( + unset GIT_TEST_ASSUME_DIFFERENT_OWNER && + git config safe.directory "$(pwd)" + ) && + expect_rejected_dir +' + test_expect_success 'safe.directory does not match' ' git config --global safe.directory bogus && expect_rejected_dir From patchwork Wed Apr 27 17:06:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 12829231 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 8BF07C433F5 for ; Wed, 27 Apr 2022 17:07:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243829AbiD0RKe (ORCPT ); Wed, 27 Apr 2022 13:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243817AbiD0RK3 (ORCPT ); Wed, 27 Apr 2022 13:10:29 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F67321B1 for ; Wed, 27 Apr 2022 10:07:16 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id z99so2694141ede.5 for ; Wed, 27 Apr 2022 10:07:15 -0700 (PDT) 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=HoMeCLHSoY8bzvsz1SzKmQRGNJzKXNC79Vn7FBLHMF4=; b=ocAEUC1hr0jMIkr1Nnya4WY5DMM4MxzsjfCTyFJMvKRhY1zF+0f88BDcPjCDWbCCco B/MAx9ItR8FR/+MYH7o8SFU3TpfNyM40ETM8XTBFsGw9RG+d0E7+Mmm3wWamqb8tq+iw q+MEex7OeL8perqQQLRg7N5cwWkTQvffY4w+3QgYyGx0x7uhGBygOtvxXoyr3EBGMZy1 hASLxyYLUNgetN8w2RAuMSOBzr7Ik9IkQFYh4WbPlc+JmAHIZ8+rIMbUL9uRPvBgWBqs wZVMM3sEQc0CD2wBEYLwBjlypkHqJb7NGo6I8j3+TVHrLWhqc1LDE9awH+8TarjtKNvn sLTg== 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=HoMeCLHSoY8bzvsz1SzKmQRGNJzKXNC79Vn7FBLHMF4=; b=U1SOPRjvODDGzoOgtdIPETeUq4BXnXpefUBvFcaoUu/sbsal0FzyrI+GDmQndaig8D uXCUIFHW7vbc0dMjVkNzSoKb35dvfchdSMj/Ys6KLJmumi513c8x2sRHAnsRuhZIFVt/ B6apz0AA1JX8ZfYhpe9NojjodHI0EBEW/F4kOvgzMI7++Wy6KsOPWg1NDtT5sVxInhWd U2Yq/dHcEiOVIYeoL/O2EIhsahsmxd3o2hWtcSEkp4rcCWFuDbLtcIzz+fx2cAffqNQF CSLmGCRJGHwDWiSy09MxYpBkc8KdXM04WqWW0+LsAmu3M9loK0wK5NsdvZZw2KHuDyIy Fylg== X-Gm-Message-State: AOAM533TBXX0OI3Nr7oDV/c7UWy3n1gzaTR6PvP+l49o0TfWXJob0eVG IL1i+7hIScbmxi1HbCRq9e3POwEu3U4P+A== X-Google-Smtp-Source: ABdhPJysKdLkJC0Fvp45D73M3O6eAJj6VrW6TFBPXF23cMOX8cXJ+UhyYzgDFwDiAq8Kky+cfkxv0w== X-Received: by 2002:aa7:c6c3:0:b0:425:b13b:94f with SMTP id b3-20020aa7c6c3000000b00425b13b094fmr31271402eds.313.1651079234581; Wed, 27 Apr 2022 10:07:14 -0700 (PDT) Received: from buzz.local (62-165-236-195.pool.digikabel.hu. [62.165.236.195]) by smtp.gmail.com with ESMTPSA id jl5-20020a17090775c500b006f3b76a87ffsm2748849ejc.51.2022.04.27.10.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 10:07:14 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: git@vger.kernel.org Cc: Derrick Stolee , Taylor Blau , Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 3/3] safe.directory: document and check that it's ignored in the environment Date: Wed, 27 Apr 2022 19:06:49 +0200 Message-Id: <20220427170649.4949-4-szeder.dev@gmail.com> X-Mailer: git-send-email 2.36.0.676.gf39b21ed98 In-Reply-To: <20220427170649.4949-1-szeder.dev@gmail.com> References: <20220427170649.4949-1-szeder.dev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The description of 'safe.directory' mentions that it's respected in the system and global configs, and ignored in the repository config and on the command line, but it doesn't mention whether it's respected or ignored when specified via environment variables (nor does the commit message adding 'safe.directory' [1]). Clarify that 'safe.directory' is ignored when specified in the environment, and add tests to make sure that it remains so. [1] 8959555cee (setup_git_directory(): add an owner check for the top-level directory, 2022-03-02) Signed-off-by: SZEDER Gábor --- Documentation/config/safe.txt | 4 ++-- t/t0033-safe-directory.sh | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Documentation/config/safe.txt b/Documentation/config/safe.txt index 6d764fe0cc..ae0e2e3bdb 100644 --- a/Documentation/config/safe.txt +++ b/Documentation/config/safe.txt @@ -13,8 +13,8 @@ override any such directories specified in the system config), add a `safe.directory` entry with an empty value. + This config setting is only respected when specified in a system or global -config, not when it is specified in a repository config or via the command -line option `-c safe.directory=`. +config, not when it is specified in a repository config, via the command +line option `-c safe.directory=`, or in environment variables. + The value of this setting is interpolated, i.e. `~/` expands to a path relative to the home directory and `%(prefix)/` expands to a diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh index 82dac0eb93..238b25f91a 100755 --- a/t/t0033-safe-directory.sh +++ b/t/t0033-safe-directory.sh @@ -21,6 +21,21 @@ test_expect_success 'ignoring safe.directory on the command line' ' grep "unsafe repository" err ' +test_expect_success 'ignoring safe.directory in the environment' ' + test_must_fail env GIT_CONFIG_COUNT=1 \ + GIT_CONFIG_KEY_0="safe.directory" \ + GIT_CONFIG_VALUE_0="$(pwd)" \ + git status 2>err && + grep "unsafe repository" err +' + +test_expect_success 'ignoring safe.directory in GIT_CONFIG_PARAMETERS' ' + test_must_fail env \ + GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \ + git status 2>err && + grep "unsafe repository" err +' + test_expect_success 'ignoring safe.directory in repo config' ' ( unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&