Class: Dolt::Git::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/libdolt/git/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Repository

Returns a new instance of Repository.



28
29
30
# File 'lib/libdolt/git/repository.rb', line 28

def initialize(root)
  @repo = Rugged::Repository.new(root)
end

Instance Method Details

#bare?Boolean

Returns:

  • (Boolean)


32
# File 'lib/libdolt/git/repository.rb', line 32

def bare?; @repo.bare?; end

#blame(ref, blob_path) ⇒ Object



57
58
59
60
# File 'lib/libdolt/git/repository.rb', line 57

def blame(ref, blob_path)
  process = Dolt::Git.git(path, "blame -l -t -p #{ref} -- #{blob_path}")
  Dolt::Git::Blame.parse_porcelain(process.stdout.read)
end

#log(ref, path, limit) ⇒ Object



62
63
64
# File 'lib/libdolt/git/repository.rb', line 62

def log(ref, path, limit)
  entry_history(ref, path, limit)
end

#lookup(*args) ⇒ Object



37
# File 'lib/libdolt/git/repository.rb', line 37

def lookup(*args); @repo.lookup(*args); end

#pathObject



33
# File 'lib/libdolt/git/repository.rb', line 33

def path; @repo.path; end

#readme(ref) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/libdolt/git/repository.rb', line 77

def readme(ref)
  tree(ref, "").entries.select do |e|
    e[:type] == :blob && e[:name].match(/readme/i)
  end
rescue Exception => err
  []
end

#refs(*args) ⇒ Object



36
# File 'lib/libdolt/git/repository.rb', line 36

def refs(*args); @repo.refs(*args); end

#rev_parse(*args) ⇒ Object



34
# File 'lib/libdolt/git/repository.rb', line 34

def rev_parse(*args); @repo.rev_parse(*args); end

#rev_parse_oid(*args) ⇒ Object



35
# File 'lib/libdolt/git/repository.rb', line 35

def rev_parse_oid(*args); @repo.rev_parse_oid(*args); end

#submodules(ref) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/libdolt/git/repository.rb', line 39

def submodules(ref)
  config = rev_parse("#{ref}:.gitmodules")
  Dolt::Git::Submodule.parse_config(config.content)
rescue Rugged::IndexerError => err
  # Raised if .gitmodules cannot be found, which means no submodules
  []
end

#tree(ref, path) ⇒ Object

Raises:

  • (StandardError)


47
48
49
50
51
# File 'lib/libdolt/git/repository.rb', line 47

def tree(ref, path)
  object = rev_parse("#{ref}:#{path}")
  raise StandardError.new("Not a tree") if !object.is_a?(Rugged::Tree)
  annotate_tree(ref, path, object)
end

#tree_entry(ref, path) ⇒ Object



53
54
55
# File 'lib/libdolt/git/repository.rb', line 53

def tree_entry(ref, path)
  annotate_tree(ref, path, rev_parse("#{ref}:#{path}"))
end

#tree_history(ref, path, limit = 1) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/libdolt/git/repository.rb', line 66

def tree_history(ref, path, limit = 1)
  tree = rev_parse("#{ref}:#{path}")

  if tree.class != Rugged::Tree
    message = "#{ref}:#{path} is not a tree (#{tree.class.to_s})"
    raise Exception.new(message)
  end

  annotate_history(path || "./", ref, tree, limit)
end