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

[PATCH] t/test-lib.sh: resolve symlinks in working directory, for pathname comparisons

From
LWLea Wiemann <lewiemann@gmail.com>
Date
May 31, 2008, 21:11 UTC
Message-ID
<1212268281-16797-1-git-send-email-LeWiemann@gmail.com>

Without this, some tests will fail because they compare command output of subprocesses (such as git) with $PWD -- but subprocesses have the physical path as their working directory, whereas $PWD contains the symlinked path. This fixes it.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---
Here is how to reproduce it:
$ ln -s /path/to/git git-symlink
$ cd git-symlink/t
$ ./t0001-init.sh 
*   ok 1: plain
*   ok 2: plain with GIT_WORK_TREE
*   ok 3: plain bare
*   ok 4: plain bare with GIT_WORK_TREE
*   ok 5: GIT_DIR bare
*   ok 6: GIT_DIR non-bare
* FAIL 7: GIT_DIR & GIT_WORK_TREE (1)
	
	
		(
			unset GIT_CONFIG
			mkdir git-dir-wt-1.git &&
			GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
		) &&
		check_config git-dir-wt-1.git false "$(pwd)"
	
*   ok 8: GIT_DIR & GIT_WORK_TREE (2)
*   ok 9: reinit
* failed 1 among 9 test(s)

With this patch applied, all tests work fine in symlinked working directories.

 t/test-lib.sh |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 3bf570b..7a8bd27 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -419,7 +419,9 @@ rm -fr "$test" || {
 }
 
 test_create_repo "$test"
-cd "$test" || exit 1
+# Use -P to resolve symlinks in our working directory so that the cwd
+# in subprocesses like git equals our $PWD (for pathname comparisons).
+cd -P "$test" || exit 1
 
 this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
 for skp in $GIT_SKIP_TESTS
-- 
1.5.5.GIT
Message 1 of 1 in “t/test-lib.sh: resolve symlinks in working directory, for pathname comparisons”
  1. t/test-lib.sh: resolve symlinks in working directory, for pathname comparisonsLea Wiemann, May 31, 2008

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.