131
ROOT="$(pwd)"
132
fi
133
134
-test_expect_success 'setup for __gitdir tests' '
134
+test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
135
mkdir -p subdir/subsubdir &&
136
+ mkdir -p non-repo &&
137
git init otherrepo
138
'
139
139
-test_expect_success '__gitdir - from command line (through $__git_dir)' '
140
+test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
141
echo "$ROOT/otherrepo/.git" >expected &&
142
(
143
__git_dir="$ROOT/otherrepo/.git" &&
143
- __gitdir >"$actual"
144
- ) &&
145
- test_cmp expected "$actual"
146
-'
147
-
148
-test_expect_success '__gitdir - repo as argument' '
149
- echo "otherrepo/.git" >expected &&
150
- (
151
- __gitdir "otherrepo" >"$actual"
144
+ __git_find_repo_path &&
145
+ echo "$__git_repo_path" >"$actual"
146
) &&
147
test_cmp expected "$actual"
148
'
149
156
-test_expect_success '__gitdir - remote as argument' '
157
- echo "remote" >expected &&
158
- (
159
- __gitdir "remote" >"$actual"
160
- ) &&
161
- test_cmp expected "$actual"
162
-'
163
-
164
-test_expect_success '__gitdir - .git directory in cwd' '
150
+test_expect_success '__git_find_repo_path - .git directory in cwd' '
151
echo ".git" >expected &&
152
(
167
- __gitdir >"$actual"
153
+ __git_find_repo_path &&
154
+ echo "$__git_repo_path" >"$actual"
155
) &&
156
test_cmp expected "$actual"
157
'
158
172
-test_expect_success '__gitdir - .git directory in parent' '
159
+test_expect_success '__git_find_repo_path - .git directory in parent' '
160
echo "$ROOT/.git" >expected &&
161
(
162
cd subdir/subsubdir &&
176
- __gitdir >"$actual"
163
+ __git_find_repo_path &&
164
+ echo "$__git_repo_path" >"$actual"
165
) &&
166
test_cmp expected "$actual"
167
'
168
181
-test_expect_success '__gitdir - cwd is a .git directory' '
169
+test_expect_success '__git_find_repo_path - cwd is a .git directory' '
170
echo "." >expected &&
171
(
172
cd .git &&
185
- __gitdir >"$actual"
173
+ __git_find_repo_path &&
174
+ echo "$__git_repo_path" >"$actual"
175
) &&
176
test_cmp expected "$actual"
177
'
178
190
-test_expect_success '__gitdir - parent is a .git directory' '
179
+test_expect_success '__git_find_repo_path - parent is a .git directory' '
180
echo "$ROOT/.git" >expected &&
181
(
182
cd .git/refs/heads &&
194
- __gitdir >"$actual"
183
+ __git_find_repo_path &&
184
+ echo "$__git_repo_path" >"$actual"
185
) &&
186
test_cmp expected "$actual"
187
'
188
199
-test_expect_success '__gitdir - $GIT_DIR set while .git directory in cwd' '
189
+test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' '
190
echo "$ROOT/otherrepo/.git" >expected &&
191
(
192
GIT_DIR="$ROOT/otherrepo/.git" &&
193
export GIT_DIR &&
204
- __gitdir >"$actual"
194
+ __git_find_repo_path &&
195
+ echo "$__git_repo_path" >"$actual"
196
) &&
197
test_cmp expected "$actual"
198
'
199
209
-test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' '
200
+test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' '
201
echo "$ROOT/otherrepo/.git" >expected &&
202
(
203
GIT_DIR="$ROOT/otherrepo/.git" &&
204
export GIT_DIR &&
205
cd subdir &&
215
- __gitdir >"$actual"
206
+ __git_find_repo_path &&
207
+ echo "$__git_repo_path" >"$actual"
208
) &&
209
test_cmp expected "$actual"
210
'
211
220
-test_expect_success '__gitdir - from command line while "git -C"' '
212
+test_expect_success '__git_find_repo_path - from command line while "git -C"' '
213
echo "$ROOT/.git" >expected &&
214
(
215
__git_dir="$ROOT/.git" &&
216
__git_C_args=(-C otherrepo) &&
225
- __gitdir >"$actual"
217
+ __git_find_repo_path &&
218
+ echo "$__git_repo_path" >"$actual"
219
) &&
220
test_cmp expected "$actual"
221
'
222
230
-test_expect_success '__gitdir - relative dir from command line and "git -C"' '
223
+test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' '
224
echo "$ROOT/otherrepo/.git" >expected &&
225
(
226
cd subdir &&
227
__git_dir="otherrepo/.git" &&
228
__git_C_args=(-C ..) &&
236
- __gitdir >"$actual"
229
+ __git_find_repo_path &&
230
+ echo "$__git_repo_path" >"$actual"
231
) &&
232
test_cmp expected "$actual"
233
'
234
241
-test_expect_success '__gitdir - $GIT_DIR set while "git -C"' '
235
+test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' '
236
echo "$ROOT/.git" >expected &&
237
(
238
GIT_DIR="$ROOT/.git" &&
239
export GIT_DIR &&
240
__git_C_args=(-C otherrepo) &&
247
- __gitdir >"$actual"
241
+ __git_find_repo_path &&
242
+ echo "$__git_repo_path" >"$actual"
243
) &&
244
test_cmp expected "$actual"
245
'
246
252
-test_expect_success '__gitdir - relative dir in $GIT_DIR and "git -C"' '
247
+test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' '
248
echo "$ROOT/otherrepo/.git" >expected &&
249
(
250
cd subdir &&
251
GIT_DIR="otherrepo/.git" &&
252
export GIT_DIR &&
253
__git_C_args=(-C ..) &&
259
- __gitdir >"$actual"
254
+ __git_find_repo_path &&
255
+ echo "$__git_repo_path" >"$actual"
256
) &&
257
test_cmp expected "$actual"
258
'
259
264
-test_expect_success '__gitdir - "git -C" while .git directory in cwd' '
260
+test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' '
261
echo "$ROOT/otherrepo/.git" >expected &&
262
(
263
__git_C_args=(-C otherrepo) &&
268
- __gitdir >"$actual"
264
+ __git_find_repo_path &&
265
+ echo "$__git_repo_path" >"$actual"
266
) &&
267
test_cmp expected "$actual"
268
'
269
273
-test_expect_success '__gitdir - "git -C" while cwd is a .git directory' '
270
+test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' '
271
echo "$ROOT/otherrepo/.git" >expected &&
272
(
273
cd .git &&
274
__git_C_args=(-C .. -C otherrepo) &&
278
- __gitdir >"$actual"
275
+ __git_find_repo_path &&
276
+ echo "$__git_repo_path" >"$actual"
277
) &&
278
test_cmp expected "$actual"
279
'
280
283
-test_expect_success '__gitdir - "git -C" while .git directory in parent' '
281
+test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' '
282
echo "$ROOT/otherrepo/.git" >expected &&
283
(
284
cd subdir &&
285
__git_C_args=(-C .. -C otherrepo) &&
288
- __gitdir >"$actual"
286
+ __git_find_repo_path &&
287
+ echo "$__git_repo_path" >"$actual"
288
) &&
289
test_cmp expected "$actual"
290
'
291
293
-test_expect_success '__gitdir - non-existing path in "git -C"' '
292
+test_expect_success '__git_find_repo_path - non-existing path in "git -C"' '
293
(
294
__git_C_args=(-C non-existing) &&
296
- test_must_fail __gitdir >"$actual"
295
+ test_must_fail __git_find_repo_path &&
296
+ printf "$__git_repo_path" >"$actual"
297
) &&
298
test_must_be_empty "$actual"
299
'
300
301
-test_expect_success '__gitdir - non-existing path in $__git_dir' '
301
+test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' '
302
(
303
__git_dir="non-existing" &&
304
- test_must_fail __gitdir >"$actual"
304
+ test_must_fail __git_find_repo_path &&
305
+ printf "$__git_repo_path" >"$actual"
306
) &&
307
test_must_be_empty "$actual"
308
'
309
309
-test_expect_success '__gitdir - non-existing $GIT_DIR' '
310
+test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' '
311
(
312
GIT_DIR="$ROOT/non-existing" &&
313
export GIT_DIR &&
313
- test_must_fail __gitdir >"$actual"
314
+ test_must_fail __git_find_repo_path &&
315
+ printf "$__git_repo_path" >"$actual"
316
) &&
317
test_must_be_empty "$actual"
318
'
319
318
-test_expect_success '__gitdir - gitfile in cwd' '
320
+test_expect_success '__git_find_repo_path - gitfile in cwd' '
321
echo "$ROOT/otherrepo/.git" >expected &&
322
echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
323
test_when_finished "rm -f subdir/.git" &&
324
(
325
cd subdir &&
324
- __gitdir >"$actual"
326
+ __git_find_repo_path &&
327
+ echo "$__git_repo_path" >"$actual"
328
) &&
329
test_cmp expected "$actual"
330
'
331
329
-test_expect_success '__gitdir - gitfile in parent' '
332
+test_expect_success '__git_find_repo_path - gitfile in parent' '
333
echo "$ROOT/otherrepo/.git" >expected &&
334
echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
335
test_when_finished "rm -f subdir/.git" &&
336
(
337
cd subdir/subsubdir &&
335
- __gitdir >"$actual"
338
+ __git_find_repo_path &&
339
+ echo "$__git_repo_path" >"$actual"
340
) &&
341
test_cmp expected "$actual"
342
'
343
340
-test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
344
+test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' '
345
echo "$ROOT/otherrepo/.git" >expected &&
346
mkdir otherrepo/dir &&
347
test_when_finished "rm -rf otherrepo/dir" &&
349
test_when_finished "rm -f link" &&
350
(
351
cd link &&
352
+ __git_find_repo_path &&
353
+ echo "$__git_repo_path" >"$actual"
354
+ ) &&
355
+ test_cmp expected "$actual"
356
+'
357
+
358
+test_expect_success '__git_find_repo_path - not a git repository' '
359
+ (
360
+ cd non-repo &&
361
+ GIT_CEILING_DIRECTORIES="$ROOT" &&
362
+ export GIT_CEILING_DIRECTORIES &&
363
+ test_must_fail __git_find_repo_path &&
364
+ printf "$__git_repo_path" >"$actual"
365
+ ) &&
366
+ test_must_be_empty "$actual"
367
+'
368
+
369
+test_expect_success '__gitdir - finds repo' '
370
+ echo "$ROOT/.git" >expected &&
371
+ (
372
+ cd subdir/subsubdir &&
373
__gitdir >"$actual"
374
) &&
375
test_cmp expected "$actual"
376
'
377
353
-test_expect_success '__gitdir - not a git repository' '
354
- nongit test_must_fail __gitdir >"$actual" &&
378
+
379
+test_expect_success '__gitdir - returns error when cant find repo' '
380
+ (
381
+ __git_dir="non-existing" &&
382
+ test_must_fail __gitdir >"$actual"
383
+ ) &&
384
test_must_be_empty "$actual"
385
'
386
387
+test_expect_success '__gitdir - repo as argument' '
388
+ echo "otherrepo/.git" >expected &&
389
+ (
390
+ __gitdir "otherrepo" >"$actual"
391
+ ) &&
392
+ test_cmp expected "$actual"
393
+'
394
+
395
+test_expect_success '__gitdir - remote as argument' '
396
+ echo "remote" >expected &&
397
+ (
398
+ __gitdir "remote" >"$actual"
399
+ ) &&
400
+ test_cmp expected "$actual"
401
+'
402
+
403
test_expect_success '__gitcomp - trailing space - options' '
404
test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
405
--reset-author" <<-EOF