summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.inc3
-rwxr-xr-xutil/scripts/prepare-commit-msg.clang-format13
2 files changed, 16 insertions, 0 deletions
diff --git a/Makefile.inc b/Makefile.inc
index fe325048f8..aa93222920 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -597,6 +597,9 @@ update:
gitconfig:
util/gitconfig/gitconfig.sh "$(MAKE)"
+install-git-commit-clangfmt:
+ cp util/scripts/prepare-commit-msg.clang-format .git/hooks/prepare-commit-msg
+
include util/crossgcc/Makefile.inc
.PHONY: tools
diff --git a/util/scripts/prepare-commit-msg.clang-format b/util/scripts/prepare-commit-msg.clang-format
new file mode 100755
index 0000000000..7033f3cc07
--- /dev/null
+++ b/util/scripts/prepare-commit-msg.clang-format
@@ -0,0 +1,13 @@
+#!/bin/bash
+files=`git diff --cached --name-only | grep '\.[ch]$'`
+if [ -z "$files" ]; then
+ exit 0
+fi
+# This has to be set here; otherwise a grep error seems to cause
+# us to exit with non-zero status.
+set -e
+clang-format -i $files
+git add $files
+u=`git config user.name`
+m="clang-formatted-by: $u"
+echo $m >> $1