From: Junio C Hamano <gitster@pobox.com>
To: "Štěpán Němec" <stepnem@smrk.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] test-lib: make sure TEST_DIRECTORY has no trailing slash
Date: Wed, 04 Oct 2023 09:19:40 -0700 [thread overview]
Message-ID: <xmqqbkdes6lf.fsf@gitster.g> (raw)
In-Reply-To: <20231004113413+0200.161419-stepnem@smrk.net> ("Štěpán Němec"'s message of "Wed, 04 Oct 2023 11:34:13 +0200")
Štěpán Němec <stepnem@smrk.net> writes:
> 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.
Actually I was still being silly. We sometimes do
val=$(cd there && do something there)
so that we can get the output from a command in a different
directory _without_ having to move our current directory. But the
point of this current topic is that we _need_ to convince the shell
that the path to our current directory is a canonical one without
trailing slash, so my silly 'cd "$(pwd)/."' (or your "cd .") should
be done outside the command expansion, or the canonicalized $PWD will
only appear inside the $() and the next reference to $(pwd) or $PWD
in the test script will still give the path with the trailing slash,
that is textually different from $TEST_DIRECTORY.
I wonder if this works better for you. We would be sure that $PWD
and $TEST_DIRECTORY (when the latter is not imported from the
environment) are the same, so "your cwd that does not end with /t
and has a trailing slash after it" would be gone. Any $PWD or $(pwd)
the tests refer to later in the step will also lack the unwanted
trailing slash. As long as "cd ." is sufficient to cause the shell
reexamine and canonicalize the $PWD, that is.
Thanks.
t/test-lib.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git c/t/test-lib.sh w/t/test-lib.sh
index 1656c9eed0..a7045e028c 100644
--- c/t/test-lib.sh
+++ w/t/test-lib.sh
@@ -19,6 +19,11 @@
# t/ subdirectory and are run in 'trash directory' subdirectory.
if test -z "$TEST_DIRECTORY"
then
+ # It is reported that some shells spawned in tricky ways can
+ # give $PWD with a trailing slash. An explicit chdir hopefully
+ # would wake them out of their hallucination.
+ cd .
+
# ensure that TEST_DIRECTORY is an absolute path so that it
# is valid even if the current working directory is changed
TEST_DIRECTORY=$(pwd)
@@ -626,7 +631,6 @@ fi
# Protect ourselves from common misconfiguration to export
# CDPATH into the environment
unset CDPATH
-
unset GREP_OPTIONS
unset UNZIP
next prev parent reply other threads:[~2023-10-04 16:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 8:23 [PATCH] test-lib: make sure TEST_DIRECTORY has no trailing slash Štěpán Němec
2023-10-03 21:21 ` Junio C Hamano
2023-10-03 21:57 ` Junio C Hamano
2023-10-04 9:34 ` Štěpán Němec
2023-10-04 16:19 ` Junio C Hamano [this message]
2023-10-04 17:01 ` Štěpán Němec
2023-10-04 17:15 ` Junio C Hamano
2023-10-04 17:40 ` Štěpán Němec
2023-10-04 18:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbkdes6lf.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=stepnem@smrk.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).