summary refs log tree commit diff
path: root/githooks/commit-msg
blob: 985819cf9ada44c4eb44e74a9c22233c84bbc7d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#! /usr/bin/env bash
# SPDX-FileCopyrightText: edef <edef@unfathomable.blue>
# SPDX-License-Identifier: OSL-3.0

set -euo pipefail
change_id=$(head -c32 /dev/urandom | git hash-object --stdin)

cut_line='------------------------ >8 ------------------------'
if [ $(< "$1" sed -e "/^# ${cut_line}$/Q" | git stripspace --strip-comments | wc -c) -eq 0 ]; then
    # don't inhibit "Aborting commit due to empty commit message"
    exit 0
fi

git interpret-trailers \
    --if-exists doNothing \
    --trailer "Change-Id:I$change_id" \
    --in-place "$1"