brew/Library/Homebrew/cmd/update-reset.sh

49 lines
1.1 KiB
Bash
Raw Normal View History

#: * `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
2018-10-04 09:31:37 +01:00
for DIR in "${REPOS[@]}"
do
[[ -d "$DIR/.git" ]] || continue
cd "$DIR" || continue
2019-11-21 16:18:46 -05:00
ohai "Fetching $DIR..."
git fetch --force --tags origin
git remote set-head origin --auto >/dev/null
echo
2019-11-21 16:18:46 -05:00
ohai "Resetting $DIR..."
git checkout --force -B master origin/master
echo
done
}