lib/terraspace_bundler/lockfile/version_comparer.rb in terraspace-bundler-0.2.0 vs lib/terraspace_bundler/lockfile/version_comparer.rb in terraspace-bundler-0.3.0

- old
+ new

@@ -8,36 +8,55 @@ def changed? @changed end + # Tricky logic, maybe spec this. + # + # no mods specified: + # terraspace bundle update # no mods specified => update all + # terraspace bundle install # no Terrafile.lock => update all + # mods specified: + # terraspace bundle update s3 # explicit mod => update s3 + # terraspace bundle install s3 # errors: not possible to specify module for install command + # + # Note: Install with specific mods wipes existing mods. Not worth it to support. + # def run @changed = false - strict_versions = %w[subfolder ref tag export_to] + + # Most props are "strict" version checks. So if user changes options generally in the mod line + # the Terrafile.lock will get updated, which is expected behavior. + props = @locked.props.keys + @current.props.keys + strict_versions = props.uniq.sort - [:sha] strict_versions.each do |version| @changed = @locked.send(version) != @current.send(version) if @changed @reason = reason_message(version) return @changed end end - # Loose version checks work a little different. If not set it explicitly, they will not be checked. - # Will use locked version in Terrafile.lock in this case. - # Note: Also, check the sha last since it triggers a git fetch. - loose_versions = %w[branch sha] - loose_versions.each do |version| - @changed = @current.send(version) && @current.send(version) != @locked.send(version) - if @changed - @reason = reason_message(version) - return @changed - end + # Lots of nuance with the sha check that works differently + # Only check when set. + # Also in update mode then always check it. + @changed = @current.sha && !@locked.sha.include?(@current.sha) || + update_mode? && !@current.latest_sha.include?(@locked.sha) + if @changed + @reason = reason_message("sha") + return @changed end @changed end def reason_message(version) - "Replacing mod: #{@current.name}. #{version} is different in Terrafile and Terrafile.lock" + "Replacing mod #{@current.name} because #{version} is different in Terrafile and Terrafile.lock" end + + def update_mode? + self.class.update_mode + end + + class_attribute :update_mode end end