[X2Go-Commits] [maintenancescripts] 02/03: git/hooks/common.sh: add

git-admin at x2go.org git-admin at x2go.org
Mon Feb 23 22:44:53 CET 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository maintenancescripts.

commit 43c2b37eee3102faf895dabc769fd276aa2e36bc
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Mon Feb 23 22:17:09 2015 +0100

    git/hooks/common.sh: add
    
      - deny()
      - echoerr()
      - echowarn()
      - is_text_file()
      - check_log_message()
      - check_trailing_whitespace()
      - check_ending_newline()
      - check_tabs()
      - check_dos_linebreaks()
    
    functions.
---
 git/hooks/common.sh |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/git/hooks/common.sh b/git/hooks/common.sh
index 6c6100f..c350386 100755
--- a/git/hooks/common.sh
+++ b/git/hooks/common.sh
@@ -45,3 +45,77 @@ function info () {
   [ "$(make_boolean "${verbose}")" = "1" ] && echo "-Info-          ${1}" >&2
 }
 
+function deny () {
+  [ "$(make_boolean "${verbose}")" = "1" ] && echo "-Deny-          ${1}" >&2
+  echo deny
+  exit 1
+}
+
+function echoerr () {
+  echo "-Deny-          ${@}" >&2
+}
+
+function echowarn () {
+  echo "-Warn-          ${@}" >&2
+}
+
+function is_text_file () {
+  rev="${1}"
+  file="${2}"
+  info
+  [ -z "$(git show --stat --pretty="format:" "${rev}" -- "${file}" | grep "${file} *|  Bin.*bytes"'$')" ]
+}
+
+# Make sure that the log message contains some text.
+function check_log_message () {
+  if ! git log -1 --pretty="format:%B" "${REVISION}" | grep -q "[a-zA-Z0-9]"; then
+    echoerr "In ${REVISION}:"
+    echoerr "Your log message is empty."
+    echoerr "Commit aborted, fix the issue and try again."
+    exit 1
+  fi
+}
+
+function check_trailing_whitespace () {
+  git diff-tree --diff-filter="A|C|M|R" --name-only -r "${REVISION}" | tail -n +2 | egrep -v '/$|\.diff$|\.patch$' | egrep "${@}" | while read file; do
+    if is_text_file "${REVISION}" "${file}" 2> /dev/null ; then
+      if git cat-file -p "${REVISION}:${file}" | grep -e '[  ]$' > /dev/null ; then
+        echowarn "In ${REVISION}:"
+        echowarn "Trailing whitespace found in ${file}."
+      fi
+    fi
+  done
+}
+
+function check_ending_newline () {
+  git diff-tree --diff-filter="A|C|M|R" --name-only -r "${REVISION}" | tail -n +2 | egrep -v '/$|\.diff$|\.patch$' | egrep "${@}" | while read file; do
+    if is_text_file "${REVISION}" "${file}" 2> /dev/null ; then
+      if [ "$(git cat-file -p "${REVISION}:${file}" | tail -c1 | wc -l)" = "0" ]; then
+        echowarn "In ${REVISION}:"
+        echowarn "${file} does not end in a newline."
+      fi
+    fi
+  done
+}
+
+function check_tabs () {
+  git diff-tree --diff-filter="A|C|M|R" --name-only -r "${REVISION}" | tail -n +2 | egrep -v 'Makefile.*|common.mak|subdir.mak|clean-diff|\.diff|\.patch' | egrep "${@}" | while read file; do
+    if is_text_file "${REVISION}" "${file}" 2> /dev/null ; then
+      if git cat-file -p "${REVISION}:${file}" | grep -P '\t' > /dev/null; then
+        echowarn "In ${REVISION}:"
+        echowarn "Tabs found in ${file}."
+      fi
+    fi
+  done
+}
+
+function check_dos_linebreaks () {
+  git diff-tree --diff-filter="A|C|M|R" --name-only -r "${REVISION}" | tail -n +2 | egrep "${@}" | while read file; do
+    if is_text_file "${REVISION}" "${file}" 2> /dev/null ; then
+      if  git cat-file -p "${REVISION}:${file}" | grep -q '^M$' 2> /dev/null; then
+        echowarn "In ${REVISION}:"
+        echowarn "DOS linebreaks found in ${file}."
+      fi
+    fi
+  done
+}

--
Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/maintenancescripts.git


More information about the x2go-commits mailing list