checkout/__test__/verify-sparse-checkout.sh

41 lines
905 B
Bash
Raw Normal View History

2023-05-02 17:41:51 +00:00
#!/bin/bash
2023-05-02 19:08:06 +00:00
# Verify .git folder
if [ ! -d "./sparse-checkout/.git" ]; then
echo "Expected ./sparse-checkout/.git folder to exist"
exit 1
fi
2023-05-02 19:08:06 +00:00
# Verify sparse-checkout
cd sparse-checkout
2023-05-02 17:41:51 +00:00
2023-05-02 19:08:06 +00:00
checkSparse () {
if [ ! -d "./$1" ]; then
echo "Expected directory '$1' to exist"
2023-05-02 17:41:51 +00:00
exit 1
fi
2023-05-02 19:08:06 +00:00
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
}
2023-05-02 17:41:51 +00:00
2023-05-02 19:08:06 +00:00
# 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)
2023-05-02 17:41:51 +00:00
do
2023-05-02 19:08:06 +00:00
if [ -d "$pattern" ]; then
if [[ "$pattern" != "__test__" && "$pattern" != ".github" && "$pattern" != "dist" ]]; then
echo "Expected directory '$pattern' to not exist"
exit 1
fi
2023-05-02 17:41:51 +00:00
fi
done