[Sources] reset --hard rather than git pull

parent 5c0989aa
...@@ -25,6 +25,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -25,6 +25,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Johannes Plunien](https://github.com/plu) [Johannes Plunien](https://github.com/plu)
[#5512](https://github.com/CocoaPods/CocoaPods/issues/5512) [#5512](https://github.com/CocoaPods/CocoaPods/issues/5512)
* Use fetch and reset rather than a pull when updating specs repos.
[Danielle Tomlinson](https://github.com/dantoml)
[#6206](https://github.com/CocoaPods/CocoaPods/pull/6206)
##### Bug Fixes ##### Bug Fixes
* Fix default LD_RUNPATH_SEARCH_PATHS for host targets. * Fix default LD_RUNPATH_SEARCH_PATHS for host targets.
......
...@@ -104,7 +104,9 @@ module Pod ...@@ -104,7 +104,9 @@ module Pod
def update_git_repo(show_output = false) def update_git_repo(show_output = false)
Config.instance.with_changes(:verbose => show_output) do Config.instance.with_changes(:verbose => show_output) do
git!(['-C', repo, 'pull', '--ff-only']) git!(%W(-C #{repo} fetch origin))
current_branch = git!(%W(-C #{repo} rev-parse --abbrev-ref HEAD)).strip
git!(%W(-C #{repo} reset --hard origin/#{current_branch}))
end end
rescue rescue
raise Informative, 'CocoaPods was not able to update the ' \ raise Informative, 'CocoaPods was not able to update the ' \
...@@ -118,7 +120,7 @@ module Pod ...@@ -118,7 +120,7 @@ module Pod
def update_git_repo(show_output = false) def update_git_repo(show_output = false)
if repo.join('.git', 'shallow').file? if repo.join('.git', 'shallow').file?
UI.info "Performing a deep fetch of the `#{name}` specs repo to improve future performance" do UI.info "Performing a deep fetch of the `#{name}` specs repo to improve future performance" do
git!(['-C', repo, 'fetch', '--unshallow']) git!(%W(-C #{repo} fetch --unshallow))
end end
end end
super super
......
...@@ -90,16 +90,24 @@ module Pod ...@@ -90,16 +90,24 @@ module Pod
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
@sources_manager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil) @sources_manager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil)
MasterSource.any_instance.expects(:git!).with do |options|
options.join(' ') == %W(-C #{test_repo_path} pull --ff-only).join(' ')
end
@sources_manager.update(test_repo_path.basename.to_s, true)
end
it 'uses the only fast forward git option' do repo_update = sequence('repo update')
set_up_test_repo_for_update MasterSource.any_instance.
MasterSource.any_instance.expects(:git!).with { |options| options.should.include? '--ff-only' } expects(:git!).
@sources_manager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil) with(%W(-C #{test_repo_path} fetch origin)).
in_sequence(repo_update)
MasterSource.any_instance.
expects(:git!).
with(%W(-C #{test_repo_path} rev-parse --abbrev-ref HEAD)).
returns("my-special-branch\n").
in_sequence(repo_update)
MasterSource.any_instance.
expects(:git!).
with(%W(-C #{test_repo_path} reset --hard origin/my-special-branch)).
in_sequence(repo_update)
@sources_manager.update(test_repo_path.basename.to_s, true) @sources_manager.update(test_repo_path.basename.to_s, true)
end end
...@@ -107,12 +115,29 @@ module Pod ...@@ -107,12 +115,29 @@ module Pod
set_up_test_repo_for_update set_up_test_repo_for_update
test_repo_path.join('.git', 'shallow').open('w') { |f| f << 'a' * 40 } test_repo_path.join('.git', 'shallow').open('w') { |f| f << 'a' * 40 }
@sources_manager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil) @sources_manager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil)
MasterSource.any_instance.expects(:git!).with do |options|
options.join(' ') == %W(-C #{test_repo_path} fetch --unshallow).join(' ') repo_update = sequence('repo update')
end MasterSource.any_instance.
MasterSource.any_instance.expects(:git!).with do |options| expects(:git!).
options.join(' ') == %W(-C #{test_repo_path} pull --ff-only).join(' ') with(%W(-C #{test_repo_path} fetch --unshallow)).
end in_sequence(repo_update)
MasterSource.any_instance.
expects(:git!).
with(%W(-C #{test_repo_path} fetch origin)).
in_sequence(repo_update)
MasterSource.any_instance.
expects(:git!).
with(%W(-C #{test_repo_path} rev-parse --abbrev-ref HEAD)).
returns("master\n").
in_sequence(repo_update)
MasterSource.any_instance.
expects(:git!).
with(%W(-C #{test_repo_path} reset --hard origin/master)).
in_sequence(repo_update)
@sources_manager.update(test_repo_path.basename.to_s, true) @sources_manager.update(test_repo_path.basename.to_s, true)
UI.output.should.match /deep fetch.+`master`.+improve future performance/ UI.output.should.match /deep fetch.+`master`.+improve future performance/
...@@ -126,9 +151,7 @@ module Pod ...@@ -126,9 +151,7 @@ module Pod
Source.any_instance.stubs(:git).with do |options| Source.any_instance.stubs(:git).with do |options|
options.join(' ') == %W(-C #{test_repo_path} diff --name-only aabbccd..HEAD).join(' ') options.join(' ') == %W(-C #{test_repo_path} diff --name-only aabbccd..HEAD).join(' ')
end.returns('') end.returns('')
MasterSource.any_instance.expects(:git!).with do |options| MasterSource.any_instance.expects(:git!).with(%W(-C #{test_repo_path} fetch origin)).raises(<<-EOS)
options.join(' ') == %W(-C #{test_repo_path} pull --ff-only).join(' ')
end.raises(<<-EOS)
fatal: '/dev/null' does not appear to be a git repository fatal: '/dev/null' does not appear to be a git repository
fatal: Could not read from remote repository. fatal: Could not read from remote repository.
......
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