t9801: do not overuse test_must_fail
[git] / t / t1504-ceiling-dirs.sh
1 #!/bin/sh
2
3 test_description='test GIT_CEILING_DIRECTORIES'
4 . ./test-lib.sh
5
6 test_prefix() {
7         test_expect_success "$1" \
8         "test '$2' = \"\$(git rev-parse --show-prefix)\""
9 }
10
11 test_fail() {
12         test_expect_success "$1: prefix" '
13                 test_expect_code 128 git rev-parse --show-prefix
14         '
15 }
16
17 TRASH_ROOT="$PWD"
18 ROOT_PARENT=$(dirname "$TRASH_ROOT")
19
20
21 unset GIT_CEILING_DIRECTORIES
22 test_prefix no_ceil ""
23
24 export GIT_CEILING_DIRECTORIES
25
26 GIT_CEILING_DIRECTORIES=""
27 test_prefix ceil_empty ""
28
29 GIT_CEILING_DIRECTORIES="$ROOT_PARENT"
30 test_prefix ceil_at_parent ""
31
32 GIT_CEILING_DIRECTORIES="$ROOT_PARENT/"
33 test_prefix ceil_at_parent_slash ""
34
35 GIT_CEILING_DIRECTORIES="$TRASH_ROOT"
36 test_prefix ceil_at_trash ""
37
38 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/"
39 test_prefix ceil_at_trash_slash ""
40
41 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub"
42 test_prefix ceil_at_sub ""
43
44 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/"
45 test_prefix ceil_at_sub_slash ""
46
47
48 mkdir -p sub/dir || exit 1
49 cd sub/dir || exit 1
50
51 unset GIT_CEILING_DIRECTORIES
52 test_prefix subdir_no_ceil "sub/dir/"
53
54 export GIT_CEILING_DIRECTORIES
55
56 GIT_CEILING_DIRECTORIES=""
57 test_prefix subdir_ceil_empty "sub/dir/"
58
59 GIT_CEILING_DIRECTORIES="$TRASH_ROOT"
60 test_fail subdir_ceil_at_trash
61
62 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/"
63 test_fail subdir_ceil_at_trash_slash
64
65 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub"
66 test_fail subdir_ceil_at_sub
67
68 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/"
69 test_fail subdir_ceil_at_sub_slash
70
71 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/dir"
72 test_prefix subdir_ceil_at_subdir "sub/dir/"
73
74 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/dir/"
75 test_prefix subdir_ceil_at_subdir_slash "sub/dir/"
76
77
78 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su"
79 test_prefix subdir_ceil_at_su "sub/dir/"
80
81 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su/"
82 test_prefix subdir_ceil_at_su_slash "sub/dir/"
83
84 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/di"
85 test_prefix subdir_ceil_at_sub_di "sub/dir/"
86
87 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/di"
88 test_prefix subdir_ceil_at_sub_di_slash "sub/dir/"
89
90 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi"
91 test_prefix subdir_ceil_at_subdi "sub/dir/"
92
93 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi"
94 test_prefix subdir_ceil_at_subdi_slash "sub/dir/"
95
96
97 GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub"
98 test_fail second_of_two
99
100 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub:/bar"
101 test_fail first_of_two
102
103 GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub:/bar"
104 test_fail second_of_three
105
106
107 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub"
108 GIT_DIR=../../.git
109 export GIT_DIR
110 test_prefix git_dir_specified ""
111 unset GIT_DIR
112
113
114 cd ../.. || exit 1
115 mkdir -p s/d || exit 1
116 cd s/d || exit 1
117
118 unset GIT_CEILING_DIRECTORIES
119 test_prefix sd_no_ceil "s/d/"
120
121 export GIT_CEILING_DIRECTORIES
122
123 GIT_CEILING_DIRECTORIES=""
124 test_prefix sd_ceil_empty "s/d/"
125
126 GIT_CEILING_DIRECTORIES="$TRASH_ROOT"
127 test_fail sd_ceil_at_trash
128
129 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/"
130 test_fail sd_ceil_at_trash_slash
131
132 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s"
133 test_fail sd_ceil_at_s
134
135 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/"
136 test_fail sd_ceil_at_s_slash
137
138 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/d"
139 test_prefix sd_ceil_at_sd "s/d/"
140
141 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/d/"
142 test_prefix sd_ceil_at_sd_slash "s/d/"
143
144
145 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su"
146 test_prefix sd_ceil_at_su "s/d/"
147
148 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su/"
149 test_prefix sd_ceil_at_su_slash "s/d/"
150
151 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/di"
152 test_prefix sd_ceil_at_s_di "s/d/"
153
154 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/di"
155 test_prefix sd_ceil_at_s_di_slash "s/d/"
156
157 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sdi"
158 test_prefix sd_ceil_at_sdi "s/d/"
159
160 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sdi"
161 test_prefix sd_ceil_at_sdi_slash "s/d/"
162
163
164 test_done