gitignore_check.sh 768 B

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