Properly distinguish between added and updated formulae.

This commit is contained in:
Eloy Duran 2009-09-20 17:54:10 +02:00 committed by Max Howell
parent af6c890294
commit 1022c23990
2 changed files with 23 additions and 8 deletions

View File

@ -101,7 +101,7 @@ class RefreshBrewMock < RefreshBrew
end
def expectations_met?
@expect.keys == @called
@expect.keys.sort == @called.sort
end
def inspect
@ -533,6 +533,7 @@ class BeerTasting <Test::Unit::TestCase
assert_equal false, updater.update_from_masterbrew!
assert updater.expectations_met?
assert updater.updated_formulae.empty?
assert updater.added_formulae.empty?
end
end
@ -546,6 +547,7 @@ class BeerTasting <Test::Unit::TestCase
assert_equal true, updater.update_from_masterbrew!
assert !updater.pending_formulae_changes?
assert updater.updated_formulae.empty?
assert updater.added_formulae.empty?
end
end
@ -558,7 +560,8 @@ class BeerTasting <Test::Unit::TestCase
assert_equal true, updater.update_from_masterbrew!
assert updater.pending_formulae_changes?
assert_equal %w{ antiword bash-completion xar yajl }, updater.updated_formulae
assert_equal %w{ xar yajl }, updater.updated_formulae
assert_equal %w{ antiword bash-completion ddrescue dict lua }, updater.added_formulae
end
end

View File

@ -26,12 +26,15 @@ class RefreshBrew
UPDATE_COMMAND = 'git pull origin master'
REVISION_COMMAND = 'git log -l -1 --pretty=format:%H'
GIT_UP_TO_DATE = 'Already up-to-date.'
UPDATED_FORMULA = %r{^\s+Library/Formula/(.+?)\.rb\s}
attr_reader :updated_formulae
formula_regexp = 'Library/Formula/(.+?)\.rb'
ADDED_FORMULA = %r{^\s+create mode \d+ #{formula_regexp}$}
UPDATED_FORMULA = %r{^\s+#{formula_regexp}\s}
attr_reader :added_formulae, :updated_formulae
def initialize
@updated_formulae = []
@added_formulae, @updated_formulae = [], []
end
# Performs an update of the homebrew source. Returns +true+ if a newer
@ -39,9 +42,18 @@ class RefreshBrew
def update_from_masterbrew!
git_checkout_masterbrew!
output = git_pull!
output.split("\n").each do |line|
@updated_formulae << $1 if line =~ UPDATED_FORMULA
output.split("\n").reverse.each do |line|
case line
when ADDED_FORMULA
@added_formulae << $1
when UPDATED_FORMULA
@updated_formulae << $1 unless @added_formulae.include?($1)
end
end
@added_formulae.sort!
@updated_formulae.sort!
output.strip != GIT_UP_TO_DATE
end
@ -63,7 +75,7 @@ class RefreshBrew
out = `#{cmd}`
unless $?.success?
puts out
raise "Failed while executing #{cmd}"
raise "Failed while executing #{cmd}"
end
ohai(cmd, out) if ARGV.verbose?
out