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:
parent
489a1d8f43
commit
60e3737f17
@ -70,7 +70,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
if !updated
|
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?
|
elsif hub.empty?
|
||||||
puts "No changes to formulae."
|
puts "No changes to formulae."
|
||||||
else
|
else
|
||||||
@ -81,6 +83,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
Tap.each(&:link_manpages)
|
Tap.each(&:link_manpages)
|
||||||
|
|
||||||
|
Homebrew.failed = true if ENV["HOMEBREW_UPDATE_FAILED"]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -158,6 +158,10 @@ pull() {
|
|||||||
CURRENT_REVISION="$(read_current_revision)"
|
CURRENT_REVISION="$(read_current_revision)"
|
||||||
export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$INITIAL_REVISION"
|
export HOMEBREW_UPDATE_BEFORE"$TAP_VAR"="$INITIAL_REVISION"
|
||||||
export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$CURRENT_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"
|
if ! git merge-base --is-ancestor "$INITIAL_REVISION" "$CURRENT_REVISION"
|
||||||
then
|
then
|
||||||
odie "Your $DIR HEAD is not a descendant of $UPSTREAM_BRANCH!"
|
odie "Your $DIR HEAD is not a descendant of $UPSTREAM_BRANCH!"
|
||||||
@ -210,7 +214,13 @@ pull() {
|
|||||||
--strategy-option=ignore-all-space
|
--strategy-option=ignore-all-space
|
||||||
fi
|
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
|
trap '' SIGINT
|
||||||
|
|
||||||
@ -301,6 +311,9 @@ EOS
|
|||||||
# kill all of subprocess on interrupt
|
# kill all of subprocess on interrupt
|
||||||
trap '{ pkill -P $$; wait; exit 130; }' SIGINT
|
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/*/*
|
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
|
||||||
do
|
do
|
||||||
[[ -d "$DIR/.git" ]] || continue
|
[[ -d "$DIR/.git" ]] || continue
|
||||||
@ -335,9 +348,11 @@ EOS
|
|||||||
git fetch --force "${QUIET_ARGS[@]}" origin \
|
git fetch --force "${QUIET_ARGS[@]}" origin \
|
||||||
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" 2>/dev/null
|
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" 2>/dev/null
|
||||||
else
|
else
|
||||||
git fetch --force "${QUIET_ARGS[@]}" origin \
|
if ! git fetch --force "${QUIET_ARGS[@]}" origin \
|
||||||
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" || \
|
"refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH"
|
||||||
odie "Fetching $DIR failed!"
|
then
|
||||||
|
echo "Fetching $DIR failed!" >> "$update_failed_file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
) &
|
) &
|
||||||
done
|
done
|
||||||
@ -345,6 +360,13 @@ EOS
|
|||||||
wait
|
wait
|
||||||
trap - SIGINT
|
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/*/*
|
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
|
||||||
do
|
do
|
||||||
[[ -d "$DIR/.git" ]] || continue
|
[[ -d "$DIR/.git" ]] || continue
|
||||||
@ -352,6 +374,13 @@ EOS
|
|||||||
done
|
done
|
||||||
|
|
||||||
chdir "$HOMEBREW_REPOSITORY"
|
chdir "$HOMEBREW_REPOSITORY"
|
||||||
|
|
||||||
|
if [[ -n "$HOMEBREW_UPDATED" || -n "$HOMEBREW_UPDATE_FAILED" ]]
|
||||||
|
then
|
||||||
brew update-report "$@"
|
brew update-report "$@"
|
||||||
return $?
|
return $?
|
||||||
|
elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]]
|
||||||
|
then
|
||||||
|
echo "Already up-to-date."
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
HOMEBREW_VERSION="0.9.9"
|
HOMEBREW_VERSION="0.9.9"
|
||||||
|
|
||||||
odie() {
|
onoe() {
|
||||||
if [[ -t 2 ]] # check whether stderr is a tty.
|
if [[ -t 2 ]] # check whether stderr is a tty.
|
||||||
then
|
then
|
||||||
echo -ne "\033[4;31mError\033[0m: " >&2 # highlight Error with underline and red color
|
echo -ne "\033[4;31mError\033[0m: " >&2 # highlight Error with underline and red color
|
||||||
@ -13,6 +13,10 @@ odie() {
|
|||||||
else
|
else
|
||||||
echo "$*" >&2
|
echo "$*" >&2
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
odie() {
|
||||||
|
onoe "$@"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user