@matheusbsbs / matheus-bagliano / commits / fc4045ee3e
Fork 0

t1510: setup case #0

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 26, 2010 at 22:31 UTC fc4045ee3eae49c829a466752da1937cfa13e048
1 file changed +51 -2
t/t1510-repo-setup.sh
+51 -2
@@ -41,8 +41,10 @@ test_description='Tests of cwd/prefix/worktree/gitdir setup in all cases'
41
42 test_repo() {
43 (
44 - if test -n "$1"; then cd "$1"; fi &&
45 - if test -f trace; then rm trace; fi &&
44 + cd "$1" &&
45 + if test -n "$2"; then GIT_DIR="$2" && export GIT_DIR; fi &&
46 + if test -n "$3"; then GIT_WORK_TREE="$3" && export GIT_WORK_TREE; fi &&
47 + rm -f trace &&
48 GIT_TRACE="`pwd`/trace" git symbolic-ref HEAD >/dev/null &&
49 grep '^setup: ' trace >result &&
50 test_cmp expected result
@@ -56,4 +58,51 @@ test_repo() {
58 # Bit 4 = bare repo
59 # Case# = encoding of the above 5 bits
60
61 +#
62 +# Case #0
63 +#
64 +############################################################
65 +#
66 +# Input:
67 +#
68 +# - GIT_WORK_TREE is not set
69 +# - GIT_DIR is not set
70 +# - core.worktree is not set
71 +# - .git is a directory
72 +# - core.bare is not set, cwd is outside .git
73 +#
74 +# Output:
75 +#
76 +# - worktree is .git's parent directory
77 +# - cwd is at worktree root dir
78 +# - prefix is calculated
79 +# - git_dir is set to ".git"
80 +# - cwd can't be outside worktree
81 +
82 +test_expect_success '#0: setup' '
83 + unset GIT_DIR GIT_WORK_TREE &&
84 + mkdir 0 0/sub &&
85 + cd 0 && git init && cd ..
86 +'
87 +
88 +test_expect_success '#0: at root' '
89 + cat >0/expected <<EOF &&
90 +setup: git_dir: .git
91 +setup: worktree: $TRASH_DIRECTORY/0
92 +setup: cwd: $TRASH_DIRECTORY/0
93 +setup: prefix: (null)
94 +EOF
95 + test_repo 0
96 +'
97 +
98 +test_expect_success '#0: in subdir' '
99 + cat >0/sub/expected <<EOF &&
100 +setup: git_dir: .git
101 +setup: worktree: $TRASH_DIRECTORY/0
102 +setup: cwd: $TRASH_DIRECTORY/0
103 +setup: prefix: sub/
104 +EOF
105 + test_repo 0/sub
106 +'
107 +
108 test_done