brew/Library/Homebrew/cmd/update-reset.sh
Shaun Jackman b4fc3ead1e update-reset: Use the default branch origin/HEAD
Use the default branch of the repo, origin/HEAD.
2020-06-17 17:26:15 -07:00

51 lines
1.2 KiB
Bash

#: * `update-reset` [<repository>]
#:
#: Fetch and reset Homebrew and all tap repositories (or any specified <repository>) using `git`(1) to their latest `origin/master`.
#:
#: *Note:* this will destroy all your uncommitted or committed changes.
homebrew-update-reset() {
local DIR
local -a REPOS=()
for option in "$@"
do
case "$option" in
-\?|-h|--help|--usage) brew help update-reset; exit $? ;;
--debug) HOMEBREW_DEBUG=1 ;;
-*)
[[ "$option" = *d* ]] && HOMEBREW_DEBUG=1
;;
*)
REPOS+=("$option")
;;
esac
done
if [[ -n "$HOMEBREW_DEBUG" ]]
then
set -x
fi
if [[ -z "${REPOS[*]}" ]]
then
REPOS+=("$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*)
fi
for DIR in "${REPOS[@]}"
do
[[ -d "$DIR/.git" ]] || continue
cd "$DIR" || continue
ohai "Fetching $DIR..."
git fetch --force --tags origin
git remote set-head origin --auto >/dev/null
echo
ohai "Resetting $DIR..."
head="$(git symbolic-ref refs/remotes/origin/HEAD)"
head="${head#refs/remotes/origin/}"
git checkout --force -B "$head" origin/HEAD
echo
done
}