Add strict mode header in all functions
This commit is contained in:
parent
8d5dfb2214
commit
35a9a2f086
1 changed files with 12 additions and 6 deletions
18
util.sh
18
util.sh
|
@ -3,17 +3,23 @@ set -euo pipefail
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
printf 'Error: %s\n' "$1" >&2
|
printf 'Error: %s\n' "$1" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
arguments() {
|
arguments() {
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
if [ "$1" -ne "$2" ]; then
|
if [ "$1" -ne "$2" ]; then
|
||||||
error "expected $1 argument(s), got $2"
|
error "expected $1 argument(s), got $2"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
valid_repo_name() {
|
valid_repo_name() {
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
# If you modify this, make sure that "git-shell-commands" cannot be accessed.
|
# If you modify this, make sure that "git-shell-commands" cannot be accessed.
|
||||||
# Currently this is ensured by forbidding / and enforcing a .git suffix.
|
# Currently this is ensured by forbidding / and enforcing a .git suffix.
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -33,9 +39,9 @@ valid_repo_name() {
|
||||||
}
|
}
|
||||||
|
|
||||||
repo_name_new() {
|
repo_name_new() {
|
||||||
# Do not remove the extra `|| exit 1`!
|
set -euo pipefail
|
||||||
# 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
|
local repo_name="$(valid_repo_name "$1")"
|
||||||
# `test` dereferences symlinks, so explicit -L is necessary
|
# `test` dereferences symlinks, so explicit -L is necessary
|
||||||
if [ -e "$repo_name" -o -L "$repo_name" ]; then
|
if [ -e "$repo_name" -o -L "$repo_name" ]; then
|
||||||
error "'$repo_name' already exists."
|
error "'$repo_name' already exists."
|
||||||
|
@ -44,9 +50,9 @@ repo_name_new() {
|
||||||
}
|
}
|
||||||
|
|
||||||
repo_name_existing() {
|
repo_name_existing() {
|
||||||
# Do not remove the extra `|| exit 1`!
|
set -euo pipefail
|
||||||
# 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
|
local repo_name="$(valid_repo_name "$1")"
|
||||||
# `test` dereferences symlinks, so explicit -L is necessary
|
# `test` dereferences symlinks, so explicit -L is necessary
|
||||||
if ! [ -e "$repo_name" -o -L "$repo_name" ]; then
|
if ! [ -e "$repo_name" -o -L "$repo_name" ]; then
|
||||||
error "'$repo_name' does not exist."
|
error "'$repo_name' does not exist."
|
||||||
|
|
Loading…
Reference in a new issue