From 16b7f0a14ca6d1db02c07de1466f602889cb229a Mon Sep 17 00:00:00 2001
From: Nick Kralevich <nnk@google.com>
Date: Fri, 9 Dec 2016 20:35:34 -0800
Subject: [PATCH] Block files without trailing newlines

Add a pre-submit check to ensure that files have a newline character at
the end.

Please see https://android.googlesource.com/platform/tools/repohooks/
for documentation on how PREUPLOAD hooks work.

Test: created a change and watched the presubmit check reject it.
Change-Id: Id0528cb1bd6fa9c4483ba43720839832f4fec34d
---
 PREUPLOAD.cfg       |  2 ++
 tools/whitespace.sh | 13 +++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 PREUPLOAD.cfg
 create mode 100755 tools/whitespace.sh

diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 000000000..468243a2c
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,2 @@
+[Hook Scripts]
+whitespace = tools/whitespace.sh ${PREUPLOAD_FILES}
diff --git a/tools/whitespace.sh b/tools/whitespace.sh
new file mode 100755
index 000000000..5fb4a2f4e
--- /dev/null
+++ b/tools/whitespace.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+RESULT=0
+
+for i in "$@"; do
+  a="`tail -c 1 "$i"`"
+  if [ "$a" != "" ]; then
+    echo "$i does not have a trailing newline" 1>&2
+    RESULT=-1
+  fi
+done
+
+exit $RESULT
-- 
GitLab