class XMigra::GitSpecifics::VersionComparator

Public Class Methods

new(vcs_object, options={}) click to toggle source

vcs_object.kind_of?(GitSpecifics)

# File lib/xmigra/vcs_support/git.rb, line 327
def initialize(vcs_object, options={})
  @object = vcs_object
  @expected_content_method = options[:expected_content_method]
  @path_statuses = Hash.new do |h, file_path|
    file_path = Pathname(file_path).expand_path
    next h[file_path] if h.has_key?(file_path)
    h[file_path] = @object.git_retrieve_status(file_path)
  end
end

Public Instance Methods

latest_commit(file_path) click to toggle source
# File lib/xmigra/vcs_support/git.rb, line 381
def latest_commit(file_path)
  @object.git(
    :log,
    '--pretty=format:%H',
    '-1',
    '--',
    file_path
  )
end
relative_version(file_path) click to toggle source
# File lib/xmigra/vcs_support/git.rb, line 337
def relative_version(file_path)
  # Comparing @object.file_path (a) to file_path (b)
  #
  # returns: :newer, :equal, :older, or :missing
  
  b_status = @path_statuses[file_path]
  
  return :missing if b_status.nil? || b_status.include?('D')
  
  a_status = @path_statuses[@object.file_path]
  
  if a_status == '??' || a_status[0] == 'A'
    if b_status == '??' || b_status[0] == 'A' || b_status.include?('M')
      return relative_version_by_content(file_path)
    end
    
    return :older
  elsif a_status == '  '
    # Look for re-introduction of a declarative that was previously destroyed or renounced
    if (b_status == '??' || b_status[0] == 'A') && [:renunciation, :destruction].include?(@object.goal)
      return :unimplemented
    end
    
    return :newer unless b_status == '  '
    
    return begin
      a_commit = latest_commit(@object.file_path)
      b_commit = latest_commit(file_path)
      
      if @object.git_commits_in? a_commit..b_commit, file_path
        :newer
      elsif @object.git_commits_in? b_commit..a_commit, @object.file_path
        :older
      else
        :equal
      end
    end
  elsif b_status == '  '
    return :older
  else
    return relative_version_by_content(file_path)
  end
end
relative_version_by_content(file_path) click to toggle source
# File lib/xmigra/vcs_support/git.rb, line 391
def relative_version_by_content(file_path)
  ec_method = @expected_content_method
  if !ec_method || @object.send(ec_method, file_path)
    return :equal
  else
    return :newer
  end
end