Parent

Rugged::Repository

Repository is an interface into a Git repository on-disk. It's the primary interface between your app and the main Git objects Rugged makes available to you.

Public Instance Methods

blob_at(revision, path) click to toggle source

Get the blob at a path for a specific revision.

revision - The String SHA1. path - The String file path.

Returns a String.

# File lib/rugged/repository.rb, line 187
def blob_at(revision, path)
  tree = Rugged::Commit.lookup(self, revision).tree
  begin
    blob_data = tree.path(path)
  rescue Rugged::TreeError
    return nil
  end
  blob = Rugged::Blob.lookup(self, blob_data[:oid])
  (blob.type == :blob) ? blob : nil
end
branches() click to toggle source

All the branches in the repository

Returns an BranchCollection containing Rugged::Branch objects

# File lib/rugged/repository.rb, line 159
def branches
  @branches ||= BranchCollection.new(self)
end
checkout(target, options = {}) click to toggle source

Checkout the specified branch, reference or commit.

target - A revparse spec for the branch, reference or commit to check out. options - Options passed to checkout_tree.

# File lib/rugged/repository.rb, line 24
def checkout(target, options = {})
  options[:strategy] ||= :safe
  options.delete(:paths)

  return checkout_head(options) if target == "HEAD"

  if target.kind_of?(Rugged::Branch)
    branch = target
  else
    branch = branches[target]
  end

  if branch
    self.checkout_tree(branch.target, options)

    if branch.remote?
      references.create("HEAD", branch.target_id, force: true)
    else
      references.create("HEAD", branch.canonical_name, force: true)
    end
  else
    commit = Commit.lookup(self, self.rev_parse_oid(target))
    references.create("HEAD", commit.oid, force: true)
    self.checkout_tree(commit, options)
  end
end
create_branch(name, sha_or_ref = "HEAD") click to toggle source

Create a new branch in the repository

name - The name of the branch (without a full reference path) sha_or_ref - The target of the branch; either a String representing an OID or a reference name, or a Rugged::Object instance.

Returns a Rugged::Branch object

# File lib/rugged/repository.rb, line 170
def create_branch(name, sha_or_ref = "HEAD")
  case sha_or_ref
  when Rugged::Object
    target = sha_or_ref.oid
  else
    target = rev_parse_oid(sha_or_ref)
  end

  branches.create(name, target)
end
diff(left, right, opts = {}) click to toggle source
# File lib/rugged/repository.rb, line 51
def diff(left, right, opts = {})
  left = rev_parse(left) if left.kind_of?(String)
  right = rev_parse(right) if right.kind_of?(String)

  if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit) && !left.nil?
    raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
  end

  if !right.is_a?(Rugged::Tree) && !right.is_a?(Rugged::Commit) && !right.nil?
    raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
  end

  if left
    left.diff(right, opts)
  elsif right
    right.diff(left, opts.merge(:reverse => !opts[:reverse]))
  end
end
diff_workdir(left, opts = {}) click to toggle source
# File lib/rugged/repository.rb, line 70
def diff_workdir(left, opts = {})
  left = rev_parse(left) if left.kind_of?(String)

  if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit)
    raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
  end

  left.diff_workdir(opts)
end
fetch(remote_or_url, *args) click to toggle source
# File lib/rugged/repository.rb, line 198
def fetch(remote_or_url, *args)
  unless remote_or_url.kind_of? Remote
    remote_or_url = remotes[remote_or_url] || remotes.create_anonymous(remote_or_url)
  end

  remote_or_url.fetch(*args)
end
inspect() click to toggle source

Pretty formatting of a Repository.

Returns a very pretty String.

# File lib/rugged/repository.rb, line 9
def inspect
  "#<Rugged::Repository:#{object_id} {path: #{path.inspect}}>"
end
last_commit() click to toggle source

Get the most recent commit from this repo.

Returns a Rugged::Commit object.

# File lib/rugged/repository.rb, line 16
def last_commit
  self.head.target
end
lookup(oid) click to toggle source

Look up a SHA1.

Returns one of the four classes that inherit from Rugged::Object.

# File lib/rugged/repository.rb, line 98
def lookup(oid)
  Rugged::Object.lookup(self, oid)
end
push(remote_or_url, *args) click to toggle source

Push a list of refspecs to the given remote.

refspecs - A list of refspecs that should be pushed to the remote.

Returns a hash containing the pushed refspecs as keys and any error messages or nil as values.

# File lib/rugged/repository.rb, line 212
def push(remote_or_url, *args)
  unless remote_or_url.kind_of? Remote
    remote_or_url = remotes[remote_or_url] || remotes.create_anonymous(remote_or_url)
  end

  remote_or_url.push(*args)
end
ref(ref_name) click to toggle source

Look up a single reference by name.

Example:

repo.ref 'refs/heads/master'
# => #<Rugged::Reference:2199125780 {name: "refs/heads/master",
       target: "25b5d3b40c4eadda8098172b26c68cf151109799"}>

Returns a Rugged::Reference.

# File lib/rugged/repository.rb, line 125
def ref(ref_name)
  references[ref_name]
end
ref_names(glob = nil) click to toggle source
# File lib/rugged/repository.rb, line 137
def ref_names(glob = nil)
  references.each_name(glob)
end
references() click to toggle source
# File lib/rugged/repository.rb, line 133
def references
  @references ||= ReferenceCollection.new(self)
end
refs(glob = nil) click to toggle source
# File lib/rugged/repository.rb, line 129
def refs(glob = nil)
  references.each(glob)
end
remotes() click to toggle source

All the remotes in the repository.

Returns a Rugged::RemoteCollection containing all the Rugged::Remote objects in the repository.

# File lib/rugged/repository.rb, line 152
def remotes
  @remotes ||= RemoteCollection.new(self)
end
rev_parse(spec) click to toggle source

Look up an object by a revision string.

Returns one of the four classes that inherit from Rugged::Object.

# File lib/rugged/repository.rb, line 105
def rev_parse(spec)
  Rugged::Object.rev_parse(self, spec)
end
rev_parse_oid(spec) click to toggle source

Look up an object by a revision string.

Returns the oid of the matched object as a String

# File lib/rugged/repository.rb, line 112
def rev_parse_oid(spec)
  Rugged::Object.rev_parse_oid(self, spec)
end
tags() click to toggle source

All the tags in the repository.

Returns an TagCollection containing all the tags.

# File lib/rugged/repository.rb, line 144
def tags
  @tags ||= TagCollection.new(self)
end
walk(from, sorting=Rugged::SORT_DATE, &block) click to toggle source

Walks over a set of commits using Rugged::Walker.

from - The String SHA1 to push onto Walker to begin our walk. sorting - The sorting order of the commits, as defined in the README. block - A block that we pass into walkereach.

Returns nothing if called with a block, otherwise returns an instance of Enumerable::Enumerator containing Rugged::Commit objects.

# File lib/rugged/repository.rb, line 88
def walk(from, sorting=Rugged::SORT_DATE, &block)
  walker = Rugged::Walker.new(self)
  walker.sorting(sorting)
  walker.push(from)
  walker.each(&block)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.