aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2016-05-03 14:24:41 +0100
committerMike McQuaid2016-05-03 14:24:41 +0100
commit60e3737f17614e43856af6f1ccfba663374a5f43 (patch)
tree71c37685ebbeaadafe759cb491da0a739edccf7e /Library
parent489a1d8f4377f1177f07804b799471faa8a01c7a (diff)
downloadbrew-60e3737f17614e43856af6f1ccfba663374a5f43.tar.bz2
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).
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/update-report.rb6
-rw-r--r--Library/Homebrew/cmd/update.sh41
-rw-r--r--Library/brew.sh6
3 files changed, 45 insertions, 8 deletions
diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb
index 1d9822ae5..9339a63d9 100644
--- a/Library/Homebrew/cmd/update-report.rb
+++ b/Library/Homebrew/cmd/update-report.rb
@@ -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
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index ba5ed2598..cff66f7b4 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -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
}
diff --git a/Library/brew.sh b/Library/brew.sh
index 33f446503..76cb2f9e9 100644
--- a/Library/brew.sh
+++ b/Library/brew.sh
@@ -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
}