From 3aada5dbccc7f42aa8d8f14e59b4ec6f8753bd11 Mon Sep 17 00:00:00 2001 From: azeemshatp Date: Thu, 6 Aug 2020 17:19:30 +0100 Subject: [PATCH] Fix trailing whitespace check in Windows and Linux Previous check in check.bat considered only uncommitted changes. --- check.bat | 16 +++++++++++----- check.sh | 8 +++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/check.bat b/check.bat index 6dc501a..d7529f0 100644 --- a/check.bat +++ b/check.bat @@ -1,10 +1,16 @@ @ECHO OFF -:: This batch file performs the same checks as TravisCI and should be run after each commit and before -:: pushing the commits +:: This batch file performs the same checks as TravisCI and should be run after each commit and +:: before pushing the commits echo "---------- Trailing whitespace check -------------" -REM git diff --check 'git rev-list --max-count=1 --reverse HEAD' ..$TRAVIS_BRANCH -git diff --check master +:: check uncommitted changes +git diff --check HEAD +if errorlevel 1 ( + echo Failure Reason is %errorlevel% + exit /b %errorlevel% +) +:: check all commits starting from initial commit +for /F %i in ('"git rev-list --max-parents=0 HEAD"') do git diff --check %i..HEAD if errorlevel 1 ( echo Failure Reason is %errorlevel% exit /b %errorlevel% @@ -31,4 +37,4 @@ if errorlevel 1 ( exit /b %errorlevel% ) -echo "---------- All tests passed -------------" \ No newline at end of file +echo "---------- All tests passed -------------" diff --git a/check.sh b/check.sh index 9690592..2fab31d 100755 --- a/check.sh +++ b/check.sh @@ -5,7 +5,13 @@ # echo "---------- Trailing whitespace check -------------" -git diff --check `git rev-list HEAD | tail -n 1`..$TRAVIS_BRANCH +# check uncommitted changes +git diff --check HEAD +if [ $? != 0 ]; then + exit 1; +fi +# check all commits starting from initial commit +git diff --check `git rev-list --max-parents=0 HEAD`..HEAD if [ $? != 0 ]; then exit 1; fi