lbmk/.gitcheck

83 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
# SPDX-License-Identifier: GPL-3.0-only
git_name="lbmkplaceholder"
git_email="placeholder@lbmkplaceholder.com"
main()
{
if [ $# -gt 0 ]; then
if [ "${1}" = "clean" ]; then
clean > /dev/null 2> /dev/null
else
printf "%s: Unsupported argument\n" $0
exit 1
fi
else
set_placeholders > /dev/null 2> /dev/null
fi
}
set_placeholders()
{
set_git_credentials
# Check coreboot as well to prevent errors during building
if [ ! -d coreboot ]; then
return
fi
for x in coreboot/*; do
if [ ! -d "${x}" ]; then
continue
fi
(
cd "${x}"
set_git_credentials
)
done
}
set_git_credentials()
{
2022-11-21 02:42:31 +00:00
# Check if username and or email is set.
if ! git config user.name || git config user.email ; then
git config user.name \
|| git config user.name "${git_name}"
git config user.email \
|| git config user.email "${git_email}"
2022-11-21 02:42:31 +00:00
fi
}
clean()
{
unset_placeholders
if [ ! -d coreboot ]; then
return
fi
for x in coreboot/*; do
if [ ! -d "${x}" ]; then
continue
fi
(
cd "${x}"
unset_placeholders
)
done
}
unset_placeholders()
{
if [ "$(git config user.name)" = "${git_name}" ]; then
git config --unset user.name
fi
if [ "$(git config user.email)" = "${git_email}" ]; then
git config --unset user.email
fi
}
main $@