check_filename_spaces.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. # Copyright 2019 Google
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Fail on spaces in file names, excluding the patterns listed below.
  16. # A sed program that removes filename patterns that are allowed to have spaces
  17. # in them.
  18. function remove_valid_names() {
  19. sed '
  20. # Xcode-generated asset files
  21. /Assets.xcassets/ d
  22. # Files without spaces
  23. /^[^ ]*$/ d
  24. '
  25. }
  26. count=$(git ls-files | remove_valid_names | wc -l | xargs)
  27. if [[ ${count} != 0 ]]; then
  28. echo 'ERROR: Spaces in filenames are not permitted in this repo. Please fix.'
  29. echo ''
  30. git ls-files | remove_valid_names
  31. exit 1
  32. fi