Skip to content

Commit eedf8f9

Browse files
cworth-ghJunio C Hamano
authored andcommitted
Abstract test_create_repo out for use in tests.
Signed-off-by: Carl Worth <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41ff7a1 commit eedf8f9

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

t/test-lib.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ test_expect_code () {
149149
fi
150150
}
151151

152+
# Most tests can use the created repository, but some amy need to create more.
153+
# Usage: test_create_repo <directory>
154+
test_create_repo () {
155+
test "$#" = 1 ||
156+
error "bug in the test script: not 1 parameter to test-create-repo"
157+
owd=`pwd`
158+
repo="$1"
159+
mkdir "$repo"
160+
cd "$repo" || error "Cannot setup test environment"
161+
"$GIT_EXEC_PATH/git" init-db --template=$GIT_EXEC_PATH/templates/blt/ 2>/dev/null ||
162+
error "cannot run git init-db -- have you built things yet?"
163+
mv .git/hooks .git/hooks-disabled
164+
cd "$owd"
165+
}
166+
152167
test_done () {
153168
trap - exit
154169
case "$test_failure" in
@@ -196,9 +211,5 @@ test -d ../templates/blt || {
196211
# Test repository
197212
test=trash
198213
rm -fr "$test"
199-
mkdir "$test"
200-
cd "$test" || error "Cannot setup test environment"
201-
"$GIT_EXEC_PATH/git" init-db --template=../../templates/blt/ 2>/dev/null ||
202-
error "cannot run git init-db -- have you built things yet?"
203-
204-
mv .git/hooks .git/hooks-disabled
214+
test_create_repo $test
215+
cd "$test"

0 commit comments

Comments
 (0)