Add strict mode header in all functions

This commit is contained in:
Midgard 2023-09-09 11:36:43 +02:00
parent 8d5dfb2214
commit 35a9a2f086
Signed by: midgard
GPG key ID: 511C112F1331BBB4

18
util.sh
View file

@ -3,17 +3,23 @@ set -euo pipefail
IFS=$'\n'
error() {
set -euo pipefail
printf 'Error: %s\n' "$1" >&2
exit 1
}
arguments() {
set -euo pipefail
if [ "$1" -ne "$2" ]; then
error "expected $1 argument(s), got $2"
fi
}
valid_repo_name() {
set -euo pipefail
# If you modify this, make sure that "git-shell-commands" cannot be accessed.
# Currently this is ensured by forbidding / and enforcing a .git suffix.
case "$1" in
@ -33,9 +39,9 @@ valid_repo_name() {
}
repo_name_new() {
# Do not remove the extra `|| exit 1`!
# Due to bash weirdness, `exit 1` does not propagate through more than one $(…) even with set -e
local repo_name="$(valid_repo_name "$1")" || exit 1
set -euo pipefail
local repo_name="$(valid_repo_name "$1")"
# `test` dereferences symlinks, so explicit -L is necessary
if [ -e "$repo_name" -o -L "$repo_name" ]; then
error "'$repo_name' already exists."
@ -44,9 +50,9 @@ repo_name_new() {
}
repo_name_existing() {
# Do not remove the extra `|| exit 1`!
# Due to bash weirdness, `exit 1` does not propagate through more than one $(…) even with set -e
local repo_name="$(valid_repo_name "$1")" || exit 1
set -euo pipefail
local repo_name="$(valid_repo_name "$1")"
# `test` dereferences symlinks, so explicit -L is necessary
if ! [ -e "$repo_name" -o -L "$repo_name" ]; then
error "'$repo_name' does not exist."