Skip to content

Commit

Permalink
feat: refactor on sparse-checkout test
Browse files Browse the repository at this point in the history
  • Loading branch information
dfdez committed May 2, 2023
1 parent a910f4b commit eea6d0e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
9 changes: 9 additions & 0 deletions __test__/verify-sparse-checkout-basic.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/bash

# Verify .git folder
if [ ! -d "./sparse-checkout/.git" ]; then
echo "Expected ./sparse-checkout/.git folder to exist"
exit 1
fi

# Verify sparse-checkout basic
cd sparse-checkout

SPARSE=$(git sparse-checkout list)

if [ "$?" != "0" ]; then
Expand Down
69 changes: 28 additions & 41 deletions __test__/verify-sparse-checkout.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,41 @@
#!/bin/bash

# Check that only sparse-checkout folders has been fetched
for pattern in $(git ls-tree --name-only HEAD)
do
if [ -d "$pattern" ]; then
if [[ "$pattern" != "__test__" && "$pattern" != ".github" && "$pattern" != "dist" ]]; then
echo "Expected directory '$pattern' to not exist"
exit 1
fi
fi
done

# Check that .github and its childrens has been fetched correctly
if [ ! -d "./__test__" ]; then
echo "Expected directory '__test__' to exist"
# Verify .git folder
if [ ! -d "./sparse-checkout/.git" ]; then
echo "Expected ./sparse-checkout/.git folder to exist"
exit 1
fi

for file in $(git ls-tree -r --name-only HEAD __test__)
do
if [ ! -f "$file" ]; then
echo "Expected file '$file' to exist"
exit 1
fi
done

# Check that .github and its childrens has been fetched correctly
if [ ! -d "./.github" ]; then
echo "Expected directory '.github' to exist"
exit 1
fi
# Verify sparse-checkout
cd sparse-checkout

for file in $(git ls-tree -r --name-only HEAD .github)
do
if [ ! -f "$file" ]; then
echo "Expected file '$file' to exist"
checkSparse () {
if [ ! -d "./$1" ]; then
echo "Expected directory '$1' to exist"
exit 1
fi
done

# Check that dist and its childrens has been fetched correctly
if [ ! -d "./dist" ]; then
echo "Expected directory 'dist' to exist"
exit 1
fi
for file in $(git ls-tree -r --name-only HEAD $1)
do
if [ ! -f "$file" ]; then
echo "Expected file '$file' to exist"
exit 1
fi
done
}

for file in $(git ls-tree -r --name-only HEAD dist)
# Check that all folders and its childrens has been fetched correctly
checkSparse __test__
checkSparse .github
checkSparse dist

# Check that only sparse-checkout folders has been fetched
for pattern in $(git ls-tree --name-only HEAD)
do
if [ ! -f "$file" ]; then
echo "Expected file '$file' to exist"
exit 1
if [ -d "$pattern" ]; then
if [[ "$pattern" != "__test__" && "$pattern" != ".github" && "$pattern" != "dist" ]]; then
echo "Expected directory '$pattern' to not exist"
exit 1
fi
fi
done

0 comments on commit eea6d0e

Please sign in to comment.