Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-update when running brew install/upgrade. #50

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
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

Expand All @@ -17,6 +24,7 @@ def update_report
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
Expand All @@ -37,13 +45,14 @@ def update_report
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
Expand Down
26 changes: 22 additions & 4 deletions Library/Homebrew/cmd/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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
}
Expand All @@ -226,6 +233,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;
Expand Down Expand Up @@ -311,11 +319,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

Expand Down
17 changes: 15 additions & 2 deletions Library/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ then
& disown
fi

update-preinstall() {
[[ -n "$HOMEBREW_AUTO_UPDATE" ]] || return
[[ -z "$HOMEBREW_NO_AUTO_UPDATE" ]] || return

if [[ "$HOMEBREW_COMMAND" = "install" || "$HOMEBREW_COMMAND" = "upgrade" ]]
then
# Hide shellcheck complaint:
# shellcheck source=/dev/null
source "$HOMEBREW_LIBRARY/Homebrew/cmd/update.sh"
homebrew-update --preinstall
fi
}

if [[ -n "$HOMEBREW_BASH_COMMAND" ]]
then
# source rather than executing directly to ensure the entire file is read into
Expand All @@ -240,9 +253,9 @@ then
# Hide shellcheck complaint:
# shellcheck source=/dev/null
source "$HOMEBREW_BASH_COMMAND"
{ "homebrew-$HOMEBREW_COMMAND" "$@"; exit $?; }
{ update-preinstall; "homebrew-$HOMEBREW_COMMAND" "$@"; exit $?; }
else
# Unshift command back into argument list (unless argument list was empty).
[[ "$HOMEBREW_ARG_COUNT" -gt 0 ]] && set -- "$HOMEBREW_COMMAND" "$@"
exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/brew.rb" "$@"
{ update-preinstall; exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/brew.rb" "$@"; }
fi