Make sure git commands in RefreshBrew are executed with the proper working dir.

This commit is contained in:
Eloy Duran 2009-09-11 10:52:32 +02:00
parent 52efea0e7d
commit c9f056c327
2 changed files with 41 additions and 24 deletions

View File

@ -25,12 +25,16 @@ class RefreshBrew
end end
def current_revision def current_revision
`#{REVISION_COMMAND}`.strip in_prefix { `#{REVISION_COMMAND}`.strip }
end end
private private
def in_prefix
Dir.chdir(HOMEBREW_PREFIX) { yield }
end
def git_pull! def git_pull!
Dir.chdir(HOMEBREW_PREFIX) { `#{UPDATE_COMMAND}` } in_prefix { `#{UPDATE_COMMAND}` }
end end
end end

View File

@ -502,41 +502,54 @@ class BeerTasting <Test::Unit::TestCase
end end
def test_updater_update_homebrew_without_any_changes def test_updater_update_homebrew_without_any_changes
updater = RefreshBrewMock.new outside_prefix do
updater.in_prefix_expect("git pull origin masterbrew", "Already up-to-date.\n") updater = RefreshBrewMock.new
updater.in_prefix_expect("git pull origin masterbrew", "Already up-to-date.\n")
assert_equal false, updater.update_from_masterbrew! assert_equal false, updater.update_from_masterbrew!
assert updater.updated_formulae.empty? assert updater.updated_formulae.empty?
end
end end
def test_updater_update_homebrew_without_formulae_changes def test_updater_update_homebrew_without_formulae_changes
updater = RefreshBrewMock.new outside_prefix do
output = fixture('update_git_pull_output_without_formulae_changes') updater = RefreshBrewMock.new
updater.in_prefix_expect("git pull origin masterbrew", output) output = fixture('update_git_pull_output_without_formulae_changes')
updater.in_prefix_expect("git pull origin masterbrew", output)
assert_equal true, updater.update_from_masterbrew! assert_equal true, updater.update_from_masterbrew!
assert !updater.pending_formulae_changes? assert !updater.pending_formulae_changes?
assert updater.updated_formulae.empty? assert updater.updated_formulae.empty?
end
end end
def test_updater_update_homebrew_with_formulae_changes def test_updater_update_homebrew_with_formulae_changes
updater = RefreshBrewMock.new outside_prefix do
output = fixture('update_git_pull_output_with_formulae_changes') updater = RefreshBrewMock.new
updater.in_prefix_expect("git pull origin masterbrew", output) output = fixture('update_git_pull_output_with_formulae_changes')
updater.in_prefix_expect("git pull origin masterbrew", output)
assert_equal true, updater.update_from_masterbrew! assert_equal true, updater.update_from_masterbrew!
assert updater.pending_formulae_changes? assert updater.pending_formulae_changes?
assert_equal %w{ antiword bash-completion xar yajl }, updater.updated_formulae assert_equal %w{ antiword bash-completion xar yajl }, updater.updated_formulae
end
end end
def test_updater_returns_current_revision def test_updater_returns_current_revision
updater = RefreshBrewMock.new outside_prefix do
updater.in_prefix_expect('git log -l -1 --pretty=format:%H', 'the-revision-hash') updater = RefreshBrewMock.new
assert_equal 'the-revision-hash', updater.current_revision updater.in_prefix_expect('git log -l -1 --pretty=format:%H', 'the-revision-hash')
assert_equal 'the-revision-hash', updater.current_revision
end
end end
private private
OUTSIDE_PREFIX = '/tmp'
def outside_prefix
Dir.chdir(OUTSIDE_PREFIX) { yield }
end
def fixture(name) def fixture(name)
self.class.fixture_data[name] self.class.fixture_data[name]
end end