From 35a9a2f086dced5077b97f12bb6587fe832adc65 Mon Sep 17 00:00:00 2001 From: Midgard Date: Sat, 9 Sep 2023 11:36:43 +0200 Subject: [PATCH] Add strict mode header in all functions --- util.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/util.sh b/util.sh index 9a48072..6d42b64 100644 --- a/util.sh +++ b/util.sh @@ -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."