verify-sparse-checkout.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # Verify .git folder
  3. if [ ! -d "./sparse-checkout/.git" ]; then
  4. echo "Expected ./sparse-checkout/.git folder to exist"
  5. exit 1
  6. fi
  7. # Verify sparse-checkout
  8. cd sparse-checkout
  9. SPARSE=$(git sparse-checkout list)
  10. if [ "$?" != "0" ]; then
  11. echo "Failed to validate sparse-checkout"
  12. exit 1
  13. fi
  14. # Check that sparse-checkout list is not empty
  15. if [ -z "$SPARSE" ]; then
  16. echo "Expected sparse-checkout list to not be empty"
  17. exit 1
  18. fi
  19. # Check that all folders of the sparse checkout exist
  20. for pattern in $SPARSE
  21. do
  22. if [ ! -d "$pattern" ]; then
  23. echo "Expected directory '$pattern' to exist"
  24. exit 1
  25. fi
  26. done
  27. checkSparse () {
  28. if [ ! -d "./$1" ]; then
  29. echo "Expected directory '$1' to exist"
  30. exit 1
  31. fi
  32. for file in $(git ls-tree -r --name-only HEAD $1)
  33. do
  34. if [ ! -f "$file" ]; then
  35. echo "Expected file '$file' to exist"
  36. exit 1
  37. fi
  38. done
  39. }
  40. # Check that all folders and their children have been checked out
  41. checkSparse __test__
  42. checkSparse .github
  43. checkSparse dist
  44. # Check that only sparse-checkout folders have been checked out
  45. for pattern in $(git ls-tree --name-only HEAD)
  46. do
  47. if [ -d "$pattern" ]; then
  48. if [[ "$pattern" != "__test__" && "$pattern" != ".github" && "$pattern" != "dist" ]]; then
  49. echo "Expected directory '$pattern' to not exist"
  50. exit 1
  51. fi
  52. fi
  53. done