File tree Expand file tree Collapse file tree 1 file changed +35
-16
lines changed
Expand file tree Collapse file tree 1 file changed +35
-16
lines changed Original file line number Diff line number Diff line change 1- #! /bin/bash
1+ #! /usr/bin/env bash
2+ #
3+ # This is based upon another script which had the following license:
24#
35# Copyright (c) 2010, Benjamin C. Meyer <ben@meyerhome.net>
46# All rights reserved.
2628# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2729#
2830
29- set -e
31+ # shellcheck disable=SC2034
32+ GREP_OPTIONS=" "
33+
34+ function test_file {
35+ file=" ${1} "
3036
31- function run_test {
32- if git rev-parse --verify HEAD > /dev/null 2>&1 ; then
33- head=" HEAD"
34- else
35- # First commit, use an empty tree
36- head=" 4b825dc642cb6eb9a060e54bf8d69288fbee4904"
37- fi
38- git diff-index --check --cached " ${head} " --
37+ if [ ! -f " ${file} " ] ; then
38+ return
39+ fi
40+
41+ echo " Running whitespace lint..."
42+ # Set -e before and +e after for _required_ linters (i.e.: that will prevent
43+ # commit, e.g.: syntax linters).
44+ # Set +e before and -e after for _optional_ linters (i.e.: that will only
45+ # output messages upon commit, e.g.: style linters).
46+ set +e
47+ if git rev-parse --verify HEAD > /dev/null 2>&1 ; then
48+ head=" HEAD"
49+ else
50+ # First commit, use an empty tree
51+ head=" 4b825dc642cb6eb9a060e54bf8d69288fbee4904"
52+ fi
53+ git diff-index --check --cached " ${head} " -- " $file "
54+ set -e
3955}
4056
4157case " ${1} " in
42- --about )
43- echo " Check for introduced trailing whitespace or an indent that uses a space before a tab."
44- ;;
45- * )
46- run_test
47- ;;
58+ --about )
59+ echo " Check for introduced trailing whitespace or an indent that uses a space before a tab."
60+ ;;
61+
62+ * )
63+ for file in $( git diff-index --cached --name-only HEAD | grep -v -E ' \.(gif|gz|ico|jpeg|jpg|png|phar|exe|svgz|tff)' ) ; do
64+ test_file " ${file} "
65+ done
66+ ;;
4867esac
You can’t perform that action at this time.
0 commit comments