[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH 00/12] Plannings for secure-testing repository migration to git



Hi,
On Thu, Dec 28, 2017 at 12:45:38PM +0100, Guido Günther wrote:
[..snip..]
> We could provide a pre-commit hook:
> 
>     https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks
> 
> they're not enforced though. User would have to set it up via
> 
>     ln -s bin/pre-commit .git/hooks/pre-commit
> 
> (which we could put into a "bin/setup-repo"). Since the hook can
> identify changed files we could only run tests on changed files so it
> would be reasonably fast. I'll have a look.

What about adding this to the secure-testing-repo (the makefile already
creates stamps so we don't need to differentiate in the hook again). We
might add other stuff like installing dependencies to run the various
commands to setup-repo later on.

>From 9e0f77e41b4e194e320609c0d74ced3a82b06f05 Mon Sep 17 00:00:00 2001
Message-Id: <9e0f77e41b4e194e320609c0d74ced3a82b06f05.1514463957.git.agx@sigxcpu.org>
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Thu, 28 Dec 2017 13:05:05 +0100
Subject: [PATCH] Add pre-commit hook to check syntax

---
 bin/setup-repo  | 31 +++++++++++++++++++++++++++++++
 conf/pre-commit | 12 ++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100755 bin/setup-repo
 create mode 100755 conf/pre-commit

diff --git a/bin/setup-repo b/bin/setup-repo
new file mode 100755
index 0000000000..ef7cf2c95b
--- /dev/null
+++ b/bin/setup-repo
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Set up a clone of the security-tracker git repo
+
+set -e
+
+SRC=../../conf/pre-commit
+HOOK=.git/hooks/pre-commit
+
+install_pre_commit_hook() {
+  if [ -L "${HOOK}" ] && [ "$(readlink ${HOOK})" = "${SRC}" ]; then
+      echo "pre-commit hook already set up"
+      return
+  fi
+
+  if [ -e "${HOOK}" ] || [ -L "${HOOK}" ]; then
+    echo "Moving old pre-commit hook"
+     mv -f "${HOOK}" "${HOOK}.$(date '+%s')"
+  fi
+
+  echo "Installing pre-commit hook"
+  ln -s "${SRC}" "${HOOK}"
+}
+
+
+if [ "$(git rev-parse --show-cdup)" != '' ] || [ -d data/CVE/list ]; then
+     echo "This does not look like the git repo of the security tracker" 1>&2
+     exit 1
+fi
+
+install_pre_commit_hook
diff --git a/conf/pre-commit b/conf/pre-commit
new file mode 100755
index 0000000000..f097a88abd
--- /dev/null
+++ b/conf/pre-commit
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -e
+
+if [ -z "${GIT_DIR}" ]; then
+    echo "GIT_DIR not set" 1>&2
+    exit 1
+fi
+
+exec 1>&2
+
+make check-syntax
-- 
2.15.1



Reply to: