2019-11-27 01:24:29 -07:00
|
|
|
# -*- sh -*-
|
|
|
|
|
2017-03-15 07:47:47 -07:00
|
|
|
update_command() {
|
|
|
|
local update_to_head=$1
|
|
|
|
|
|
|
|
(
|
2019-02-28 20:55:50 -07:00
|
|
|
cd "$(asdf_dir)" || exit 1
|
2017-03-15 07:47:47 -07:00
|
|
|
|
2018-12-01 19:07:44 -07:00
|
|
|
if [ -f asdf_updates_disabled ] || ! git rev-parse --is-inside-work-tree &>/dev/null; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "Update command disabled. Please use the package manager that you used to install asdf to upgrade asdf.\n"
|
2020-03-12 04:04:19 -07:00
|
|
|
exit 42
|
2017-09-12 15:33:48 -07:00
|
|
|
else
|
|
|
|
do_update "$update_to_head"
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
do_update() {
|
|
|
|
local update_to_head=$1
|
|
|
|
|
2017-03-15 07:47:47 -07:00
|
|
|
if [ "$update_to_head" = "--head" ]; then
|
|
|
|
# Update to latest on the master branch
|
2019-11-29 09:42:22 -07:00
|
|
|
git fetch origin master
|
2017-03-15 09:37:41 -07:00
|
|
|
git checkout master
|
2019-11-29 09:42:22 -07:00
|
|
|
git reset --hard origin/master
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "Updated asdf to latest on the master branch\n"
|
2017-03-15 07:47:47 -07:00
|
|
|
else
|
|
|
|
# Update to latest release
|
2017-09-25 06:13:35 -07:00
|
|
|
git fetch origin --tags || exit 1
|
2019-03-24 15:24:19 -07:00
|
|
|
|
|
|
|
if [ "$(get_asdf_config_value "use_release_candidates")" = "yes" ]; then
|
|
|
|
# Use the latest tag whether or not it is an RC
|
|
|
|
tag=$(git tag | sort_versions | sed '$!d') || exit 1
|
|
|
|
else
|
|
|
|
# Exclude RC tags when selecting latest tag
|
|
|
|
tag=$(git tag | sort_versions | grep -vi "rc" | sed '$!d') || exit 1
|
|
|
|
fi
|
2017-03-15 07:47:47 -07:00
|
|
|
|
|
|
|
# Update
|
|
|
|
git checkout "$tag" || exit 1
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "Updated asdf to release %s\n" "$tag"
|
2017-03-15 07:47:47 -07:00
|
|
|
fi
|
|
|
|
}
|
2017-03-15 08:16:25 -07:00
|
|
|
|
|
|
|
# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942
|
|
|
|
sort_versions() {
|
|
|
|
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
|
|
|
|
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
|
|
|
|
}
|
2019-11-27 01:24:29 -07:00
|
|
|
|
|
|
|
update_command "$@"
|