t2300-cd-to-toplevel.sh 911 字节
Newer Older
1 2 3 4 5 6
#!/bin/sh

test_description='cd_to_toplevel'

. ./test-lib.sh

7 8 9 10 11 12 13 14
EXEC_PATH="$(git --exec-path)"
test_have_prereq !MINGW ||
case "$EXEC_PATH" in
[A-Za-z]:/*)
	EXEC_PATH="/${EXEC_PATH%%:*}${EXEC_PATH#?:}"
	;;
esac

15
test_cd_to_toplevel () {
16
	test_expect_success $3 "$2" '
17 18
		(
			cd '"'$1'"' &&
19
			PATH="$EXEC_PATH:$PATH" &&
20
			. git-sh-setup &&
21
			cd_to_toplevel &&
22
			[ "$(pwd -P)" = "$TOPLEVEL" ]
23 24 25 26
		)
	'
}

27
TOPLEVEL="$(pwd -P)/repo"
28 29 30 31 32 33 34 35
mkdir -p repo/sub/dir
mv .git repo/
SUBDIRECTORY_OK=1

test_cd_to_toplevel repo 'at physical root'

test_cd_to_toplevel repo/sub/dir 'at physical subdir'

36 37
ln -s repo symrepo 2>/dev/null
test_cd_to_toplevel symrepo 'at symbolic root' SYMLINKS
38

39 40
ln -s repo/sub/dir subdir-link 2>/dev/null
test_cd_to_toplevel subdir-link 'at symbolic subdir' SYMLINKS
41 42

cd repo
43 44
ln -s sub/dir internal-link 2>/dev/null
test_cd_to_toplevel internal-link 'at internal symbolic subdir' SYMLINKS
45 46

test_done