.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>
This commit is contained in:
Leah Rowe
2023-08-24 01:08:08 +01:00
parent 3a5ba57f5e
commit be7a5b0ca2
+17 -20
View File
@@ -3,6 +3,8 @@
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org> # SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
# SPDX-License-Identifier: GPL-3.0-only # SPDX-License-Identifier: GPL-3.0-only
. "include/err.sh"
git_name="lbmkplaceholder" git_name="lbmkplaceholder"
git_email="placeholder@lbmkplaceholder.com" git_email="placeholder@lbmkplaceholder.com"
@@ -12,8 +14,7 @@ main()
if [ "${1}" = "clean" ]; then if [ "${1}" = "clean" ]; then
clean 1> /dev/null clean 1> /dev/null
else else
printf "%s: Unsupported argument\n" $0 err "unsupported argument, \"${1}\""
exit 1
fi fi
else else
set_placeholders 1> /dev/null set_placeholders 1> /dev/null
@@ -25,13 +26,10 @@ set_placeholders()
set_git_credentials set_git_credentials
# Check coreboot as well to prevent errors during building # Check coreboot as well to prevent errors during building
if [ ! -d coreboot ]; then [ -d coreboot ] || return 0
return
fi
for x in coreboot/*; do for x in coreboot/*; do
if [ ! -d "${x}" ]; then [ -d "${x}" ] || continue
continue [ -e "${x}/.git" ] || break
fi
( (
cd "${x}" cd "${x}"
set_git_credentials set_git_credentials
@@ -43,10 +41,10 @@ set_git_credentials()
{ {
# Check if username and or email is set. # Check if username and or email is set.
if ! git config user.name || git config user.email ; then if ! git config user.name || git config user.email ; then
git config user.name \ git config user.name || git config user.name "${git_name}" || \
|| git config user.name "${git_name}" err "cannot set local git user.name"
git config user.email \ git config user.email || git config user.email "${git_email}" \
|| git config user.email "${git_email}" || err "cannot set local git user.email"
fi fi
} }
@@ -54,13 +52,10 @@ clean()
{ {
unset_placeholders unset_placeholders
if [ ! -d coreboot ]; then [ -d coreboot ] || return 0
return
fi
for x in coreboot/*; do for x in coreboot/*; do
if [ ! -d "${x}" ]; then [ -d "${x}" ] || continue
continue [ -e "${x}/.git" ] || break
fi
( (
cd "${x}" cd "${x}"
unset_placeholders unset_placeholders
@@ -71,11 +66,13 @@ clean()
unset_placeholders() unset_placeholders()
{ {
if [ "$(git config user.name)" = "${git_name}" ]; then if [ "$(git config user.name)" = "${git_name}" ]; then
git config --unset user.name git config --unset user.name || \
err "cannot unset local git user.name"
fi fi
if [ "$(git config user.email)" = "${git_email}" ]; then if [ "$(git config user.email)" = "${git_email}" ]; then
git config --unset user.email git config --unset user.email || \
err "cannot unset local git user.email"
fi fi
} }