update: improve some edge cases.

- When running `brew update` and there’s been no changes from upstream
on any repositories there’s no need to call the (relatively) slow `brew
update-report` when we already know what it will say (“Already up-to
date.”).
- When any`git fetch`es fail then throw out an error at the end of the
output and produce a failing exit code (closes #65).
This commit is contained in:
Mike McQuaid 2016-05-03 14:24:41 +01:00
parent 489a1d8f43
commit 60e3737f17
3 changed files with 45 additions and 8 deletions

View File

@ -70,7 +70,9 @@ module Homebrew
end
if !updated
puts "Already up-to-date." unless ARGV.include?("--preinstall")
if !ARGV.include?("--preinstall") && !ENV["HOMEBREW_UPDATE_FAILED"]
puts "Already up-to-date."
end
elsif hub.empty?
puts "No changes to formulae."
else
@ -81,6 +83,8 @@ module Homebrew
end
Tap.each(&:link_manpages)
Homebrew.failed = true if ENV["HOMEBREW_UPDATE_FAILED"]
end
private

View File

@ -158,6 +158,10 @@ pull() {
CURRENT_REVISION="$(read_current_revision)"
export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$INITIAL_REVISION"
export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$CURRENT_REVISION"
if [[ "$INITIAL_REVISION" != "$CURRENT_REVISION" ]]
then
HOMEBREW_UPDATED="1"
fi
if ! git merge-base --is-ancestor "$INITIAL_REVISION" "$CURRENT_REVISION"
then
odie "Your $DIR HEAD is not a descendant of $UPSTREAM_BRANCH!"
@ -210,7 +214,13 @@ pull() {
--strategy-option=ignore-all-space
fi
export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(read_current_revision)"
CURRENT_REVISION="$(read_current_revision)"
export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$CURRENT_REVISION"
if [[ "$INITIAL_REVISION" != "$CURRENT_REVISION" ]]
then
HOMEBREW_UPDATED="1"
fi
trap '' SIGINT
@ -301,6 +311,9 @@ EOS
# kill all of subprocess on interrupt
trap '{ pkill -P $$; wait; exit 130; }' SIGINT
local update_failed_file="$HOMEBREW_REPOSITORY/.git/UPDATE_FAILED"
rm -f "$update_failed_file"
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
do
[[ -d "$DIR/.git" ]] || continue
@ -335,9 +348,11 @@ EOS
git fetch --force "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" 2>/dev/null
else
git fetch --force "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" || \
odie "Fetching $DIR failed!"
if ! git fetch --force "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH"
then
echo "Fetching $DIR failed!" >> "$update_failed_file"
fi
fi
) &
done
@ -345,6 +360,13 @@ EOS
wait
trap - SIGINT
if [[ -f "$update_failed_file" ]]
then
onoe < "$update_failed_file"
rm -f "$update_failed_file"
export HOMEBREW_UPDATE_FAILED="1"
fi
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
do
[[ -d "$DIR/.git" ]] || continue
@ -352,6 +374,13 @@ EOS
done
chdir "$HOMEBREW_REPOSITORY"
brew update-report "$@"
return $?
if [[ -n "$HOMEBREW_UPDATED" || -n "$HOMEBREW_UPDATE_FAILED" ]]
then
brew update-report "$@"
return $?
elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]]
then
echo "Already up-to-date."
fi
}

View File

@ -1,6 +1,6 @@
HOMEBREW_VERSION="0.9.9"
odie() {
onoe() {
if [[ -t 2 ]] # check whether stderr is a tty.
then
echo -ne "\033[4;31mError\033[0m: " >&2 # highlight Error with underline and red color
@ -13,6 +13,10 @@ odie() {
else
echo "$*" >&2
fi
}
odie() {
onoe "$@"
exit 1
}