git: Add commit hooks
e66f918fb2bd2e8864bb842160dd32adc41f283f5ad5de828cb55332af07826f
* Formatting * Change-Ids Change-Id: I88ca9624affbef934f2f0e5d43f58164a86c9683
1 parent
7be9285b
.githooks/commit-msg
added
+16 -0
| 1 | + | #!/bin/sh |
|
| 2 | + | # Add a Change-Id to the commit message footer if it has none. |
|
| 3 | + | ||
| 4 | + | trailers=$(git interpret-trailers --parse "$1") || exit 1 |
|
| 5 | + | if printf '%s\n' "$trailers" | grep -qi '^Change-Id:'; then |
|
| 6 | + | exit 0 |
|
| 7 | + | fi |
|
| 8 | + | ||
| 9 | + | change_id=$(od -An -N20 -tx1 /dev/urandom) || exit 1 |
|
| 10 | + | change_id=$(printf '%s' "$change_id" | tr -d '[:space:]') || exit 1 |
|
| 11 | + | if [ "${#change_id}" -ne 40 ]; then |
|
| 12 | + | echo "commit-msg: cannot read 20 random bytes from /dev/urandom" >&2 |
|
| 13 | + | exit 1 |
|
| 14 | + | fi |
|
| 15 | + | ||
| 16 | + | git interpret-trailers --in-place --trailer "Change-Id: I$change_id" "$1" |
.githooks/pre-commit
added
+14 -0
| 1 | + | #!/bin/sh |
|
| 2 | + | # Check the format of staged C source files. |
|
| 3 | + | ||
| 4 | + | tmp=$(mktemp -d) || exit 1 |
|
| 5 | + | trap 'rm -rf "$tmp"' EXIT |
|
| 6 | + | ||
| 7 | + | git diff --cached --name-only --diff-filter=ACMRT -z -- '*.c' '*.h' > "$tmp/files" || exit 1 |
|
| 8 | + | [ -s "$tmp/files" ] || exit 0 |
|
| 9 | + | ||
| 10 | + | git checkout-index --prefix="$tmp/" -z --stdin < "$tmp/files" || exit 1 |
|
| 11 | + | git show :.clang-format > "$tmp/.clang-format" || exit 1 |
|
| 12 | + | cd "$tmp" || exit 1 |
|
| 13 | + | ||
| 14 | + | xargs -0 clang-format --dry-run --Werror -- < files |