blob: 3826dbaf4ba2fd11dce9570549cbea2a34b33924 [file] [log] [blame]
Geoffrey Martin-Nobleebc6a832020-08-25 12:08:52 -07001#!/bin/bash
2
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07003# Copyright 2020 The IREE Authors
Geoffrey Martin-Nobleebc6a832020-08-25 12:08:52 -07004#
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07005# 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-Nobleebc6a832020-08-25 12:08:52 -07008
9# Checks for tabs in files modified vs the specified reference commit (default
10# "main")
11
12set -o pipefail
13
14BASE_REF="${1:-main}"
15
16declare -a excluded_files_patterns=(
Stella Laurenzoa4137ef2020-12-09 21:28:08 -080017 "^\.gitmodules$"
Geoffrey Martin-Nobleebc6a832020-08-25 12:08:52 -070018 "/third_party/"
19 "^third_party/"
20)
21
22# Join on |
23excluded_files_pattern="$(IFS="|" ; echo "${excluded_files_patterns[*]?}")"
24
25readarray -t files < <(\
Geoffrey Martin-Noble6ef77d92020-09-03 10:18:08 -070026 (git diff --name-only --diff-filter=d "${BASE_REF}" || kill $$) \
Geoffrey Martin-Nobleebc6a832020-08-25 12:08:52 -070027 | grep -v -E "${excluded_files_pattern?}")
28
Geoffrey Martin-Noble04058272021-05-04 16:10:18 -070029diff="$(grep --with-filename --line-number --perl-regexp --binary-files=without-match '\t' "${files[@]}")"
Geoffrey Martin-Nobleebc6a832020-08-25 12:08:52 -070030
31grep_exit="$?"
32
33if (( "${grep_exit?}" >= 2 )); then
34 exit "${grep_exit?}"
35fi
36
37if (( "${grep_exit?}" == 0 )); then
38 echo "Changed files include tabs. Please use spaces.";
39 echo "$diff"
40 exit 1;
41fi