Commit fb19f1dd authored by Danielle Tomlinson's avatar Danielle Tomlinson Committed by GitHub

Merge pull request #6206 from CocoaPods/dani_reset_updates

[Sources] reset --hard rather than git pull
parents 5c0989aa 4b88a6a0
......@@ -25,6 +25,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Johannes Plunien](https://github.com/plu)
[#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
* Fix default LD_RUNPATH_SEARCH_PATHS for host targets.
......
......@@ -104,7 +104,9 @@ module Pod
def update_git_repo(show_output = false)
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
rescue
raise Informative, 'CocoaPods was not able to update the ' \
......@@ -118,7 +120,7 @@ module Pod
def update_git_repo(show_output = false)
if repo.join('.git', 'shallow').file?
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
super
......
......@@ -90,16 +90,24 @@ module Pod
it 'updates source backed by a git repository' do
set_up_test_repo_for_update
@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
set_up_test_repo_for_update
MasterSource.any_instance.expects(:git!).with { |options| options.should.include? '--ff-only' }
@sources_manager.expects(:update_search_index_if_needed_in_background).with({}).returns(nil)
repo_update = 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("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)
end
......@@ -107,12 +115,29 @@ module Pod
set_up_test_repo_for_update
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)
MasterSource.any_instance.expects(:git!).with do |options|
options.join(' ') == %W(-C #{test_repo_path} fetch --unshallow).join(' ')
end
MasterSource.any_instance.expects(:git!).with do |options|
options.join(' ') == %W(-C #{test_repo_path} pull --ff-only).join(' ')
end
repo_update = sequence('repo update')
MasterSource.any_instance.
expects(:git!).
with(%W(-C #{test_repo_path} fetch --unshallow)).
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)
UI.output.should.match /deep fetch.+`master`.+improve future performance/
......@@ -126,9 +151,7 @@ module Pod
Source.any_instance.stubs(:git).with do |options|
options.join(' ') == %W(-C #{test_repo_path} diff --name-only aabbccd..HEAD).join(' ')
end.returns('')
MasterSource.any_instance.expects(:git!).with do |options|
options.join(' ') == %W(-C #{test_repo_path} pull --ff-only).join(' ')
end.raises(<<-EOS)
MasterSource.any_instance.expects(:git!).with(%W(-C #{test_repo_path} fetch origin)).raises(<<-EOS)
fatal: '/dev/null' does not appear to be a git 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