Skip to content

Commit a4f7a6d

Browse files
committed
t0003: use --git-dir for bare repo attribute tests
The bare repo tests in t0003-attributes.sh currently `cd` into the bare repository inside subshells, relying on implicit discovery. Restructure these tests to pass `--git-dir=bare.git` to the `attr_check` and `attr_check_source` helpers instead. This makes the code much easier to read, and also makes bare repo access explicit, i.e. compatible with an eventual `safe.bareRepository=explicit` default. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 7874460 commit a4f7a6d

1 file changed

Lines changed: 27 additions & 39 deletions

File tree

t/t0003-attributes.sh

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,14 @@ test_expect_success 'setup bare' '
346346

347347
test_expect_success 'bare repository: check that .gitattribute is ignored' '
348348
(
349-
cd bare.git &&
350-
(
351-
echo "f test=f" &&
352-
echo "a/i test=a/i"
353-
) >.gitattributes &&
354-
attr_check f unspecified &&
355-
attr_check a/f unspecified &&
356-
attr_check a/c/f unspecified &&
357-
attr_check a/i unspecified &&
358-
attr_check subdir/a/i unspecified
359-
)
349+
echo "f test=f" &&
350+
echo "a/i test=a/i"
351+
) >bare.git/.gitattributes &&
352+
attr_check f unspecified --git-dir=bare.git &&
353+
attr_check a/f unspecified --git-dir=bare.git &&
354+
attr_check a/c/f unspecified --git-dir=bare.git &&
355+
attr_check a/i unspecified --git-dir=bare.git &&
356+
attr_check subdir/a/i unspecified --git-dir=bare.git
360357
'
361358

362359
bad_attr_source_err="fatal: bad --attr-source or GIT_ATTR_SOURCE"
@@ -449,41 +446,32 @@ test_expect_success 'diff without repository with attr source' '
449446
'
450447

451448
test_expect_success 'bare repository: with --source' '
452-
(
453-
cd bare.git &&
454-
attr_check_source foo/bar/f f tag-1 &&
455-
attr_check_source foo/bar/a/i n tag-1 &&
456-
attr_check_source foo/bar/f unspecified tag-2 &&
457-
attr_check_source foo/bar/a/i m tag-2 &&
458-
attr_check_source foo/bar/g g tag-2 &&
459-
attr_check_source foo/bar/g unspecified tag-1
460-
)
449+
attr_check_source foo/bar/f f tag-1 --git-dir=bare.git &&
450+
attr_check_source foo/bar/a/i n tag-1 --git-dir=bare.git &&
451+
attr_check_source foo/bar/f unspecified tag-2 --git-dir=bare.git &&
452+
attr_check_source foo/bar/a/i m tag-2 --git-dir=bare.git &&
453+
attr_check_source foo/bar/g g tag-2 --git-dir=bare.git &&
454+
attr_check_source foo/bar/g unspecified tag-1 --git-dir=bare.git
461455
'
462456

463457
test_expect_success 'bare repository: check that --cached honors index' '
464-
(
465-
cd bare.git &&
466-
GIT_INDEX_FILE=../.git/index \
467-
git check-attr --cached --stdin --all <../stdin-all |
468-
sort >actual &&
469-
test_cmp ../specified-all actual
470-
)
458+
GIT_INDEX_FILE=.git/index \
459+
git --git-dir=bare.git check-attr --cached --stdin --all <stdin-all |
460+
sort >actual &&
461+
test_cmp specified-all actual
471462
'
472463

473464
test_expect_success 'bare repository: test info/attributes' '
465+
mkdir -p bare.git/info &&
474466
(
475-
cd bare.git &&
476-
mkdir info &&
477-
(
478-
echo "f test=f" &&
479-
echo "a/i test=a/i"
480-
) >info/attributes &&
481-
attr_check f f &&
482-
attr_check a/f f &&
483-
attr_check a/c/f f &&
484-
attr_check a/i a/i &&
485-
attr_check subdir/a/i unspecified
486-
)
467+
echo "f test=f" &&
468+
echo "a/i test=a/i"
469+
) >bare.git/info/attributes &&
470+
attr_check f f --git-dir=bare.git &&
471+
attr_check a/f f --git-dir=bare.git &&
472+
attr_check a/c/f f --git-dir=bare.git &&
473+
attr_check a/i a/i --git-dir=bare.git &&
474+
attr_check subdir/a/i unspecified --git-dir=bare.git
487475
'
488476

489477
test_expect_success 'binary macro expanded by -a' '

0 commit comments

Comments
 (0)