From 0684db8255cb0e73bbf00b27210a4ac95472a9d0 Mon Sep 17 00:00:00 2001
From: Albert Astals Cid <aacid@kde.org>
Date: Mon, 7 Sep 2020 02:22:22 +0200
Subject: [PATCH] Add .git-blame-ignore-revs and some instructions for
 clang-format

---
 .git-blame-ignore-revs |  2 ++
 README.clang-format    | 14 ++++++++++++++
 hooks/pre-commit       | 10 ++++++++++
 3 files changed, 26 insertions(+)
 create mode 100644 .git-blame-ignore-revs
 create mode 100644 README.clang-format
 create mode 100644 hooks/pre-commit

diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
new file mode 100644
index 00000000..ea00bd21
--- /dev/null
+++ b/.git-blame-ignore-revs
@@ -0,0 +1,2 @@
+# _clang_format added
+f62a8ee8f7e81a1b573c335ded3326d8ee985ab4
diff --git a/README.clang-format b/README.clang-format
new file mode 100644
index 00000000..79f95796
--- /dev/null
+++ b/README.clang-format
@@ -0,0 +1,14 @@
+We introduced clang-format mandatory usage in September 2020.
+If you want git blame to ignore the revision in which we did the mass change you can do
+   git config blame.ignoreRevsFile .git-blame-ignore-revs
+on your clone
+
+To get the clang-format warnings locally instead at CI time we recommend you
+to copy the hooks/pre-commit to your .git
+    cp hooks/pre-commit .git/hooks/
+
+We are using clang-format 10 on CI. Unfortunately clang-format is not totally
+compatible with older versions of itself. If CI gives you trouble but your local
+clang-format disagrees, just apply the changes suggested by CI and then commit
+with the --no-verify flag. If you get stuck, don't hesitate to ask the reviewer
+to help and they will reformat your commits :)
diff --git a/hooks/pre-commit b/hooks/pre-commit
new file mode 100644
index 00000000..6337bbbd
--- /dev/null
+++ b/hooks/pre-commit
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+readonly output=$(git clang-format -v --diff)
+
+if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi
+if [[ "$output" == *"clang-format did not modify any files"* ]]; then exit 0; fi
+
+echo "ERROR: you need to run git clang-format on your commit"
+echo "       git clang-format -f is potentially what you want"
+exit 1