git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 3, 2023, 21:57 UTC
Message-ID
<xmqqjzs3wer0.fsf@gitster.g>
In-Reply-To
<xmqqwmw3wgeo.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 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
Previous: Junio C HamanoNext: Štěpán Němec
Message 3 of 9 in “test-lib: make sure TEST_DIRECTORY has no trailing slash”
  1. test-lib: make sure TEST_DIRECTORY has no trailing slashŠtěpán Němec, Oct 3, 2023
  2. Junio C HamanoOct 3, 2023
  3. Junio C HamanoOct 3, 2023
  4. Štěpán NěmecOct 4, 2023
  5. Junio C HamanoOct 4, 2023
  6. Štěpán NěmecOct 4, 2023
  7. Junio C HamanoOct 4, 2023
  8. Štěpán NěmecOct 4, 2023
  9. Junio C HamanoOct 4, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.