#!/usr/bin/env bash
# commit the new entry to package.mask
# (c) 2019-2024 Michał Górny <mgorny@gentoo.org>
# SPDX-License-Identifier: GPL-2.0-or-later

set -e

cd "$(git rev-parse --show-toplevel)"
[[ -n "$(git diff -U0 profiles/package.mask)" ]]

# 1. package(s)
pkg=(
	$(git diff -U0 profiles/package.mask | sed -n -e 's/^+\([^+#]\)/\1/p')
)
pkg="${pkg[*]}"

# 2. bugno
bugno=$(git diff -U0 profiles/package.mask |
	sed -n -e 's/^+#.*Removal.* Bug #\([0-9]\+\)./\1/p')

msg="package.mask: Last rite ${pkg// /, }${bugno:+

Bug: https://bugs.gentoo.org/${bugno}}"

exec git commit -s -S -m "${msg}" profiles/package.mask
