Class: Gollum::Git::Repo
- Inherits:
-
Object
- Object
- Gollum::Git::Repo
- Defined in:
- lib/rugged_adapter/git_layer_rugged.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bare ⇒ Object
- #commit(id) ⇒ Object
- #commits(start = 'refs/heads/master', max_count = 10, skip = 0) ⇒ Object
- #config ⇒ Object
- #diff(sha1, sha2, *paths) ⇒ Object
- #git ⇒ Object
- #head ⇒ Object
- #index ⇒ Object
-
#initialize(path, options) ⇒ Repo
constructor
A new instance of Repo.
- #log(commit = 'refs/heads/master', path = nil, options = {}) ⇒ Object
- #lstree(sha, options = {}) ⇒ Object
- #path ⇒ Object
-
#update_ref(ref, commit_sha) ⇒ Object
Checkout branch and if necessary first create it.
Constructor Details
#initialize(path, options) ⇒ Repo
Returns a new instance of Repo.
527 528 529 530 531 532 533 534 535 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 527 def initialize(path, ) begin @repo = Rugged::Repository.new(path, ) #rescue Grit::InvalidGitRepositoryError # raise Gollum::InvalidGitRepositoryError #rescue Grit::NoSuchPathError # raise Gollum::NoSuchPathError end end |
Class Method Details
.init(path) ⇒ Object
537 538 539 540 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 537 def self.init(path) Rugged::Repository.init_at(path, false) self.new(path, :is_bare => false) end |
.init_bare(path) ⇒ Object
542 543 544 545 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 542 def self.(path) Rugged::Repository.init_at(path, true) self.new(path, :is_bare => true) end |
Instance Method Details
#bare ⇒ Object
547 548 549 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 547 def @repo. end |
#commit(id) ⇒ Object
559 560 561 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 559 def commit(id) git.commit_from_ref(id) end |
#commits(start = 'refs/heads/master', max_count = 10, skip = 0) ⇒ Object
563 564 565 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 563 def commits(start = 'refs/heads/master', max_count = 10, skip = 0) git.log(start, nil, :max_count => max_count, :skip => skip) end |
#config ⇒ Object
551 552 553 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 551 def config @repo.config end |
#diff(sha1, sha2, *paths) ⇒ Object
575 576 577 578 579 580 581 582 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 575 def diff(sha1, sha2, *paths) opts = path == nil ? {} : {:path => path} patches = @repo.diff(sha1, sha2, opts).patches if not paths.empty? patches.keep_if { |p| paths.include? p.delta.new_file[:path] } end patches.map {|patch| OpenStruct.new(:diff => patch.to_s.split("\n")[2..-1].join("\n").force_encoding("UTF-8"))}.reverse # First remove two superfluous lines. Rugged seems to order the diffs differently than Grit, so reverse. end |
#git ⇒ Object
555 556 557 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 555 def git @git ||= Gollum::Git::Git.new(@repo) end |
#head ⇒ Object
567 568 569 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 567 def head Gollum::Git::Ref.new(@repo.head) end |
#index ⇒ Object
571 572 573 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 571 def index @index ||= Gollum::Git::Index.new(@repo.index, @repo) end |
#log(commit = 'refs/heads/master', path = nil, options = {}) ⇒ Object
584 585 586 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 584 def log(commit = 'refs/heads/master', path = nil, = {}) git.log(commit, path, ) end |
#lstree(sha, options = {}) ⇒ Object
588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 588 def lstree(sha, = {}) results = [] @repo.lookup(sha).tree.walk(:postorder) do |root, entry| entry[:sha] = entry[:oid] entry[:mode] = entry[:filemode].to_s(8) entry[:type] = entry[:type].to_s entry[:path] = "#{root}#{entry[:name]}" results << entry end results end |
#path ⇒ Object
600 601 602 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 600 def path @repo.path end |
#update_ref(ref, commit_sha) ⇒ Object
Checkout branch and if necessary first create it. Currently used only in gollum-lib’s tests.
605 606 607 608 609 610 611 612 613 |
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 605 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. end end |