@@ -31,24 +31,43 @@ version_compare () {
31
31
test $a1 -le $b1 || { echo 1; return ; }
32
32
test $b1 -le $a1 || { echo -1; return ; }
33
33
34
- # Get the next character
35
- a1=" $( expr " $a " : ' ^\(.\)' ) " ; a=" ${a# $a1 } "
36
- b1=" $( expr " $b " : ' ^\(.\)' ) " ; b=" ${b# $b1 } "
37
-
38
- test " x$a1 " = " x$b1 " || {
39
- if test . = " $b1 "
40
- then
41
- echo -1
42
- else
43
- echo 1
44
- fi
45
- return
46
- }
34
+ # Skip non-numeric prefixes
35
+ a1=" $( expr " $a " : ' ^\([^0-9]\+\)' ) " ; a=" ${a# $a1 } "
36
+ b1=" $( expr " $b " : ' ^\([^0-9]\+\)' ) " ; b=" ${b# $b1 } "
47
37
48
- test . = " $a1 " || { echo 0; return ; }
38
+ case " $a1 ,$b1 " in
39
+ -rc,-rc) ;; # both are -rc versions
40
+ -rc,* ) echo -1; return ;;
41
+ * ,-rc) echo 1; return ;;
42
+ esac
49
43
done
50
44
}
51
45
46
+ test " --test-version-compare" ! = " $* " || {
47
+ test_version_compare () {
48
+ result=" $( version_compare " $1 " " $2 " ) "
49
+ test " $3 " = " $result " || {
50
+ echo " version_compare $1 $2 returned $result instead of $3 " >&2
51
+ exit 1
52
+ }
53
+
54
+ result2=" $( version_compare " $2 " " $1 " ) "
55
+ test " $result2 " = " $(( - $3 )) " || {
56
+ echo " version_compare $2 $1 returned $result2 instead of $(( - $3 )) " >&2
57
+ exit 1
58
+ }
59
+ }
60
+
61
+ test_version_compare 2.32.0.windows.1 2.32.1.windows.1 -1
62
+ test_version_compare 2.32.1.windows.1 2.32.0.windows.1 1
63
+ test_version_compare 2.32.1.vfs.0.0 2.32.0.windows.1 1
64
+ test_version_compare 2.32.1.vfs.0.0 2.32.0.vfs.0.0 1
65
+ test_version_compare 2.32.0.vfs.0.1 2.32.0.vfs.0.2 -1
66
+ test_version_compare 2.32.0-rc0.windows.1 2.31.1.windows.1 1
67
+ test_version_compare 2.32.0-rc2.windows.1 2.32.0.windows.1 -1
68
+ exit 0
69
+ }
70
+
52
71
# Counts how many Bash instances are running, apart from the current one (if
53
72
# any: `git update-git-for-windows` might have been called from a CMD window,
54
73
# in which case no Git Bash might be running at all).
@@ -229,16 +248,16 @@ update_git_for_windows () {
229
248
set_recently_seen " $latest "
230
249
return
231
250
fi
232
- test -n " $testing " ||
233
- case " $version " in
234
- * .rc[0-9]* )
235
- # Do not downgrade from -rc versions to the latest stable one
251
+ if ! test -n " $testing "
252
+ then
253
+ # We are not testing and we don't have exact equality,
254
+ # so do a careful comparison and look to see if the
255
+ # latest release is strictly newer than ours.
236
256
if test 0 -lt " $( version_compare " $version " " $latest " ) "
237
257
then
238
258
return
239
259
fi
240
- ;;
241
- esac
260
+ fi
242
261
243
262
echo " Update $latest is available" >&2
244
263
releases=$( http_get $releases_url /latest) || return
0 commit comments