t0001: fix on case-insensitive filesystems

On a case-insensitive filesystem, such as HFS+ or NTFS, it is possible that the idea Bash has of the current directory differs in case from what Git thinks it is. That's totally okay, though, and we should not expect otherwise. On Windows, for example, when you call cd C:\GIT-SDK-64 in a PowerShell and there exists a directory called `C:\git-sdk-64`, the current directory will be reported in all upper-case. Even in a Bash that you might call from that PowerShell. Git, however, will have normalized this via `GetFinalPathByHandle()`, and the expectation in t0001 that the recorded gitdir will match what `pwd` says will be violated. Let's address this by comparing these paths in a case-insensitive manner when `core.ignoreCase` is `true`. Reported by Jameson Miller. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 24, 2019 at 19:40 UTC ed33bd8f305fd62c87059aa227b99d2411e8eabc
2 files changed +23 -14
t/t0001-init.sh
+8 -14
@@ -311,8 +311,8 @@ test_expect_success 'init prefers command line to GIT_DIR' '
311 test_expect_success 'init with separate gitdir' '
312 rm -rf newdir &&
313 git init --separate-git-dir realgitdir newdir &&
314 - echo "gitdir: $(pwd)/realgitdir" >expected &&
315 - test_cmp expected newdir/.git &&
314 + newdir_git="$(cat newdir/.git)" &&
315 + test_cmp_fspath "$(pwd)/realgitdir" "${newdir_git#gitdir: }" &&
316 test_path_is_dir realgitdir/refs
317 '
318
@@ -361,12 +361,9 @@ test_expect_success 're-init on .git file' '
361 '
362
363 test_expect_success 're-init to update git link' '
364 - (
365 - cd newdir &&
366 - git init --separate-git-dir ../surrealgitdir
367 - ) &&
368 - echo "gitdir: $(pwd)/surrealgitdir" >expected &&
369 - test_cmp expected newdir/.git &&
364 + git -C newdir init --separate-git-dir ../surrealgitdir &&
365 + newdir_git="$(cat newdir/.git)" &&
366 + test_cmp_fspath "$(pwd)/surrealgitdir" "${newdir_git#gitdir: }" &&
367 test_path_is_dir surrealgitdir/refs &&
368 test_path_is_missing realgitdir/refs
369 '
@@ -374,12 +371,9 @@ test_expect_success 're-init to update git link' '
371 test_expect_success 're-init to move gitdir' '
372 rm -rf newdir realgitdir surrealgitdir &&
373 git init newdir &&
377 - (
378 - cd newdir &&
379 - git init --separate-git-dir ../realgitdir
380 - ) &&
381 - echo "gitdir: $(pwd)/realgitdir" >expected &&
382 - test_cmp expected newdir/.git &&
374 + git -C newdir init --separate-git-dir ../realgitdir &&
375 + newdir_git="$(cat newdir/.git)" &&
376 + test_cmp_fspath "$(pwd)/realgitdir" "${newdir_git#gitdir: }" &&
377 test_path_is_dir realgitdir/refs
378 '
379
t/test-lib-functions.sh
+15
@@ -888,6 +888,21 @@ test_cmp_rev () {
888 fi
889 }
890
891 +# Compare paths respecting core.ignoreCase
892 +test_cmp_fspath () {
893 + if test "x$1" = "x$2"
894 + then
895 + return 0
896 + fi
897 +
898 + if test true != "$(git config --get --type=bool core.ignorecase)"
899 + then
900 + return 1
901 + fi
902 +
903 + test "x$(echo "$1" | tr A-Z a-z)" = "x$(echo "$2" | tr A-Z a-z)"
904 +}
905 +
906 # Print a sequence of integers in increasing order, either with
907 # two arguments (start and end):
908 #