class Dandelion::Workspace

Attributes

adapter[R]
config[R]

Public Class Methods

new(repo, adapter, config = nil) click to toggle source
# File lib/dandelion/workspace.rb, line 7
def initialize(repo, adapter, config = nil)
  @repo = repo
  @adapter = adapter

  if config.is_a?(Hash)
    @config = Config.new(data: config)
  else
    @config = config || Config.new
  end

  @config.defaults(revision_file: '.revision', local_path: '')
end

Public Instance Methods

changeset() click to toggle source
# File lib/dandelion/workspace.rb, line 24
def changeset
  Changeset.new(tree, remote_commit, @config)
end
local_commit() click to toggle source
# File lib/dandelion/workspace.rb, line 28
def local_commit
  lookup(local_sha)
end
lookup(val) click to toggle source
# File lib/dandelion/workspace.rb, line 41
def lookup(val)
  result = lookup_sha(val) ||
    lookup_ref(val) ||
    lookup_ref("refs/tags/#{val}") ||
    lookup_ref("refs/branches/#{val}") ||
    lookup_ref("refs/heads/#{val}")

  raise RevisionError.new(val) unless result

  result
end
remote_commit() click to toggle source
# File lib/dandelion/workspace.rb, line 32
def remote_commit
  sha = remote_sha
  sha ? lookup(remote_sha) : nil
end
remote_commit=(commit) click to toggle source
# File lib/dandelion/workspace.rb, line 37
def remote_commit=(commit)
  self.remote_sha = commit.oid
end
tree() click to toggle source
# File lib/dandelion/workspace.rb, line 20
def tree
  Tree.new(@repo, local_commit)
end

Private Instance Methods

local_sha() click to toggle source
# File lib/dandelion/workspace.rb, line 68
def local_sha
  @config[:revision] || @repo.head.target.oid
end
lookup_ref(val) click to toggle source
# File lib/dandelion/workspace.rb, line 61
def lookup_ref(val)
  ref = @repo.ref(val)
  lookup_sha(ref.target.oid) if ref
rescue Rugged::ReferenceError
  nil
end
lookup_sha(val) click to toggle source
# File lib/dandelion/workspace.rb, line 55
def lookup_sha(val)
  @repo.lookup(val)
rescue Rugged::OdbError, Rugged::InvalidError
  nil
end
remote_sha() click to toggle source
# File lib/dandelion/workspace.rb, line 72
def remote_sha
  @remote_sha ||= begin
    sha = @adapter.read(@config[:revision_file])
    sha.chomp if sha
  end
end
remote_sha=(sha) click to toggle source
# File lib/dandelion/workspace.rb, line 79
def remote_sha=(sha)
  @adapter.write(@config[:revision_file], sha)
  @remote_sha = sha
end