check_line_terminators.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. #
  3. # Copyright 2020 The Matrix.org Foundation C.I.C.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # This script checks that line terminators in all repository files (excluding
  18. # those in the .git directory) feature unix line terminators.
  19. #
  20. # Usage:
  21. #
  22. # ./check_line_terminators.sh
  23. #
  24. # The script will emit exit code 1 if any files that do not use unix line
  25. # terminators are found, 0 otherwise.
  26. # cd to the root of the repository
  27. cd `dirname $0`/..
  28. # Find and print files with non-unix line terminators
  29. if find . -path './.git/*' -prune -o -type f -print0 | xargs -0 grep -I -l $'\r$'; then
  30. echo -e '\e[31mERROR: found files with CRLF line endings. See above.\e[39m'
  31. exit 1
  32. fi