Class: Gollum::Git::Repo
- Inherits:
-
Object
- Object
- Gollum::Git::Repo
- Defined in:
- lib/rjgit_adapter/git_layer_rjgit.rb
Instance Attribute Summary collapse
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Class Method Summary collapse
- .init(path, git_options = {}, repo_options = {}) ⇒ Object
- .init_bare(path, git_options = {}, repo_options = {}) ⇒ Object
Instance Method Summary collapse
- #bare ⇒ Object
- #commit(ref) ⇒ Object
- #commits(ref = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0) ⇒ Object
- #config ⇒ Object
- #diff(sha1, sha2, path = nil) ⇒ Object
-
#find(sha, type) ⇒ Object
Not required by gollum-lib.
-
#find_branch(search_list) ⇒ Object
Find the first existing branch in an Array of branch names of the form [‘main’, …] and return its String name.
- #git ⇒ Object
- #head ⇒ Object
- #index ⇒ Object
-
#initialize(path, options = {}) ⇒ Repo
constructor
A new instance of Repo.
- #log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {}) ⇒ Object
- #lstree(sha, options = {}) ⇒ Object
- #path ⇒ Object
- #update_ref(ref, commit_sha) ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Repo
Returns a new instance of Repo.
377 378 379 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 377 def initialize(path, = {}) @repo = RJGit::Repo.new(path, ) end |
Instance Attribute Details
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
375 376 377 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 375 def repo @repo end |
Class Method Details
.init(path, git_options = {}, repo_options = {}) ⇒ Object
381 382 383 384 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 381 def self.init(path, = {}, = {}) RJGit::Repo.create(path, {:is_bare => false}) self.new(path, {:is_bare => false}) end |
.init_bare(path, git_options = {}, repo_options = {}) ⇒ Object
386 387 388 389 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 386 def self.(path, = {}, = {}) RJGit::Repo.create(path, {:is_bare => true}) self.new(path, {:is_bare => true}) end |
Instance Method Details
#bare ⇒ Object
391 392 393 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 391 def @repo. end |
#commit(ref) ⇒ Object
403 404 405 406 407 408 409 410 411 412 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 403 def commit(ref) objectid = @repo.jrepo.resolve(Gollum::Git.canonicalize(ref)) return nil if objectid.nil? id = objectid.name commit = @repo.find(id, :commit) return nil if commit.nil? Gollum::Git::Commit.new(commit) rescue Java::OrgEclipseJgitErrors::RevisionSyntaxException raise Gollum::Git::NoSuchShaFound end |
#commits(ref = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0) ⇒ Object
414 415 416 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 414 def commits(ref = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0) @repo.commits(ref, max_count).map{|commit| Gollum::Git::Commit.new(commit)} end |
#config ⇒ Object
395 396 397 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 395 def config @repo.config end |
#diff(sha1, sha2, path = nil) ⇒ Object
455 456 457 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 455 def diff(sha1, sha2, path = nil) RJGit::Porcelain.diff(@repo, {:old_rev => sha1, :new_rev => sha2, :file_path => path, :patch => true}).inject("") {|result, diff| result << diff[:patch]} end |
#find(sha, type) ⇒ Object
Not required by gollum-lib
419 420 421 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 419 def find(sha, type) @repo.find(sha, type) end |
#find_branch(search_list) ⇒ Object
Find the first existing branch in an Array of branch names of the form [‘main’, …] and return its String name.
460 461 462 463 464 465 466 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 460 def find_branch(search_list) search_list.find do |branch_name| @repo.branches.find do |canonical_name| Gollum::Git.decanonicalize(canonical_name) == branch_name end end end |
#git ⇒ Object
399 400 401 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 399 def git @git ||= Gollum::Git::Git.new(@repo.git) end |
#head ⇒ Object
424 425 426 427 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 424 def head return nil unless @repo.head Gollum::Git::Ref.new(@repo.head, Gollum::Git.head_ref_name(@repo)) end |
#index ⇒ Object
429 430 431 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 429 def index @index ||= Gollum::Git::Index.new(RJGit::Plumbing::Index.new(@repo)) end |
#log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {}) ⇒ Object
433 434 435 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 433 def log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, = {}) git.log(Gollum::Git.canonicalize(ref), path, ) end |
#lstree(sha, options = {}) ⇒ Object
437 438 439 440 441 442 443 444 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 437 def lstree(sha, ={}) entries = RJGit::Porcelain.ls_tree(@repo.jrepo, nil, @repo.find(sha, :tree), {:recursive => [:recursive]}) entries.map! do |entry| entry[:mode] = entry[:mode].to_s(8) entry[:sha] = entry[:id] entry end end |
#path ⇒ Object
446 447 448 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 446 def path @repo.path end |
#update_ref(ref, commit_sha) ⇒ Object
450 451 452 453 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 450 def update_ref(ref, commit_sha) cm = self.commit(commit_sha) @repo.update_ref(cm.commit, true, Gollum::Git.canonicalize(ref)) end |