2019-11-27 01:24:29 -07:00
|
|
|
# -*- sh -*-
|
|
|
|
|
2015-05-17 11:20:51 -07:00
|
|
|
plugin_update_command() {
|
2019-11-30 14:00:58 -07:00
|
|
|
if [ "$#" -lt 1 ]; then
|
2021-04-27 02:28:24 -07:00
|
|
|
display_error "usage: asdf plugin-update {<name> [git-ref] | --all}"
|
2016-07-03 04:15:57 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-30 13:08:52 -07:00
|
|
|
local plugin_name="$1"
|
2021-04-27 02:28:24 -07:00
|
|
|
local gitref="${2}"
|
2021-09-14 06:44:53 -07:00
|
|
|
local plugins=
|
2021-04-27 02:28:24 -07:00
|
|
|
|
2015-05-20 21:31:09 -07:00
|
|
|
if [ "$plugin_name" = "--all" ]; then
|
2020-09-16 21:00:35 -07:00
|
|
|
if [ -d "$(asdf_data_dir)"/plugins ]; then
|
2021-09-14 06:44:53 -07:00
|
|
|
plugins=$(find "$(asdf_data_dir)"/plugins -mindepth 1 -maxdepth 1 -type d)
|
|
|
|
while IFS= read -r dir; do
|
2021-04-27 02:28:24 -07:00
|
|
|
update_plugin "$(basename "$dir")" "$dir" "$gitref" &
|
2021-09-14 06:44:53 -07:00
|
|
|
done <<<"$plugins"
|
2020-09-28 09:16:06 -07:00
|
|
|
wait
|
2020-09-16 21:00:35 -07:00
|
|
|
fi
|
2015-05-17 00:46:56 -07:00
|
|
|
else
|
2017-09-04 10:04:56 -07:00
|
|
|
local plugin_path
|
2019-11-30 13:08:52 -07:00
|
|
|
plugin_path="$(get_plugin_path "$plugin_name")"
|
2017-09-04 10:04:56 -07:00
|
|
|
check_if_plugin_exists "$plugin_name"
|
2019-12-30 08:48:29 -07:00
|
|
|
update_plugin "$plugin_name" "$plugin_path" "$gitref"
|
2019-12-30 08:44:31 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
update_plugin() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local plugin_path=$2
|
2021-04-27 02:28:24 -07:00
|
|
|
plugin_remote_default_branch=$(git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" ls-remote --symref origin HEAD | awk '{ sub(/refs\/heads\//, ""); print $2; exit }')
|
|
|
|
local gitref=${3:-${plugin_remote_default_branch}}
|
2019-12-30 08:44:31 -07:00
|
|
|
logfile=$(mktemp)
|
|
|
|
{
|
2021-04-27 02:28:24 -07:00
|
|
|
printf "Updating %s to %s\\n" "$plugin_name" "$gitref"
|
|
|
|
git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" fetch --prune --update-head-ok origin "$gitref:$gitref"
|
|
|
|
git --git-dir "$plugin_path/.git" --work-tree "$plugin_path" -c advice.detachedHead=false checkout --force "$gitref"
|
2019-12-30 08:44:31 -07:00
|
|
|
} >"$logfile" 2>&1
|
|
|
|
cat "$logfile"
|
|
|
|
rm "$logfile"
|
2015-05-17 00:46:56 -07:00
|
|
|
}
|
2019-11-27 01:24:29 -07:00
|
|
|
|
|
|
|
plugin_update_command "$@"
|