class Gollum::Git::Repo

Public Class Methods

init(path) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 599
def self.init(path)
  Rugged::Repository.init_at(path, false)
  self.new(path, :is_bare => false)
end
init_bare(path) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 604
def self.init_bare(path)
  Rugged::Repository.init_at(path, true)
  self.new(path, :is_bare => true)
end
new(path, options) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 595
def initialize(path, options)
  @repo = Rugged::Repository.new(path, **options)
end

Public Instance Methods

bare() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 609
def bare
  @repo.bare?
end
commit(id) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 621
def commit(id)
  begin
    git.commit_from_ref(id)
  rescue
    raise Gollum::Git::NoSuchShaFound
  end
end
commits(start = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 629
def commits(start = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0)
  git.log(start, nil, :max_count => max_count, :skip => skip)
end
config() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 613
def config
  @repo.config
end
diff(sha1, sha2, *paths) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 645
def diff(sha1, sha2, *paths)
  opts = paths.nil? ? {} : {:paths => paths}
  @repo.diff(sha1, sha2, opts).patch.force_encoding('utf-8')
end
find_branch(search_list) click to toggle source

Find the first existing branch in an Array of branch names of the form [‘main’, …] and return its String name.

# File lib/rugged_adapter/git_layer_rugged.rb, line 678
def find_branch(search_list)
 all_branches = @repo.branches.to_a.map {|b| b.name}
  search_list.find do |branch_name|
    all_branches.include?(branch_name)
  end
end
git() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 617
def git
  @git ||= Gollum::Git::Git.new(@repo)
end
head() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 633
def head
  begin
    return Gollum::Git::Ref.new(@repo.head)
  rescue Rugged::ReferenceError
    return nil
  end
end
index() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 641
def index
  @index ||= Gollum::Git::Index.new(@repo.index, @repo)
end
log(commit = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {}) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 650
def log(commit = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {})
  git.log(commit, path, **options)
end
lstree(sha, options = {}) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 654
def lstree(sha, options = {})
  results = []
  @repo.lookup(sha).tree.walk(:postorder) do |root, entry|
    results << ::Gollum::Git::Tree.tree_entry_from_rugged_hash(entry, root)
  end
  results
end
path() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 662
def path
  @repo.path
end
update_ref(ref, commit_sha) click to toggle source

Checkout branch and if necessary first create it. Currently used only in gollum-lib’s tests.

# File lib/rugged_adapter/git_layer_rugged.rb, line 667
def update_ref(ref, commit_sha)
  ref = "refs/heads/#{ref}" unless ref =~ /^refs\/heads\//
  if _ref = @repo.references[ref]
    @repo.references.update(_ref, commit_sha)
  else
    @repo.create_branch(ref, commit_sha)
    @repo.checkout(ref, :strategy => :force) unless @repo.bare?
  end
end