git: Add change id to commits

1c9a53766a6a0fd5a39d244b20f62610cc4b179236f10b0722249f5b335f5d4b
Change-Id: Id4116a14a1a0500f0c127b8e643f4b1793aa55c4
Alexis Sellier committed ago 1 parent 3eb597b3
.githooks/commit-msg +15 -0
1 1
#!/bin/sh
2 2
# Rejects a commit whose message breaks the format described in CONTRIBUTING.
3 +
# Adds a Change-Id when the footer has none.
3 4
# The rules live in scripts/check-commit-message.
4 5
5 6
top=$(git rev-parse --show-toplevel) || exit 1
6 7
7 8
if ! "$top/scripts/check-commit-message" "$1"; then
8 9
    echo "commit-msg: see WRITING COMMITS in CONTRIBUTING" >&2
9 10
    echo "commit-msg: the message is kept in $1; retry with" \
10 11
        "'git commit -e -F $1'" >&2
11 12
    exit 1
12 13
fi
14 +
15 +
trailers=$(git interpret-trailers --parse "$1") || exit 1
16 +
if printf '%s\n' "$trailers" | grep -qi '^Change-Id:'; then
17 +
    exit 0
18 +
fi
19 +
20 +
change_id=$(od -An -N20 -tx1 /dev/urandom) || exit 1
21 +
change_id=$(printf '%s' "$change_id" | tr -d '[:space:]') || exit 1
22 +
if [ "${#change_id}" -ne 40 ]; then
23 +
    echo "commit-msg: cannot read 20 random bytes from /dev/urandom" >&2
24 +
    exit 1
25 +
fi
26 +
27 +
git interpret-trailers --in-place --trailer "Change-Id: I$change_id" "$1"