Re: [PATCH 1/3] t0033: add tests for safe.directory
- From
Derrick Stolee <derrickstolee@github.com>
- Date
- Apr 13, 2022, 16:29 UTC
- Message-ID
- <7f5bebcd-5622-51c7-2904-b793337843b1@github.com>
- In-Reply-To
- <xmqqwnft9cjg.fsf@gitster.g>
On 4/13/2022 12:24 PM, Junio C Hamano wrote:
Show 18 quoted lines
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Derrick Stolee <derrickstolee@github.com>
>>
>> It is difficult to change the ownership on a directory in our test
>> suite, so insert a new GIT_TEST_ASSUME_DIFFERENT_OWNER environment
>> variable to trick Git into thinking we are in a differently-owned
>> directory. This allows us to test that the config is parsed correctly.
>
> OK.
>
>> - if (is_path_owned_by_current_user(path))
>> + if (is_path_owned_by_current_user(path) &&
>> + !git_env_bool("GIT_TEST_ASSUME_DIFFERENT_OWNER", 0))
>> return 1;
>
> Shouldn't the overriding "GIT_TEST_BLAH" be checked before the
> real logic kicks in, I wonder?Either order would work. I bet that checking the environment is faster than checking the disk, so swapping the order would be prudent here.
Show 32 quoted lines
>> diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh
>> new file mode 100755
>> index 00000000000..9380ff3d017
>> --- /dev/null
>> +++ b/t/t0033-safe-directory.sh
>> @@ -0,0 +1,34 @@
>> +#!/bin/sh
>> +
>> +test_description='verify safe.directory checks'
>> +
>> +. ./test-lib.sh
>> +
>> +GIT_TEST_ASSUME_DIFFERENT_OWNER=1
>> +export GIT_TEST_ASSUME_DIFFERENT_OWNER
>> +
>> +expect_rejected_dir () {
>> + test_must_fail git status 2>err &&
>> + grep "safe.directory" err
>> +}
>> +...
>> +test_expect_success 'safe.directory matches' '
>> + git config --global --add safe.directory "$(pwd)" &&
>> + git status
>> +'
>
> Just double checking, as I know you are much closer to the affected
> platform than I'd ever be ;-) but is the use of $(pwd) safe and
> correct here?
>
> I always get confused between $(pwd) and $PWD, which does not make
> any difference on platforms I have access to, but makes difference
> to hurt Windows users.These tests pass CI on Windows. I've had issues before using $PWD, thinking back to tests in t7900-maintenance.sh that use $(pwd) instead.
Thanks, -Stolee