Commit ed9cf9dc authored by Samuel Giddins's avatar Samuel Giddins

[SourcesManager] Update for new Source APIs

parent fb544ef6
...@@ -323,7 +323,7 @@ module Pod ...@@ -323,7 +323,7 @@ module Pod
changed_spec_paths = {} changed_spec_paths = {}
sources.each do |source| sources.each do |source|
UI.section "Updating spec repo `#{source.name}`" do UI.section "Updating spec repo `#{source.name}`" do
changed_source_paths = source.update(show_output && !config.verbose?) changed_source_paths = source.update(show_output)
changed_spec_paths[source] = changed_source_paths if changed_source_paths.count > 0 changed_spec_paths[source] = changed_source_paths if changed_source_paths.count > 0
check_version_information(source.repo) check_version_information(source.repo)
end end
...@@ -620,9 +620,14 @@ module Pod ...@@ -620,9 +620,14 @@ module Pod
extend Executable extend Executable
executable :git executable :git
def git(args, include_error: false)
Executable.capture_command('git', args, :capture => include_error ? :merge : :out).first.strip
end
def update_git_repo(show_output = false) def update_git_repo(show_output = false)
output = git! %w(pull --ff-only) Config.instance.with_changes(:verbose => show_output) do
UI.puts output if show_output git!(%w(pull --ff-only))
end
rescue rescue
UI.warn 'CocoaPods was not able to update the ' \ UI.warn 'CocoaPods was not able to update the ' \
"`#{name}` repo. If this is an unexpected issue " \ "`#{name}` repo. If this is an unexpected issue " \
......
...@@ -10,9 +10,10 @@ module Pod ...@@ -10,9 +10,10 @@ module Pod
set_up_test_repo set_up_test_repo
config.repos_dir = SpecHelper.tmp_repos_path config.repos_dir = SpecHelper.tmp_repos_path
WebMock::API.stub_request(:get, "https://api.github.com/repos/cocoapods/specs/commits/master") MasterSource.any_instance.stubs(:git_commit_hash).returns('commit hash')
.with(:headers => {'Accept'=>'application/vnd.github.chitauri-preview+sha'}) WebMock.stub_request(:get, 'https://api.github.com/repos/CocoaPods/Specs/commits/master').
.to_return(:status => 200, :body => '', :headers => {}) with(:headers => { 'Accept' => 'application/vnd.github.chitauri-preview+sha', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'If-None-Match' => '"commit hash"', 'User-Agent' => 'CocoaPods' }).
to_return(:status => 200, :body => '', :headers => {})
end end
after do after do
......
...@@ -295,37 +295,36 @@ module Pod ...@@ -295,37 +295,36 @@ module Pod
describe 'Updating Sources' do describe 'Updating Sources' do
extend SpecHelper::TemporaryRepos extend SpecHelper::TemporaryRepos
before do
WebMock::API.stub_request(:get, "https://api.github.com/repos/cocoapods/specs/commits/master")
.with(:headers => {'Accept'=>'application/vnd.github.chitauri-preview+sha'})
.to_return(:status => 200, :body => '', :headers => {})
end
after do before do
WebMock.reset! MasterSource.any_instance.stubs(:requires_update?).returns(true)
end end
it 'updates source backed by a git repository' do it 'updates source backed by a git repository' do
set_up_test_repo_for_update set_up_test_repo_for_update
SourcesManager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil) SourcesManager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil)
MasterSource.any_instance.expects(:git!).with(%w(pull --ff-only))
SourcesManager.update(test_repo_path.basename.to_s, true) SourcesManager.update(test_repo_path.basename.to_s, true)
UI.output.should.match /is up to date/
end end
it 'uses the only fast forward git option' do it 'uses the only fast forward git option' do
set_up_test_repo_for_update set_up_test_repo_for_update
Source.any_instance.expects(:git!).with { |options| options.should.include? '--ff-only' } MasterSource.any_instance.expects(:git!).with { |options| options.should.include? '--ff-only' }
SourcesManager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil) SourcesManager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil)
SourcesManager.update(test_repo_path.basename.to_s, true) SourcesManager.update(test_repo_path.basename.to_s, true)
end end
it 'prints a warning if the update failed' do it 'prints a warning if the update failed' do
UI.warnings = ''
set_up_test_repo_for_update set_up_test_repo_for_update
Dir.chdir(test_repo_path) do Source.any_instance.stubs(:git).with(%w(rev-parse HEAD)).returns('aabbccd')
`git remote set-url origin file:///dev/null` Source.any_instance.stubs(:git).with(%w(diff --name-only aabbccd..HEAD)).returns('')
end MasterSource.any_instance.expects(:git!).with(%w(pull --ff-only)).raises(<<-EOS)
fatal: '/dev/null' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
EOS
SourcesManager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil) SourcesManager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil)
SourcesManager.update(test_repo_path.basename.to_s, true) SourcesManager.update(test_repo_path.basename.to_s, true)
UI.warnings.should.include('not able to update the `master` repo') UI.warnings.should.include('not able to update the `master` repo')
......
...@@ -418,6 +418,7 @@ module Pod ...@@ -418,6 +418,7 @@ module Pod
validator.stubs(:validate_url) validator.stubs(:validate_url)
git = Executable.which(:git) git = Executable.which(:git)
Executable.stubs(:which).with('git').returns(git) Executable.stubs(:which).with('git').returns(git)
Executable.stubs(:capture_command).with('git', ['config', '--get', 'remote.origin.url'], :capture => :out).returns(['https://github.com/CocoaPods/Specs.git'])
Executable.stubs(:which).with(:xcrun) Executable.stubs(:which).with(:xcrun)
Executable.expects(:which).with('xcodebuild').times(4).returns('/usr/bin/xcodebuild') Executable.expects(:which).with('xcodebuild').times(4).returns('/usr/bin/xcodebuild')
command = %w(clean build -workspace App.xcworkspace -scheme App -configuration Release) command = %w(clean build -workspace App.xcworkspace -scheme App -configuration Release)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment