From 397d008fc066694130fed8137891a6bb755ddeb2 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Wed, 2 Sep 2015 08:38:49 +0200
Subject: Restrict pre-commit copyright check to added files

Previously the pre-commit would require a correct copyright
header on all files, including modified files that only have a
couple lines changed.
Now, a correct copyright file header is only required on new files
added to the repository.

Test-Information:

Changed git author information to a new user and tried committing
a changed file, and afterwards a new file. Only the commit of a
new file failed due to missing copyright header. It was accepted
after setting BSD header.

Change-Id: I8e1324846fd904a72728e7c01da4c98f49a77282

diff --git a/BuildTools/Git/Hooks/pre-commit b/BuildTools/Git/Hooks/pre-commit
index ad0945e..987f127 100755
--- a/BuildTools/Git/Hooks/pre-commit
+++ b/BuildTools/Git/Hooks/pre-commit
@@ -4,6 +4,15 @@ IFS='
 '
 
 echo "Checking tabs & copyrights ..."
+for file in $(git diff --cached --diff-filter=A --name-only); do
+	if [ ! -f $file ]; then
+		continue
+	fi
+	if ! BuildTools/Copyrighter.py check-copyright $file; then
+		echo "ERROR: '$file' has a copyright error. Aborting commit."
+		exit -1
+	fi
+done
 for file in $(git diff --cached --name-only); do
 	if [ ! -f $file ]; then
 		continue
@@ -12,10 +21,6 @@ for file in $(git diff --cached --name-only); do
 		echo "ERROR: '$file' contains expanded tabs. Aborting commit."
 		exit -1
 	fi
-	if ! BuildTools/Copyrighter.py check-copyright $file; then
-		echo "ERROR: '$file' has a copyright error. Aborting commit."
-		exit -1
-	fi
 	if ! BuildTools/CheckHeaders.py $file; then
 		echo "ERROR: '$file' failed header sanity test. Aborting commit."
 		exit -1
-- 
cgit v0.10.2-6-g49f6