2010-09-11 20:22:54 +01:00
|
|
|
module Homebrew extend self
|
2012-03-06 02:23:01 +00:00
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def update
|
|
|
|
abort "Please `brew install git' first." unless system "/usr/bin/which -s git"
|
|
|
|
|
2012-03-02 18:23:49 -06:00
|
|
|
# ensure GIT_CONFIG is unset as we need to operate on .git/config
|
|
|
|
ENV.delete('GIT_CONFIG')
|
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
cd HOMEBREW_REPOSITORY
|
|
|
|
git_init_if_necessary
|
2011-09-20 02:25:50 +01:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
report = Report.new
|
|
|
|
master_updater = Updater.new
|
|
|
|
master_updater.pull!
|
|
|
|
report.merge!(master_updater.report)
|
2011-06-12 17:07:59 +02:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
Dir["Library/Taps/*"].each do |tapd|
|
|
|
|
cd tapd do
|
|
|
|
updater = Updater.new
|
|
|
|
updater.pull!
|
|
|
|
report.merge!(updater.report) do |key, oldval, newval|
|
|
|
|
oldval.concat(newval)
|
|
|
|
end
|
2011-06-12 17:07:59 +02:00
|
|
|
end
|
2012-03-06 02:23:01 +00:00
|
|
|
end
|
2011-06-12 17:07:59 +02:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
if report.empty?
|
|
|
|
puts "Already up-to-date."
|
|
|
|
else
|
|
|
|
puts "Updated Homebrew from #{master_updater.initial_revision[0,8]} to #{master_updater.current_revision[0,8]}."
|
|
|
|
report.dump
|
|
|
|
end
|
|
|
|
end
|
2011-06-12 17:07:59 +02:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
private
|
2011-06-12 17:07:59 +02:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
def git_init_if_necessary
|
|
|
|
if Dir['.git/*'].empty?
|
|
|
|
safe_system "git init"
|
|
|
|
safe_system "git config core.autocrlf false"
|
|
|
|
safe_system "git remote add origin https://github.com/mxcl/homebrew.git"
|
|
|
|
safe_system "git fetch origin"
|
|
|
|
safe_system "git reset --hard origin/master"
|
2009-09-08 00:02:28 +02:00
|
|
|
end
|
2012-03-06 02:23:01 +00:00
|
|
|
rescue Exception
|
|
|
|
FileUtils.rm_rf ".git"
|
|
|
|
raise
|
2011-06-12 17:07:59 +02:00
|
|
|
end
|
2010-07-23 17:32:43 -07:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
end
|
2010-07-23 17:32:43 -07:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
class Updater
|
|
|
|
attr_reader :initial_revision, :current_revision
|
2010-07-23 17:32:43 -07:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
def pull!
|
|
|
|
safe_system "git checkout -q master"
|
2010-02-18 19:24:03 -05:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
@initial_revision = read_current_revision
|
2010-02-18 19:24:03 -05:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
# ensure we don't munge line endings on checkout
|
|
|
|
safe_system "git config core.autocrlf false"
|
2010-07-23 17:32:43 -07:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
args = ["pull"]
|
|
|
|
args << "--rebase" if ARGV.include? "--rebase"
|
|
|
|
args << "-q" unless ARGV.verbose?
|
|
|
|
args << "origin"
|
|
|
|
# the refspec ensures that 'origin/master' gets updated
|
|
|
|
args << "refs/heads/master:refs/remotes/origin/master"
|
|
|
|
|
|
|
|
safe_system "git", *args
|
2010-07-23 17:32:43 -07:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
@current_revision = read_current_revision
|
2010-07-23 17:32:43 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def report
|
2012-03-06 02:23:01 +00:00
|
|
|
map = Hash.new{ |h,k| h[k] = [] }
|
2011-08-26 13:04:08 +01:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
if initial_revision && initial_revision != current_revision
|
|
|
|
changes = `git diff-tree -r --name-status -z #{initial_revision} #{current_revision}`.split("\0")
|
|
|
|
changes.each_slice(2) do |status, file|
|
|
|
|
file = Pathname.pwd.join(file).relative_path_from(HOMEBREW_REPOSITORY)
|
|
|
|
map[status.to_sym] << file.to_s
|
|
|
|
end
|
2011-08-26 13:04:08 +01:00
|
|
|
end
|
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
map
|
2010-07-23 17:32:43 -07:00
|
|
|
end
|
|
|
|
|
2009-09-08 00:02:28 +02:00
|
|
|
private
|
2010-07-23 17:37:03 -07:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
def read_current_revision
|
|
|
|
`git rev-parse HEAD`.chomp
|
2011-06-12 17:07:59 +02:00
|
|
|
end
|
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
def `(cmd)
|
|
|
|
out = Kernel.`(cmd) #`
|
|
|
|
if $? && !$?.success?
|
|
|
|
$stderr.puts out
|
|
|
|
raise ErrorDuringExecution, "Failure while executing: #{cmd}"
|
|
|
|
end
|
|
|
|
ohai(cmd, out) if ARGV.verbose?
|
|
|
|
out
|
2011-06-12 17:07:59 +02:00
|
|
|
end
|
2012-03-06 02:23:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class Report < Hash
|
2011-06-12 17:07:59 +02:00
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
def dump
|
|
|
|
# Key Legend: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R)
|
|
|
|
|
|
|
|
dump_formula_report :A, "New Formula"
|
|
|
|
dump_formula_report :M, "Updated Formula"
|
|
|
|
dump_formula_report :D, "Deleted Formula"
|
|
|
|
dump_formula_report :R, "Renamed Formula"
|
|
|
|
# dump_new_commands
|
|
|
|
# dump_deleted_commands
|
2011-06-12 17:07:59 +02:00
|
|
|
end
|
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
def select_formula key
|
|
|
|
fetch(key, []).map do |path|
|
|
|
|
case path when %r{^Library/Formula}
|
|
|
|
File.basename(path, ".rb")
|
|
|
|
when %r{^Library/Taps/(\w+)-(\w+)/(.*)}
|
|
|
|
"#$1/#$2/#{File.basename(path, '.rb')}"
|
|
|
|
end
|
|
|
|
end.compact.sort
|
2011-06-12 17:07:59 +02:00
|
|
|
end
|
|
|
|
|
2012-03-06 02:23:01 +00:00
|
|
|
def dump_formula_report key, title
|
|
|
|
formula = select_formula(key)
|
|
|
|
unless formula.empty?
|
|
|
|
ohai title
|
|
|
|
puts_columns formula
|
2009-09-11 20:58:41 +02:00
|
|
|
end
|
2009-09-11 20:09:39 +02:00
|
|
|
end
|
2012-03-06 02:23:01 +00:00
|
|
|
|
2009-09-17 18:40:21 +01:00
|
|
|
end
|