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.



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

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



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

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



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

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



85
86
87
88
89
90
91
# File 'lib/libdolt/git/repository.rb', line 85

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



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

def tree(ref, path)
  tree = tree_for_ref_and_path(ref, path)
  annotate_tree(ref, path, tree)
end

#tree_entry(ref, path) ⇒ Object



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

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

#tree_for_ref_and_path(ref, path) ⇒ Object



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

def tree_for_ref_and_path(ref, path)
  tree = rev_parse("#{ref}:#{path}")

  unless tree.is_a?(Rugged::Tree)
    raise Rugged::TreeError, "#{ref}:#{path} is not a tree (#{tree.class.to_s})"
  end

  tree
end

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



70
71
72
73
# File 'lib/libdolt/git/repository.rb', line 70

def tree_history(ref, path, limit = 1)
  tree = tree_for_ref_and_path(ref, path)
  annotate_history(path || "./", ref, tree, limit)
end