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.



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

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

Instance Method Details

#actual_blob(ref, path) ⇒ Object

Returns the blob, or if the blob is a symlink, returns the blob it’s pointing to. If the link is defunct, returns nil.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/libdolt/git/repository.rb', line 92

def actual_blob(ref, path)
  path = Pathname.new(path)
  tree_path = path.dirname.sub(/^\.$/, "")
  blob_path = path.basename
  blob_entry = rev_parse("#{ref}:#{tree_path}").entries.find do |e|
    e[:name] == blob_path.to_s
  end

  return if blob_entry.nil?
  blob = blob(ref, path.to_s)

  # Filemode 120000 is a symlink
  if blob_entry[:filemode] == "120000".to_i(8)
    return actual_blob(ref, tree_path + blob.content)
  end

  blob
rescue Rugged::TreeError => err
  nil
end

#bare?Boolean

Returns:

  • (Boolean)


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

def bare?; @repo.bare?; end

#blame(ref, blob_path) ⇒ Object



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

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

#blob(ref, path) ⇒ Object



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

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

#log(ref, path, limit) ⇒ Object



67
68
69
# File 'lib/libdolt/git/repository.rb', line 67

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

#lookup(*args) ⇒ Object



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

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

#pathObject



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

def path; @repo.path; end

#readmes(ref, path = "") ⇒ Object



82
83
84
85
86
87
88
# File 'lib/libdolt/git/repository.rb', line 82

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

#refs(*args) ⇒ Object



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

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

#rev_parse(*args) ⇒ Object



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

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

#rev_parse_oid(*args) ⇒ Object



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

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

#submodules(ref) ⇒ Object



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

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

#tree(ref, path) ⇒ Object

Raises:

  • (StandardError)


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

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



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

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

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



71
72
73
74
75
76
77
78
79
80
# File 'lib/libdolt/git/repository.rb', line 71

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