]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: install the git hook (#6425)
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 24 Jul 2017 08:41:45 +0000 (04:41 -0400)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Jul 2017 08:41:45 +0000 (10:41 +0200)
This was done autogen.sh previously and was dropped in
72cdb3e783174dcf9223a49f03e3b0e2ca95ddb8. Let's add it back.
The meson configuration step is the only reasonable place.

Note that this only works for the most standard git dirs, e.g.
the hook will not be installed if git worktree is used or if
$GIT_DIR is specified, etc. I think that's OK because most of
the time meson will be run at least once in the original cloned
dir.

meson.build
tools/add-git-hook.sh [new file with mode: 0755]

index ba8bb8185685ffaa5f78560faccc2098b91e4809..867a56ee81368b57529f48bf8c7b24429c615d0d 100644 (file)
@@ -26,6 +26,14 @@ m4_defines = []
 
 #####################################################################
 
+# Try to install the git pre-commit hook
+git_hook = run_command(join_paths(meson.source_root(), 'tools/add-git-hook.sh'))
+if git_hook.returncode() == 0
+        message(git_hook.stdout().strip())
+endif
+
+#####################################################################
+
 rootprefixdir = get_option('rootprefix')
 if get_option('split-usr')
         conf.set('HAVE_SPLIT_USR', true)
diff --git a/tools/add-git-hook.sh b/tools/add-git-hook.sh
new file mode 100755 (executable)
index 0000000..4ee919f
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh -eu
+
+cd "$MESON_SOURCE_ROOT"
+
+if [ ! -f .git/hooks/pre-commit.sample -o -f .git/hooks/pre-commit ]; then
+        exit 2 # not needed
+fi
+
+cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit
+chmod +x .git/hooks/pre-commit
+echo 'Activated pre-commit hook'