#! /usr/bin/env bash # SPDX-FileCopyrightText: edef # 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 -ne "/^# ${cut_line}$/q;p" | 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"