Skip to content

Commit

Permalink
(maint) Fixes behavior when comparing ref for update.
Browse files Browse the repository at this point in the history
When doing starting an update, pdk needs to be able to handle
refs that are tags or branch heads and be able to compare sha when
they are branches.
  • Loading branch information
bmjen committed Feb 22, 2018
1 parent 25bb823 commit d5bdcec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions lib/pdk/module/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ class Update < Convert
def run
stage_changes!

unless update_manager.changes?
if get_sha(current_version) == get_sha(new_version)
PDK.logger.info _('This module is already up to date with version %{version} of the template.') % {
version: new_version,
}
else
PDK::Report.default_target.puts(_('No changes required.'))
end
return
end

PDK.logger.info(update_message)

print_summary
full_report('update_report.txt') unless update_manager.changes[:modified].empty?

if !update_manager.changes? && get_sha(current_version) == get_sha(new_version)
PDK.logger.info _('This module is already up to date with version %{version} of the template.') % {
version: new_version,
}
return
end

return if noop?

unless force?
Expand Down Expand Up @@ -74,8 +78,6 @@ def describe_ref_to_s(describe_ref)

if data[:base].start_with?('heads/')
"#{data[:base].gsub(%r{^heads/}, '')}@#{data[:sha]}"
elsif data[:sha]
"#{data[:base]}@#{data[:sha]}"
else
data[:base]
end
Expand All @@ -86,11 +88,11 @@ def new_template_version
end

def fetch_remote_version(version)
data = GIT_DESCRIBE_PATTERN.match(current_template_version)

return version if data.nil?
return version unless version.include?('/')

branch = version.partition('/').last if version.include?('/')

data = GIT_DESCRIBE_PATTERN.match(current_template_version)
sha_length = data[:sha].length - 1
"#{branch}@#{PDK::Util::Git.ls_remote(template_url, "refs/heads/#{branch}")[0..sha_length]}"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

describe command('pdk update') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(no_output) }
its(:stderr) { is_expected.to match(%r{already up to date}i) }
its(:stdout) { is_expected.to match(%r{No changes required}i) }
its(:stderr) { is_expected.to match(no_output) }
end

describe file('update_report.txt') do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/pdk/module/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
let(:template_ref) { '1.3.2-0-g07678c8' }

it 'returns the tag name' do
is_expected.to eq('1.3.2@07678c8')
is_expected.to eq('1.3.2')
end
end

Expand Down

0 comments on commit d5bdcec

Please sign in to comment.