gitignore_check.sh 787 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env sh
  2. set -uo pipefail
  3. shopt -s globstar
  4. echo -e ".gitignore validation..."
  5. # Get a list of files that exist in the repo but are ignored.
  6. # The --verbose flag also includes files un-ignored via ! prefixes.
  7. # We filter those out with a somewhat awkward `awk` directive.
  8. # (Explanation: Split each line by : delimiters,
  9. # see if the actual gitignore line shown in the third field starts with !,
  10. # if it doesn't, print it.)
  11. # ignorecase for the sake of Windows users.
  12. output=$(git -c core.ignorecase=true check-ignore --verbose --no-index **/* | \
  13. awk -F ':' '{ if ($3 !~ /^!/) print $0 }')
  14. # Then we take this result and return success if it's empty.
  15. if [ -z "$output" ]; then
  16. exit 0
  17. else
  18. # And print the result if it isn't.
  19. echo "$output"
  20. exit 1
  21. fi