Files
lbmk/.gitcheck
T
Leah Rowe be7a5b0ca2 .gitcheck: must stricter error handling
we also run it in releases, so to compensate:
it now checks for .git/, but only in project
directories, not the main lbmk directory of
the git repository or a release.

this is because in a release, it's possible
that the user may still delete coreboot/
directories and re-download coreboot trees

this is not intended, but we must not assume
that users use libreboot the way it's intended!

"much stricter" because there was previously
none, intentionally, due to the above fact. the
checking of .git/ should mitigate this (the
script will exit with zero status if it isn't
there)

Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-24 01:09:54 +01:00

80 lines
1.6 KiB
Bash
Executable File

#!/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
. "include/err.sh"
git_name="lbmkplaceholder"
git_email="placeholder@lbmkplaceholder.com"
main()
{
if [ $# -gt 0 ]; then
if [ "${1}" = "clean" ]; then
clean 1> /dev/null
else
err "unsupported argument, \"${1}\""
fi
else
set_placeholders 1> /dev/null
fi
}
set_placeholders()
{
set_git_credentials
# Check coreboot as well to prevent errors during building
[ -d coreboot ] || return 0
for x in coreboot/*; do
[ -d "${x}" ] || continue
[ -e "${x}/.git" ] || break
(
cd "${x}"
set_git_credentials
)
done
}
set_git_credentials()
{
# 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}" || \
err "cannot set local git user.name"
git config user.email || git config user.email "${git_email}" \
|| err "cannot set local git user.email"
fi
}
clean()
{
unset_placeholders
[ -d coreboot ] || return 0
for x in coreboot/*; do
[ -d "${x}" ] || continue
[ -e "${x}/.git" ] || break
(
cd "${x}"
unset_placeholders
)
done
}
unset_placeholders()
{
if [ "$(git config user.name)" = "${git_name}" ]; then
git config --unset user.name || \
err "cannot unset local git user.name"
fi
if [ "$(git config user.email)" = "${git_email}" ]; then
git config --unset user.email || \
err "cannot unset local git user.email"
fi
}
main $@