| Geoffrey Martin-Noble | ebc6a83 | 2020-08-25 12:08:52 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Copyright 2020 The IREE Authors |
| Geoffrey Martin-Noble | ebc6a83 | 2020-08-25 12:08:52 -0700 | [diff] [blame] | 4 | # |
| Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 5 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 6 | # See https://llvm.org/LICENSE.txt for license information. |
| 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Geoffrey Martin-Noble | ebc6a83 | 2020-08-25 12:08:52 -0700 | [diff] [blame] | 8 | |
| 9 | # Checks for tabs in files modified vs the specified reference commit (default |
| 10 | # "main") |
| 11 | |
| 12 | set -o pipefail |
| 13 | |
| 14 | BASE_REF="${1:-main}" |
| 15 | |
| 16 | declare -a excluded_files_patterns=( |
| Stella Laurenzo | a4137ef | 2020-12-09 21:28:08 -0800 | [diff] [blame] | 17 | "^\.gitmodules$" |
| Geoffrey Martin-Noble | ebc6a83 | 2020-08-25 12:08:52 -0700 | [diff] [blame] | 18 | "/third_party/" |
| 19 | "^third_party/" |
| 20 | ) |
| 21 | |
| 22 | # Join on | |
| 23 | excluded_files_pattern="$(IFS="|" ; echo "${excluded_files_patterns[*]?}")" |
| 24 | |
| 25 | readarray -t files < <(\ |
| Geoffrey Martin-Noble | 6ef77d9 | 2020-09-03 10:18:08 -0700 | [diff] [blame] | 26 | (git diff --name-only --diff-filter=d "${BASE_REF}" || kill $$) \ |
| Geoffrey Martin-Noble | ebc6a83 | 2020-08-25 12:08:52 -0700 | [diff] [blame] | 27 | | grep -v -E "${excluded_files_pattern?}") |
| 28 | |
| Geoffrey Martin-Noble | 0405827 | 2021-05-04 16:10:18 -0700 | [diff] [blame] | 29 | diff="$(grep --with-filename --line-number --perl-regexp --binary-files=without-match '\t' "${files[@]}")" |
| Geoffrey Martin-Noble | ebc6a83 | 2020-08-25 12:08:52 -0700 | [diff] [blame] | 30 | |
| 31 | grep_exit="$?" |
| 32 | |
| 33 | if (( "${grep_exit?}" >= 2 )); then |
| 34 | exit "${grep_exit?}" |
| 35 | fi |
| 36 | |
| 37 | if (( "${grep_exit?}" == 0 )); then |
| 38 | echo "Changed files include tabs. Please use spaces."; |
| 39 | echo "$diff" |
| 40 | exit 1; |
| 41 | fi |