2021-01-15 15:04:02 -05:00
|
|
|
#: * `update-reset` [<repository> ...]
|
2019-01-30 21:31:45 +00:00
|
|
|
#:
|
2021-01-28 01:51:40 -05:00
|
|
|
#: Fetch and reset Homebrew and all tap repositories (or any specified <repository>) using `git`(1) to their latest `origin/HEAD`.
|
2019-08-19 22:44:50 -04:00
|
|
|
#:
|
|
|
|
#: *Note:* this will destroy all your uncommitted or committed changes.
|
2016-12-18 15:25:16 -08:00
|
|
|
|
2021-10-05 03:38:40 +01:00
|
|
|
# Replaces the function in Library/Homebrew/brew.sh to cache the Git executable to provide
|
|
|
|
# speedup when using Git repeatedly and prevent errors if the shim changes mid-update.
|
|
|
|
git() {
|
|
|
|
if [[ -z "${GIT_EXECUTABLE}" ]]
|
|
|
|
then
|
|
|
|
# HOMEBREW_LIBRARY is set by bin/brew
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
GIT_EXECUTABLE="$("${HOMEBREW_LIBRARY}/Homebrew/shims/shared/git" --homebrew=print-path)"
|
|
|
|
fi
|
|
|
|
"${GIT_EXECUTABLE}" "$@"
|
|
|
|
}
|
|
|
|
|
2016-12-18 15:25:16 -08:00
|
|
|
homebrew-update-reset() {
|
2022-04-25 04:22:12 -07:00
|
|
|
local option
|
2016-12-18 15:25:16 -08:00
|
|
|
local DIR
|
2018-09-18 21:14:21 +01:00
|
|
|
local -a REPOS=()
|
2016-12-18 15:25:16 -08:00
|
|
|
|
|
|
|
for option in "$@"
|
|
|
|
do
|
2021-04-24 11:11:09 +05:30
|
|
|
case "${option}" in
|
2021-09-16 01:08:02 +08:00
|
|
|
-\? | -h | --help | --usage)
|
|
|
|
brew help update-reset
|
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
--debug) HOMEBREW_DEBUG=1 ;;
|
2016-12-18 15:25:16 -08:00
|
|
|
-*)
|
2021-09-13 20:32:20 +08:00
|
|
|
[[ "${option}" == *d* ]] && HOMEBREW_DEBUG=1
|
2016-12-18 15:25:16 -08:00
|
|
|
;;
|
|
|
|
*)
|
2021-04-24 11:11:09 +05:30
|
|
|
REPOS+=("${option}")
|
2016-12-18 15:25:16 -08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-04-24 11:11:09 +05:30
|
|
|
if [[ -n "${HOMEBREW_DEBUG}" ]]
|
2016-12-18 15:25:16 -08:00
|
|
|
then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2018-10-08 18:41:46 +01:00
|
|
|
if [[ -z "${REPOS[*]}" ]]
|
2018-09-18 21:14:21 +01:00
|
|
|
then
|
2021-04-24 11:11:09 +05:30
|
|
|
REPOS+=("${HOMEBREW_REPOSITORY}" "${HOMEBREW_LIBRARY}"/Taps/*/*)
|
2018-09-18 21:14:21 +01:00
|
|
|
fi
|
|
|
|
|
2018-10-04 09:31:37 +01:00
|
|
|
for DIR in "${REPOS[@]}"
|
2016-12-18 15:25:16 -08:00
|
|
|
do
|
2021-04-24 11:11:09 +05:30
|
|
|
[[ -d "${DIR}/.git" ]] || continue
|
2022-04-25 04:22:12 -07:00
|
|
|
if ! git -C "${DIR}" config --local --get remote.origin.url &>/dev/null
|
|
|
|
then
|
|
|
|
opoo "No remote 'origin' in: ${DIR}"
|
|
|
|
continue
|
|
|
|
fi
|
2021-04-24 11:11:09 +05:30
|
|
|
ohai "Fetching ${DIR}..."
|
|
|
|
git -C "${DIR}" fetch --force --tags origin
|
|
|
|
git -C "${DIR}" remote set-head origin --auto >/dev/null
|
2016-12-18 15:25:16 -08:00
|
|
|
echo
|
|
|
|
|
2021-04-24 11:11:09 +05:30
|
|
|
ohai "Resetting ${DIR}..."
|
|
|
|
head="$(git -C "${DIR}" symbolic-ref refs/remotes/origin/HEAD)"
|
2020-06-17 17:26:15 -07:00
|
|
|
head="${head#refs/remotes/origin/}"
|
2021-04-24 11:11:09 +05:30
|
|
|
git -C "${DIR}" checkout --force -B "${head}" origin/HEAD
|
2016-12-18 15:25:16 -08:00
|
|
|
echo
|
|
|
|
done
|
|
|
|
}
|