Sha256: e2316046cea35522d61d5f5e4e763030f21fec1bd5b30ec17a2cdd7c92bbe73d

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

class External

  def self.externals_in_directory(parent, app)
    exts = []
    prop = `svn propget svn:externals #{parent}`
    prop.split("\n").each do |prop_line|
      next if prop_line.strip.empty?
      exts << External.new(parent, prop_line, app)
    end
    exts
  end

  attr_reader :name, :path, :url, :revision, :app

  def initialize(parent, property, app = nil)
    match =  /^(\S+)\s+(-r\s*\d*\s+)?(\S+)\s*$/.match(property)
    @name = match[1]
    @revision = match[2] ? match[2].gsub(/\D/,'').to_i : nil
    @url = match[3]
    @path = "#{parent}/#{@name}"
    @app = app
  end

  def say(msg)
    app.say(msg)
  end

  def svn(cmd)
    app.svn(cmd)
  end

  def run(cmd, return_output = false)
    app.run(cmd, return_output)
  end

  def ==(other)
    (path == other.path and url == other.url)
  end

  def to_s
    "External[name=#{name}, path=#{path}, url=#{url}, revision=#{revision}]"
  end

  def revision_actual
    info = `svn info #{@path}`
    info.grep(/^Revision:/).first.gsub(/Revision: /, '').to_i
  end

  def should_update?
    revision == nil || revision_actual != revision
  end

  #todo: test? (indirectly tested via root.rb)
  def update
    say "Updating external #{path}"
    run("svn cleanup #{path}")
    rev = revision.nil? ? '' : "-r#{revision}"
    svn("up #{rev} #{path} | grep -v 'At revision'")
  end

  def checkout
    say "Checking out external #{path}"
    rev = revision.nil? ? '' : "-r#{revision}"
    svn("co #{rev} #{url} #{path}")
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sub-0.3.0 lib/sub/external.rb