]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2300-cd-to-toplevel.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t2300-cd-to-toplevel.sh
1 #!/bin/sh
2
3 test_description='cd_to_toplevel'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 EXEC_PATH="$(git --exec-path)"
9 test_have_prereq !MINGW ||
10 case "$EXEC_PATH" in
11 [A-Za-z]:/*)
12 EXEC_PATH="/${EXEC_PATH%%:*}${EXEC_PATH#?:}"
13 ;;
14 esac
15
16 test_cd_to_toplevel () {
17 test_expect_success $3 "$2" '
18 (
19 cd '"'$1'"' &&
20 PATH="$EXEC_PATH:$PATH" &&
21 . git-sh-setup &&
22 cd_to_toplevel &&
23 [ "$(pwd -P)" = "$TOPLEVEL" ]
24 )
25 '
26 }
27
28 TOPLEVEL="$(pwd -P)/repo"
29 mkdir -p repo/sub/dir
30 mv .git repo/
31 SUBDIRECTORY_OK=1
32
33 test_cd_to_toplevel repo 'at physical root'
34
35 test_cd_to_toplevel repo/sub/dir 'at physical subdir'
36
37 ln -s repo symrepo 2>/dev/null
38 test_cd_to_toplevel symrepo 'at symbolic root' SYMLINKS
39
40 ln -s repo/sub/dir subdir-link 2>/dev/null
41 test_cd_to_toplevel subdir-link 'at symbolic subdir' SYMLINKS
42
43 cd repo
44 ln -s sub/dir internal-link 2>/dev/null
45 test_cd_to_toplevel internal-link 'at internal symbolic subdir' SYMLINKS
46
47 test_done