Improve version handling on component install tasks

Fixes an issue where, when using branch versions, the component wouldn't
be updated after the first branch checkout. We also save one step, since
checking out the FETCH_HEAD with `-f` already does what `reset --hard`
did.
This commit is contained in:
Alejandro Rodríguez 2017-07-20 17:30:29 -04:00
parent 729ac897fd
commit c9c0606297
2 changed files with 4 additions and 20 deletions

View File

@ -153,7 +153,6 @@ module Gitlab
clone_repo(repo, target_dir) unless Dir.exist?(target_dir) clone_repo(repo, target_dir) unless Dir.exist?(target_dir)
checkout_version(version, target_dir) checkout_version(version, target_dir)
reset_to_version(version, target_dir)
end end
def clone_repo(repo, target_dir) def clone_repo(repo, target_dir)
@ -161,12 +160,8 @@ module Gitlab
end end
def checkout_version(version, target_dir) def checkout_version(version, target_dir)
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} fetch --quiet]) run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} fetch --quiet origin #{version}])
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} checkout --quiet #{version}]) run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} checkout -f --quiet FETCH_HEAD --])
end
def reset_to_version(version, target_dir)
run_command!(%W[#{Gitlab.config.git.bin_path} -C #{target_dir} reset --hard #{version}])
end end
end end
end end

View File

@ -20,7 +20,6 @@ describe Gitlab::TaskHelpers do
it 'checkout the version and reset to it' do it 'checkout the version and reset to it' do
expect(subject).to receive(:checkout_version).with(tag, clone_path) expect(subject).to receive(:checkout_version).with(tag, clone_path)
expect(subject).to receive(:reset_to_version).with(tag, clone_path)
subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path) subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
end end
@ -31,7 +30,6 @@ describe Gitlab::TaskHelpers do
it 'checkout the version and reset to it with a branch name' do it 'checkout the version and reset to it with a branch name' do
expect(subject).to receive(:checkout_version).with(branch, clone_path) expect(subject).to receive(:checkout_version).with(branch, clone_path)
expect(subject).to receive(:reset_to_version).with(branch, clone_path)
subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path) subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
end end
@ -70,20 +68,11 @@ describe Gitlab::TaskHelpers do
describe '#checkout_version' do describe '#checkout_version' do
it 'clones the repo in the target dir' do it 'clones the repo in the target dir' do
expect(subject) expect(subject)
.to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} fetch --quiet]) .to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} fetch --quiet origin #{tag}])
expect(subject) expect(subject)
.to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} checkout --quiet #{tag}]) .to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} checkout -f --quiet FETCH_HEAD --])
subject.checkout_version(tag, clone_path) subject.checkout_version(tag, clone_path)
end end
end end
describe '#reset_to_version' do
it 'resets --hard to the given version' do
expect(subject)
.to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} reset --hard #{tag}])
subject.reset_to_version(tag, clone_path)
end
end
end end