update-bash: use odie and chdir from bin/brew

This commit is contained in:
Xu Cheng 2016-01-20 20:26:28 +08:00
parent bc78f81032
commit 83e1373376

View File

@ -2,6 +2,7 @@
if [[ -z "$HOMEBREW_BREW_FILE" ]] if [[ -z "$HOMEBREW_BREW_FILE" ]]
then then
# we don't use odie here, because it's only available when this script is called from brew.
echo "Error: $(basename "$0") must be called from brew!" >&2 echo "Error: $(basename "$0") must be called from brew!" >&2
exit 1 exit 1
fi fi
@ -134,8 +135,7 @@ pull() {
export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(git rev-parse "$UPSTREAM_BRANCH")" export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(git rev-parse "$UPSTREAM_BRANCH")"
if ! git merge-base --is-ancestor "$INITIAL_REVISION" "$CURRENT_REVISION" if ! git merge-base --is-ancestor "$INITIAL_REVISION" "$CURRENT_REVISION"
then then
echo "Your HEAD is not a descendant of $UPSTREAM_BRANCH!" >&2 odie "Your HEAD is not a descendant of $UPSTREAM_BRANCH!"
exit 1
fi fi
return return
fi fi
@ -183,8 +183,7 @@ pull() {
update-bash() { update-bash() {
if [[ -z "$HOMEBREW_DEVELOPER" ]] if [[ -z "$HOMEBREW_DEVELOPER" ]]
then then
echo "This command is currently only for Homebrew developers' use." >&2 odie "This command is currently only for Homebrew developers' use."
exit 1
fi fi
for i in "$@" for i in "$@"
@ -201,9 +200,10 @@ update-bash() {
-*d*) HOMEBREW_DEBUG=1 ;; -*d*) HOMEBREW_DEBUG=1 ;;
-*) ;; -*) ;;
*) *)
echo "This command updates brew itself, and does not take formula names." >&2 odie <<-EOS
echo "Use 'brew upgrade <formula>'." >&2 This command updates brew itself, and does not take formula names.
exit 1 Use 'brew upgrade <formula>'.
EOS
;; ;;
esac esac
done done
@ -216,14 +216,12 @@ update-bash() {
# check permissions # check permissions
if [[ "$HOMEBREW_PREFIX" = "/usr/local" && ! -w /usr/local ]] if [[ "$HOMEBREW_PREFIX" = "/usr/local" && ! -w /usr/local ]]
then then
echo "Error: /usr/local must be writable!" >&2 odie "/usr/local must be writable!"
exit 1
fi fi
if [[ ! -w "$HOMEBREW_REPOSITORY" ]] if [[ ! -w "$HOMEBREW_REPOSITORY" ]]
then then
echo "Error: $HOMEBREW_REPOSITORY must be writable!" >&2 odie "$HOMEBREW_REPOSITORY must be writable!"
exit 1
fi fi
if [[ -z "$(which_git)" ]] if [[ -z "$(which_git)" ]]
@ -231,8 +229,7 @@ update-bash() {
brew install git brew install git
if [[ -z "$(which_git)" ]] if [[ -z "$(which_git)" ]]
then then
echo "Error: Git must be installed and in your PATH!" >&2 odie "Git must be installed and in your PATH!"
exit 1
fi fi
fi fi
@ -244,10 +241,7 @@ update-bash() {
# ensure GIT_CONFIG is unset as we need to operate on .git/config # ensure GIT_CONFIG is unset as we need to operate on .git/config
unset GIT_CONFIG unset GIT_CONFIG
cd "$HOMEBREW_REPOSITORY" || { chdir "$HOMEBREW_REPOSITORY"
echo "Error: failed to cd to $HOMEBREW_REPOSITORY!" >&2
exit 1
}
git_init_if_necessary git_init_if_necessary
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/* for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
@ -270,11 +264,7 @@ update-bash() {
pull "$DIR" pull "$DIR"
done done
cd "$HOMEBREW_REPOSITORY" || { chdir "$HOMEBREW_REPOSITORY"
echo "Error: failed to cd to $HOMEBREW_REPOSITORY!" >&2
exit 1
}
brew update-report "$@" brew update-report "$@"
return $? return $?
} }