Skip to content

Commit 04ba6d2

Browse files
committed
fix: checking subversion failed
As @LangLangBart suggested a tool with version "1" would pass the check against version "1.0" but not against "1.0.0". It now works for whatever subversion NOTE: code is also cleaner
1 parent 779371b commit 04ba6d2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

gh-notify

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ select_notif() {
617617
# This function validates the version of a tool.
618618
check_version() {
619619
local tool=$1 threshold=$2 on_error=${3:-die}
620-
local user_version
620+
local user_version user_version_part index
621621
declare -a ver_parts threshold_parts
622622
user_version=$(command $tool --version 2>&1 |
623623
command command grep --color=never --extended-regexp --only-matching --regexp='[0-9]+(\.[0-9]+)*' |
@@ -626,14 +626,11 @@ check_version() {
626626
IFS='.' read -ra ver_parts <<<"$user_version"
627627
IFS='.' read -ra threshold_parts <<<"$threshold"
628628

629-
for i in "${!threshold_parts[@]}"; do
630-
# If the threshold's last part is 0 and version has one less parts, it's ok
631-
if (( i == ${#threshold_parts[@]} - 1 )) && ((${#ver_parts[@]} == ${#threshold_parts[@]} - 1)) && ((${threshold_parts[i]} == 0)); then
632-
break
633-
fi
634-
if ((i >= ${#ver_parts[@]})) || ((ver_parts[i] < threshold_parts[i])); then
629+
for index in "${!threshold_parts[@]}"; do
630+
user_version_part=${ver_parts[index]:-0}
631+
if ((user_version_part < threshold_parts[index])); then
635632
$on_error "Your '$tool' version '$user_version' is insufficient. The minimum required version is '$threshold'."
636-
elif ((ver_parts[i] > threshold_parts[i])); then
633+
elif ((user_version_part > threshold_parts[index])); then
637634
break
638635
fi
639636
done

0 commit comments

Comments
 (0)