Re: [PATCH] test-lib: make sure TEST_DIRECTORY has no trailing slash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 03 Oct 2023 14:57:39 -0700
Junio C. Hamano wrote:

> Junio C Hamano <gitster@xxxxxxxxx> writes:
>
>> I wonder if this would be a safer alternative, or is it doing too
>> much more than what is necessary?
>
> An alternative with much smaller blast radius would be to do this.
>
> Hopefully, by going "$(pwd)/." before asking the value returned by
> the `pwd` command, we can make sure that the trailing slash is
> removed (or at least $(pwd) and $TEST_DIRECTORY should be identical
> after this is done).
>
>
>
>  t/test-lib.sh | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git c/t/test-lib.sh w/t/test-lib.sh
> index 1656c9eed0..d159358b21 100644
> --- c/t/test-lib.sh
> +++ w/t/test-lib.sh
> @@ -19,9 +19,13 @@
>  # t/ subdirectory and are run in 'trash directory' subdirectory.
>  if test -z "$TEST_DIRECTORY"
>  then
> -	# ensure that TEST_DIRECTORY is an absolute path so that it
> +	# Ensure that TEST_DIRECTORY is an absolute path so that it
>  	# is valid even if the current working directory is changed
> -	TEST_DIRECTORY=$(pwd)
> +	# Some environments can talk the shell into keeping trailing
> +	# slash in $PWD---go there and ask where we are to work it
> +	# around, as we expect TEST_DIRECTORY and PWD are both
> +	# canonical and can textually be compared for equality
> +	TEST_DIRECTORY=$(cd "$(pwd)/." && pwd)
>  else
>  	# The TEST_DIRECTORY will always be the path to the "t"
>  	# directory in the git.git checkout. This is overridden by

Yes, actually, AFAICT just $(cd . && pwd) fixes things (and saves a few
syscalls), and I agree this is a much better approach than my naive fix.

And functionally it should be equivalent to your other solution that did
this unconditionally, because the else branch (TEST_DIRECTORY set) was
already cd-ing anyway.

Thanks,

  Štěpán




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux