cmd/update-reset: use stable tag.

Currently we always reset Homebrew/brew onto the latest `master`.
Instead, let's correctly use the latest tag when appropriate.
This commit is contained in:
Mike McQuaid 2024-03-14 16:41:30 +00:00
parent a7d77485f1
commit b1cbe47e45
No known key found for this signature in database

View File

@ -75,9 +75,21 @@ homebrew-update-reset() {
echo
ohai "Resetting ${DIR}..."
head="$(git -C "${DIR}" symbolic-ref refs/remotes/origin/HEAD)"
head="${head#refs/remotes/origin/}"
git -C "${DIR}" checkout --force -B "${head}" origin/HEAD
# HOMEBREW_* variables here may all set by bin/brew or the user
# shellcheck disable=SC2154
if [[ "${DIR}" == "${HOMEBREW_REPOSITORY}" &&
(-n "${HOMEBREW_UPDATE_TO_TAG}" ||
(-z "${HOMEBREW_DEVELOPER}" && -z "${HOMEBREW_DEV_CMD_RUN}")) ]]
then
local latest_git_tag
latest_git_tag="$(git -C "${DIR}" tag --list --sort="-version:refname" | head -n1)"
git -C "${DIR}" checkout --force -B stable "refs/tags/${latest_git_tag}"
else
head="$(git -C "${DIR}" symbolic-ref refs/remotes/origin/HEAD)"
head="${head#refs/remotes/origin/}"
git -C "${DIR}" checkout --force -B "${head}" origin/HEAD
fi
echo
done
}