Fix git description validation

This commit is contained in:
Ben Grande 2023-11-13 14:26:13 +00:00
parent db0d57cfcf
commit 31a64724d6
No known key found for this signature in database
GPG Key ID: 00C64E14F51F9E56
2 changed files with 16 additions and 6 deletions

View File

@ -15,12 +15,21 @@ base="src"
## Regex: can contain "A-Za-z0-9_.-" but must not start or end with "_.-".
# shellcheck disable=SC2034
regex="^[A-Za-z0-9]+([A-Za-z0-9_.-]+[A-Za-z0-9]+)?$"
description_regex="^[A-Za-z0-9 _.-]+$"
fail_invalid_name(){
echo "Error: invalid value for key: $1" >&2
exit 1
}
test_description(){
key="$1"
value="$2"
if ! (echo "$value" | grep -E -q "${description_regex}"); then
fail_invalid_name "$key"
fi
}
test_name(){
key="$1"
value="$2"
@ -37,13 +46,14 @@ clean_repo_name(){
}
is_bare(){
repo="$1"
if ! test -d "$repo"; then
echo "Repository doesn't exist: $repo" >&2
_repo="$1"
if ! test -d "$_repo"; then
echo "Repository doesn't exist: $_repo" >&2
return 1
fi
if ! test "$(git -C "$repo" rev-parse --is-bare-repository)" = "true"; then
echo "Repository is not bare: $repo" >&2
if ! test "$(git -C "$_repo" rev-parse --is-bare-repository)" = "true"
then
echo "Repository is not bare: $_repo" >&2
return 1
fi
}

View File

@ -36,6 +36,6 @@ if test -z "${3-}"; then
fi
description="$(echo "$3" | cut -c 1-80)"
test_name description "$description"
test_description description "$description"
echo "$description" | tee "$description_file"