aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
authorMike McQuaid2016-04-11 09:31:50 +0100
committerMike McQuaid2016-04-11 09:31:50 +0100
commit4a7cd160c31969b79979ae9bd20afcf82d9513c0 (patch)
tree37f16512cb0f4fee1237e72310722c67e99af69c /Library/Homebrew/cmd
parent0382134cf87321166fb8f03223e21b1d242ad7cb (diff)
downloadbrew-4a7cd160c31969b79979ae9bd20afcf82d9513c0.tar.bz2
Auto-update when running `brew install`/`upgrade`.
Also, slightly tweak the behavior of `brew update` in this case so that it doesn't print annoying output and still allows the `brew edit` flow for people with `HOMEBREW_DEVELOPER` set.
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/update-report.rb11
-rw-r--r--Library/Homebrew/cmd/update.sh26
2 files changed, 32 insertions, 5 deletions
diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb
index 7aa5a528b..4d3b280f9 100644
--- a/Library/Homebrew/cmd/update-report.rb
+++ b/Library/Homebrew/cmd/update-report.rb
@@ -4,6 +4,13 @@ require "formulary"
require "descriptions"
module Homebrew
+ def update_preinstall_header
+ @header_already_printed ||= begin
+ ohai "Auto-updated Homebrew!" if ARGV.include?("--preinstall")
+ true
+ end
+ end
+
def update_report
install_core_tap_if_necessary
@@ -17,6 +24,7 @@ module Homebrew
end
if initial_revision != current_revision
+ update_preinstall_header
puts "Updated Homebrew from #{shorten_revision(initial_revision)} to #{shorten_revision(current_revision)}."
updated = true
end
@@ -37,13 +45,14 @@ module Homebrew
end
unless updated_taps.empty?
+ update_preinstall_header
puts "Updated #{updated_taps.size} tap#{plural(updated_taps.size)} " \
"(#{updated_taps.join(", ")})."
updated = true
end
if !updated
- puts "Already up-to-date."
+ puts "Already up-to-date." unless ARGV.include?("--preinstall")
elsif hub.empty?
puts "No changes to formulae."
else
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index a0c7cc7e7..a36b25fb0 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -213,7 +213,14 @@ pull() {
trap '' SIGINT
- pop_stash_message
+ if [[ -n "$HOMEBREW_DEVELOPER" ]] &&
+ [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]]
+ then
+ git checkout "${QUIET_ARGS[@]}" "$INITIAL_BRANCH"
+ pop_stash
+ else
+ pop_stash_message
+ fi
trap - SIGINT
}
@@ -231,6 +238,7 @@ homebrew-update() {
--debug) HOMEBREW_DEBUG=1;;
--rebase) HOMEBREW_REBASE=1 ;;
--simulate-from-current-branch) HOMEBREW_SIMULATE_FROM_CURRENT_BRANCH=1 ;;
+ --preinstall) HOMEBREW_UPDATE_PREINSTALL=1 ;;
--*) ;;
-*)
[[ "$option" = *v* ]] && HOMEBREW_VERBOSE=1;
@@ -316,11 +324,21 @@ EOS
--header "If-None-Match: \"$UPSTREAM_BRANCH_LOCAL_SHA\"" \
"https://api.github.com/repos/$UPSTREAM_REPOSITORY/commits/$UPSTREAM_BRANCH")"
[[ "$UPSTREAM_SHA_HTTP_CODE" = "304" ]] && exit
+ elif [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
+ then
+ # Don't try to do a `git fetch` that may take longer than expected.
+ exit
fi
- git fetch --force "${QUIET_ARGS[@]}" origin \
- "refs/heads/$UPSTREAM_BRANCH:refs/remotes/origin/$UPSTREAM_BRANCH" || \
- odie "Fetching $DIR failed!"
+ if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
+ then
+ 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!"
+ fi
) &
done