mirror of
https://github.com/gaschz/dotfiles.git
synced 2025-03-01 14:22:33 +01:00
Fix git description validation
This commit is contained in:
parent
db0d57cfcf
commit
31a64724d6
@ -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
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user