class GemHadar

def version_log_diff(to_version: 'HEAD', from_version: nil)

Returns:
  • (String) - the git log output in patch format showing changes between the two versions

Raises:
  • (RuntimeError) - if the specified version tags are not found in the repository

Parameters:
  • from_version (String, nil) -- the starting version tag; if nil, it defaults based on to_version
  • to_version (String) -- the ending version tag or 'HEAD' to compare up to the latest commit
def version_log_diff(to_version: 'HEAD', from_version: nil)
  if to_version == 'HEAD'
    if from_version.blank?
      from_version = versions.last
    else
      unless versions.find { |v| v == from_version }
        fail "Could not find #{from_version.inspect}."
      end
    end
    `git log -p #{version_tag(from_version)}..HEAD`
  else
    unless versions.find { |v| v == to_version }
      fail "Could not find #{to_version.inspect}."
    end
    if from_version.blank?
      from_version = versions.each_cons(2).find do |previous_version, v|
        if v == to_version
          break previous_version
        end
      end
      unless from_version
        return `git log -p #{version_tag(to_version)}`
      end
    else
      unless versions.find { |v| v == from_version }
        fail "Could not find #{from_version.inspect}."
      end
    end
    `git log -p #{version_tag(from_version)}..#{version_tag(to_version)}`
  end
end