Skip to content

Commit

Permalink
git-update: do not suggest downgrading from an -rc version
Browse files Browse the repository at this point in the history
To keep things safe, -rc versions are always marked as pre-releases, and
therefore `git update` would always suggest a downgrade. Not what we
want.

This contains a port of our VersionCompare() function in the InnoSetup
installer definition to Unix shell code. Yeah. Exactly.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Oct 26, 2017
1 parent 459b6e8 commit 1418ee7
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions git-extra/git-update
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,50 @@
# when confirmation to do so is given.


# Compare version strings
# Prints -1, 0 or 1 to stdout

version_compare () {
a="$1"
b="$2"

while true
do
test -n "$b" || { echo 1; return; }
test -n "$a" || { echo -1; return; }

# Get the first numbers (if any)
a1="$(expr "$a" : '^\([0-9]*\)')"; a="${a#$a1}"
b1="$(expr "$b" : '^\([0-9]*\)')"; b="${b#$b1}"

if test -z "$b1"
then
test -z "$a1" || { echo 1; return; }
a1=0
b1=0
fi
test -n "$a1" || { echo -1; return; }
test $a1 -le $b1 || { echo 1; return; }
test $b1 -le $a1 || { echo -1; return; }

# Get the next character
a1="$(expr "$a" : '^\(.\)')"; a="${a#$a1}"
b1="$(expr "$b" : '^\(.\)')"; b="${b#$b1}"

test "x$a1" = "x$b1" || {
if test . = "$b1"
then
echo -1
else
echo 1
fi
return
}

test . = "$a1" || { echo 0; return; }
done
}

# Counts how many Bash instances are running, apart from the current one (if
# any: `git update` might have been called from a CMD window, in which case no
# Git Bash might be running at all).
Expand Down Expand Up @@ -91,6 +135,15 @@ git_update () {
echo "Up to date" >&2
return
fi
case "$version" in
*.rc[1-9]*)
# Do not downgrade from -rc versions to the latest stable one
if test 0 -lt "$(version_compare "$version" "$latest")"
then
return
fi
;;
esac

echo "Update $latest is available" >&2
download=$(echo "$releases" |
Expand Down

0 comments on commit 1418ee7

Please sign in to comment.