Merge branch 'ss/faq-fetch-pull'
[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 if test_have_prereq SYMLINKS
48 then
49         ln -s sub top
50 fi
51
52 mkdir -p sub/dir || exit 1
53 cd sub/dir || exit 1
54
55 unset GIT_CEILING_DIRECTORIES
56 test_prefix subdir_no_ceil "sub/dir/"
57
58 export GIT_CEILING_DIRECTORIES
59
60 GIT_CEILING_DIRECTORIES=""
61 test_prefix subdir_ceil_empty "sub/dir/"
62
63 GIT_CEILING_DIRECTORIES="$TRASH_ROOT"
64 test_fail subdir_ceil_at_trash
65
66 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/"
67 test_fail subdir_ceil_at_trash_slash
68
69 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub"
70 test_fail subdir_ceil_at_sub
71
72 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/"
73 test_fail subdir_ceil_at_sub_slash
74
75 if test_have_prereq SYMLINKS
76 then
77         GIT_CEILING_DIRECTORIES="$TRASH_ROOT/top"
78         test_fail subdir_ceil_at_top
79         GIT_CEILING_DIRECTORIES="$TRASH_ROOT/top/"
80         test_fail subdir_ceil_at_top_slash
81
82         GIT_CEILING_DIRECTORIES=":$TRASH_ROOT/top"
83         test_prefix subdir_ceil_at_top_no_resolve "sub/dir/"
84         GIT_CEILING_DIRECTORIES=":$TRASH_ROOT/top/"
85         test_prefix subdir_ceil_at_top_slash_no_resolve "sub/dir/"
86 fi
87
88 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/dir"
89 test_prefix subdir_ceil_at_subdir "sub/dir/"
90
91 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/dir/"
92 test_prefix subdir_ceil_at_subdir_slash "sub/dir/"
93
94
95 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su"
96 test_prefix subdir_ceil_at_su "sub/dir/"
97
98 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su/"
99 test_prefix subdir_ceil_at_su_slash "sub/dir/"
100
101 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/di"
102 test_prefix subdir_ceil_at_sub_di "sub/dir/"
103
104 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub/di"
105 test_prefix subdir_ceil_at_sub_di_slash "sub/dir/"
106
107 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi"
108 test_prefix subdir_ceil_at_subdi "sub/dir/"
109
110 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/subdi"
111 test_prefix subdir_ceil_at_subdi_slash "sub/dir/"
112
113
114 GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub"
115 test_fail second_of_two
116
117 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub:/bar"
118 test_fail first_of_two
119
120 GIT_CEILING_DIRECTORIES="/foo:$TRASH_ROOT/sub:/bar"
121 test_fail second_of_three
122
123
124 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sub"
125 GIT_DIR=../../.git
126 export GIT_DIR
127 test_prefix git_dir_specified ""
128 unset GIT_DIR
129
130
131 cd ../.. || exit 1
132 mkdir -p s/d || exit 1
133 cd s/d || exit 1
134
135 unset GIT_CEILING_DIRECTORIES
136 test_prefix sd_no_ceil "s/d/"
137
138 export GIT_CEILING_DIRECTORIES
139
140 GIT_CEILING_DIRECTORIES=""
141 test_prefix sd_ceil_empty "s/d/"
142
143 GIT_CEILING_DIRECTORIES="$TRASH_ROOT"
144 test_fail sd_ceil_at_trash
145
146 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/"
147 test_fail sd_ceil_at_trash_slash
148
149 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s"
150 test_fail sd_ceil_at_s
151
152 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/"
153 test_fail sd_ceil_at_s_slash
154
155 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/d"
156 test_prefix sd_ceil_at_sd "s/d/"
157
158 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/d/"
159 test_prefix sd_ceil_at_sd_slash "s/d/"
160
161
162 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su"
163 test_prefix sd_ceil_at_su "s/d/"
164
165 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/su/"
166 test_prefix sd_ceil_at_su_slash "s/d/"
167
168 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/di"
169 test_prefix sd_ceil_at_s_di "s/d/"
170
171 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/s/di"
172 test_prefix sd_ceil_at_s_di_slash "s/d/"
173
174 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sdi"
175 test_prefix sd_ceil_at_sdi "s/d/"
176
177 GIT_CEILING_DIRECTORIES="$TRASH_ROOT/sdi"
178 test_prefix sd_ceil_at_sdi_slash "s/d/"
179
180
181 test_done