class Rugged::Repository
def attributes(path, options = {})
def attributes(path, options = {}) Attributes.new(self, path, options) end
def blob_at(revision, path)
path - The String file path.
revision - The String SHA1.
Get the blob at a path for a specific revision.
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
def branches
All the branches in the repository
def branches @branches ||= BranchCollection.new(self) end
def checkout(target, options = {})
target - A revparse spec for the branch, reference or commit to check out.
Checkout the specified branch, reference or commit.
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
def create_branch(name, sha_or_ref = "HEAD")
an OID or a reference name, or a Rugged::Object instance.
sha_or_ref - The target of the branch; either a String representing
name - The name of the branch (without a full reference path)
Create a new branch in the repository
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
def diff(left, right, opts = {})
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
def diff_workdir(left, opts = {})
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
def fetch(remote_or_url, *args)
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
def inspect
Pretty formatting of a Repository.
def inspect "#<Rugged::Repository:#{object_id} {path: #{path.inspect}}>" end
def last_commit
Get the most recent commit from this repo.
def last_commit self.head.target end
def lookup(oid)
Look up a SHA1.
def lookup(oid) Rugged::Object.lookup(self, oid) end
def push(remote_or_url, *args)
Returns a hash containing the pushed refspecs as keys and
refspecs - A list of refspecs that should be pushed to the remote.
Push a list of refspecs to the given remote.
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
def ref(ref_name)
target: "25b5d3b40c4eadda8098172b26c68cf151109799"}>
# => #
Example:
Look up a single reference by name.
def ref(ref_name) references[ref_name] end
def ref_names(glob = nil)
def ref_names(glob = nil) references.each_name(glob) end
def references
def references @references ||= ReferenceCollection.new(self) end
def refs(glob = nil)
def refs(glob = nil) references.each(glob) end
def remotes
Returns a Rugged::RemoteCollection containing all the Rugged::Remote objects
All the remotes in the repository.
def remotes @remotes ||= RemoteCollection.new(self) end
def rev_parse(spec)
Look up an object by a revision string.
def rev_parse(spec) Rugged::Object.rev_parse(self, spec) end
def rev_parse_oid(spec)
Look up an object by a revision string.
def rev_parse_oid(spec) Rugged::Object.rev_parse_oid(self, spec) end
def submodules
All the submodules in the repository
def submodules @submodules ||= SubmoduleCollection.new(self) end
def tags
All the tags in the repository.
def tags @tags ||= TagCollection.new(self) end
def walk(from, sorting=Rugged::SORT_DATE, &block)
Returns nothing if called with a block, otherwise returns an instance of
block - A block that we pass into walker#each.
sorting - The sorting order of the commits, as defined in the README.
from - The String SHA1 to push onto Walker to begin our walk.
Walks over a set of commits using Rugged::Walker.
def walk(from, sorting=Rugged::SORT_DATE, &block) walker = Rugged::Walker.new(self) walker.sorting(sorting) walker.push(from) walker.each(&block) end