Class Grit::Git
In: lib/grit/git.rb
Parent: Object

Methods

Included Modules

POSIX::Spawn GitRuby

Classes and Modules

Class Grit::Git::CommandFailed
Class Grit::Git::GitTimeout

Attributes

bytes_read  [RW] 
git_binary  [W] 
git_dir  [RW] 
git_max_size  [RW] 
git_timeout  [RW] 
work_tree  [RW] 

Public Class methods

Public Instance methods

Applies the given patch against the given SHA of the current repo.

options - grit command hash head_sha - String SHA or ref to apply the patch to. patch - The String patch to apply. Get this from get_patch.

Returns the String Tree SHA on a successful patch application, or false.

Checks if the patch of a commit can be applied to the given head.

options - grit command options hash head_sha - String SHA or ref to check the patch against. applies_sha - String SHA of the patch. The patch itself is retrieved

              with #get_patch.

Returns 0 if the patch applies cleanly (according to `git apply`), or an Integer that is the sum of the failed exit statuses.

e(str)

Alias for shell_escape

Chmod the the file or dir and everything beneath

  +file+ is the relative path from the Git dir

Returns nothing

Delete a normal file from the filesystem

  +file+ is the relative path from the Git dir

Returns nothing

Check if a normal file exists on the filesystem

  +file+ is the relative path from the Git dir

Returns Boolean

Make a directory

  +dir+ is the relative path to the directory to create

Returns nothing

Move a normal file

  +from+ is the relative path to the current file
  +to+ is the relative path to the destination file

Returns nothing

Read a normal file from the filesystem.

  +file+ is the relative path from the Git dir

Returns the String contents of the file

Write a normal file to the filesystem.

  +file+ is the relative path from the Git dir
  +contents+ is the String content to be written

Returns nothing

Gets a patch for a given SHA using `git diff`.

options - grit command options hash applies_sha - String SHA to get the patch from, using this command:

              `git diff #{applies_sha}^ #{applies_sha}`

Returns the String patch from `git diff`.

Methods not defined by a library implementation execute the git command using native, passing the method name as the git command name.

Examples:

  git.rev_list({:max_count => 10, :header => true}, "master")

Execute a git command, bypassing any library implementation.

cmd - The name of the git command as a Symbol. Underscores are

  converted to dashes as in :rev_parse => 'rev-parse'.

options - Command line option arguments passed to the git command.

  Single char keys are converted to short options (:a => -a).
  Multi-char keys are converted to long options (:arg => '--arg').
  Underscores in keys are converted to dashes. These special options
  are used to control command execution and are not passed in command
  invocation:
    :timeout - Maximum amount of time the command can run for before
      being aborted. When true, use Grit::Git.git_timeout; when numeric,
      use that number of seconds; when false or 0, disable timeout.
    :base - Set false to avoid passing the --git-dir argument when
      invoking the git command.
    :env - Hash of environment variable key/values that are set on the
      child process.
    :raise - When set true, commands that exit with a non-zero status
      raise a CommandFailed exception. This option is available only on
      platforms that support fork(2).
    :process_info - By default, a single string with output written to
      the process's stdout is returned. Setting this option to true
      results in a [exitstatus, out, err] tuple being returned instead.

args - Non-option arguments passed on the command line.

Optionally yields to the block an IO object attached to the child process‘s STDIN.

Examples

  git.native(:rev_list, {:max_count => 10, :header => true}, "master")

Returns a String with all output written to the child process‘s stdout

  when the :process_info option is not set.

Returns a [exitstatus, out, err] tuple when the :process_info option is

  set. The exitstatus is an small integer that was the process's exit
  status. The out and err elements are the data written to stdout and
  stderr as Strings.

Raises Grit::Git::GitTimeout when the timeout is exceeded or when more

  than Grit::Git.git_max_size bytes are output.

Raises Grit::Git::CommandFailed when the :raise option is set true and the

  git command exits with a non-zero exit status. The CommandFailed's #command,
  #exitstatus, and #err attributes can be used to retrieve additional
  detail about the error.

Transform a ruby-style options hash to command-line arguments sutiable for use with Kernel::exec. No shell escaping is performed.

Returns an Array of String option arguments.

DEPRECATED OPEN3-BASED COMMAND EXECUTION

Simple wrapper around Timeout::timeout.

seconds - Float number of seconds before a Timeout::Error is raised. When

  true, the Grit::Git.git_timeout value is used. When the timeout is less
  than or equal to 0, no timeout is established.

Raises Timeout::Error when the timeout has elapsed.

Transform Ruby style options into git command line options

  +options+ is a hash of Ruby style options

Returns String[]

  e.g. ["--max-count=10", "--header"]

[Validate]