Class Grit::Repo
In: lib/grit/repo.rb
Parent: Object

Methods

Constants

DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
BATCH_PARSERS = { 'commit' => ::Grit::Commit

Attributes

bare  [R]  Public: The Boolean of whether or not the repo is bare.
git  [RW]  Public: The Grit::Git command line interface object.
path  [RW]  Public: The String path of the Git repo.
working_dir  [RW]  Public: The String path to the working directory of the repo, or nil if there is no working directory.

Public Class methods

Public: Initialize a git repository (create it on the filesystem). By default, the newly created repository will contain a working directory. If you would like to create a bare repo, use Grit::Repo.init_bare.

path - The String full path to the repo. Traditionally ends with

               "/<name>.git".

git_options - A Hash of additional options to the git init command

               (default: {}).

repo_options - A Hash of additional options to the Grit::Repo.new call

               (default: {}).

Examples

  Grit::Repo.init('/var/git/myrepo.git')

Returns the newly created Grit::Repo.

Public: Initialize a bare git repository (create it on the filesystem).

path - The String full path to the repo. Traditionally ends with

               "/<name>.git".

git_options - A Hash of additional options to the git init command

               (default: {}).

repo_options - A Hash of additional options to the Grit::Repo.new call

               (default: {}).

Examples

  Grit::Repo.init_bare('/var/git/myrepo.git')

Returns the newly created Grit::Repo.

Public: Initialize a bare Git repository (create it on the filesystem) or, if the repo already exists, simply return it.

path - The String full path to the repo. Traditionally ends with

               "/<name>.git".

git_options - A Hash of additional options to the git init command

               (default: {}).

repo_options - A Hash of additional options to the Grit::Repo.new call

               (default: {}).

Returns the new or existing Grit::Repo.

Public: Create a new Repo instance.

path - The String path to either the root git directory or the bare

          git repo. Bare repos are expected to end with ".git".

options - A Hash of options (default: {}):

          :is_bare - Boolean whether to consider the repo as bare even
                     if the repo name does not end with ".git".

Examples

  r = Repo.new("/Users/tom/dev/normal")
  r = Repo.new("/Users/tom/public/bare.git")
  r = Repo.new("/Users/tom/public/bare", {:is_bare => true})

Returns a newly initialized Grit::Repo. Raises Grit::InvalidGitRepositoryError if the path exists but is not

  a Git repository.

Raises Grit::NoSuchPathError if the path does not exist.

Public Instance methods

Adds files to the index

The list of alternates for this repo

Returns Array[String] (pathnames of alternates)

Sets the alternates

  +alts+ is the Array of String paths representing the alternates

Returns nothing

Archive the given treeish

  +treeish+ is the treeish name/id (default 'master')
  +prefix+ is the optional prefix

Examples

  repo.archive_tar
  # => <String containing tar archive>

  repo.archive_tar('a87ff14')
  # => <String containing tar archive for commit a87ff14>

  repo.archive_tar('master', 'myproject/')
  # => <String containing tar archive and prefixed with 'myproject/'>

Returns String (containing tar archive)

Archive and gzip the given treeish

  +treeish+ is the treeish name/id (default 'master')
  +prefix+ is the optional prefix

Examples

  repo.archive_tar_gz
  # => <String containing tar.gz archive>

  repo.archive_tar_gz('a87ff14')
  # => <String containing tar.gz archive for commit a87ff14>

  repo.archive_tar_gz('master', 'myproject/')
  # => <String containing tar.gz archive and prefixed with 'myproject/'>

Returns String (containing tar.gz archive)

Write an archive directly to a file

  +treeish+ is the treeish name/id (default 'master')
  +prefix+ is the optional prefix (default nil)
  +filename+ is the name of the file (default 'archive.tar.gz')
  +format+ is the optional format (default nil)
  +pipe+ is the command to run the output through (default 'gzip')

Returns nothing

Public: Return the full Git objects from the given SHAs. Only Commit objects are parsed for now.

*shas - Array of String SHAs.

Returns an Array of Grit objects (Grit::Commit).

The Blob object for the given id

  +id+ is the SHA1 id of the blob

Returns Grit::Blob (unbaked)

branches()

Alias for heads

The Commit object for the specified id

  +id+ is the SHA1 identifier of the commit

Returns Grit::Commit (baked)

Commits all tracked and modified files

Returns true/false if commit worked

The number of commits reachable by the given branch/commit

  +start+ is the branch/commit name (default 'master')

Returns Integer

Returns a list of commits that is in other_repo but not in self

Returns Grit::Commit[]

The commit diff for the given commit

  +commit+ is the commit name/id

Returns Grit::Diff[]

Commits current index

Returns true/false if commit worked

An array of Commit objects representing the history of a given ref/commit

  +start+ is the branch/commit name (default 'master')
  +max_count+ is the maximum number of commits to return (default 10, use +false+ for all)
  +skip+ is the number of commits to skip (default 0)

Returns Grit::Commit[] (baked)

The Commits objects that are reachable via to but not via from Commits are returned in chronological order.

  +from+ is the branch/commit name of the younger item
  +to+ is the branch/commit name of the older item

Returns Grit::Commit[] (baked)

The Commits objects that are newer than the specified date. Commits are returned in chronological order.

  +start+ is the branch/commit name (default 'master')
  +since+ is a string represeting a date/time
  +extra_options+ is a hash of extra options

Returns Grit::Commit[] (baked)

The project‘s description. Taken verbatim from GIT_REPO/description

Returns String

The diff from commit a to commit b, optionally restricted to the given file(s)

  +a+ is the base commit
  +b+ is the other commit
  +paths+ is an optional list of file paths on which to restrict the diff

Disable git-daemon serving of this repository by ensuring there is no git-daemon-export-ok file in its git directory

Returns nothing

Enable git-daemon serving of this repository by writing the git-daemon-export-ok file to its git directory

Returns nothing

Public: Create a bare fork of this repository.

path - The String full path of where to create the new fork.

          Traditionally ends with "/<name>.git".

options - The Hash of additional options to the git clone command.

          These options will be merged on top of the default Hash:
          {:bare => true, :shared => true}.

Returns the newly forked Grit::Repo.

Public: Fork a bare git repository from another repo.

path - The String full path of the repo from which to fork..

          Traditionally ends with "/<name>.git".

options - The Hash of additional options to the git clone command.

          These options will be merged on top of the default Hash:
          {:bare => true, :shared => true}.

Returns the newly forked Grit::Repo.

Object reprsenting the current repo head.

Returns Grit::Head (baked)

An array of Head objects representing the branch heads in this repo

Returns Grit::Head[] (baked)

Pretty object inspection

Parses `git cat-file —batch` output, returning an array of Grit objects.

text - Raw String output.

Returns an Array of Grit objects (Grit::Commit).

Finds the most recent annotated tag name that is reachable from a commit.

  @repo.recent_tag_name('master')
  # => "v1.0-0-abcdef"

committish - optional commit SHA, branch, or tag name. options - optional hash of options to pass to git.

             Default: {:always => true}
             :tags => true      # use lightweight tags too.
             :abbrev => Integer # number of hex digits to form the unique
               name.  Defaults to 7.
             :long => true      # always output tag + commit sha
             # see `git describe` docs for more options.

Returns the String tag name, or just the commit if no tag is found. If there have been updates since the tag was made, a suffix is added with the number of commits since the tag, and the abbreviated object name of the most recent commit. Returns nil if the committish value is not found.

An array of Ref objects representing the refs in this repo

Returns Grit::Ref[] (baked)

An array of Remote objects representing the remote branches in this repo

Returns Grit::Remote[] (baked)

takes an array of remote names and last pushed dates fetches from all of the remotes where the local fetch date is earlier than the passed date, then records the last fetched date

{ ‘origin’ => date,

  'peter => date,

}

Remove files from the index

Rename the current repository directory.

  +name+ is the new name

Returns nothing

An array of Tag objects that are available in this repo

Returns Grit::Tag[] (baked)

The Tree object for the given treeish reference

  +treeish+ is the reference (default 'master')
  +paths+ is an optional Array of directory paths to restrict the tree (deafult [])

Examples

  repo.tree('master', ['lib/'])

Returns Grit::Tree (baked)

[Validate]