module Git

def self.bare(git_dir, options = {})

Returns:
  • (Git::Base) - an object that can execute git commands in the context

Options Hash: (**options)
  • :log (Logger) -- A logger to use for Git operations. Git commands

Parameters:
  • options (Hash) -- The options for this command (see list of valid
  • git_dir (Pathname) -- The path to the bare repository directory

Other tags:
    Example: Open a bare repository and retrieve the first commit SHA -

Other tags:
    See: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefbarerepositoryabarerepository -
def self.bare(git_dir, options = {})
  Base.bare(git_dir, options)
end

def self.binary_version(binary_path = Git::Base.config.binary_path)

Returns:
  • (Array) - the version of the git binary
def self.binary_version(binary_path = Git::Base.config.binary_path)
  Base.binary_version(binary_path)
end

def self.clone(repository_url, directory = nil, options = {})

Returns:
  • (Git::Base) - an object that can execute git commands in the context

Other tags:
    Example: Clone a repository and set multiple config options -
    Example: Clone a repository and set a single config option -
    Example: Create a bare repository in the directory `ruby-git.git` -
    Example: Clone into a different directory `my-ruby-git` -
    Example: Clone and then checkout the `development` branch -
    Example: Clone into the default directory `ruby-git` -

Options Hash: (**options)
  • :recursive (Boolean) -- After the clone is created, initialize
  • :path (Pathname) -- The directory to clone into. May be used
  • :origin (String) -- Use the value instead `origin` to track
  • :mirror (Boolean) -- Set up a mirror of the source repository.
  • :log (Logger) -- A logger to use for Git operations. Git
  • :filter (String) -- Request that the server send a partial
  • :depth (Integer) -- Create a shallow clone with a history
  • :config (Array, String) -- A list of configuration options to
  • :branch (String) -- The name of a branch or tag to checkout
  • :bare (Boolean) -- Make a bare Git repository. See

Parameters:
  • options (Hash) -- The options for this command (see list of valid
  • directory (Pathname, nil) -- The directory to clone into
  • repository_url (URI, Pathname) -- The (possibly remote) repository url to clone

Other tags:
    See: https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a - GIT URLs
    See: https://git-scm.com/docs/git-clone - git clone
def self.clone(repository_url, directory = nil, options = {})
  clone_to_options = options.select { |key, _value| %i[bare mirror].include?(key) }
  directory ||= Git::URL.clone_to(repository_url, **clone_to_options)
  Base.clone(repository_url, directory, options)
end

def self.config

def self.config
  return Base.config
end

def self.configure

def self.configure
  yield Base.config
end

def self.default_branch(repository, options = {})

Returns:
  • (String) - the name of the default branch

Options Hash: (**options)
  • :log (Logger) -- A logger to use for Git operations. Git

Parameters:
  • options (Hash) -- The options for this command (see list of valid
  • repository (URI, Pathname, String) -- The (possibly remote) repository to get the default branch name for

Other tags:
    Example: with the logging option -
    Example: with a local repository Pathname -
    Example: with a local repository -
    Example: with a URI object -
    Example: with a URI string -
def self.default_branch(repository, options = {})
  Base.repository_default_branch(repository, options)
end

def self.export(repository, name, options = {})

remote, 'origin.'
since the .git info will be deleted anyway; always uses the default
See +clone+ for options. Does not obey the :remote option,

directory.
is specified) into the +name+ directory, then remove all traces of git from the
Export the current HEAD (or a branch, if options[:branch]
def self.export(repository, name, options = {})
  options.delete(:remote)
  repo = clone(repository, name, {:depth => 1}.merge(options))
  repo.checkout("origin/#{options[:branch]}") if options[:branch]
  FileUtils.rm_r File.join(repo.dir.to_s, '.git')
end

def self.global_config(name = nil, value = nil)

g.config # returns whole config hash
g.config('user.name') # returns 'Scott Chacon'
g.config('user.email', 'email@email.com') # sets value
g.config('user.name', 'Scott Chacon') # sets value

Same as g.config, but forces it to be at the global level
def self.global_config(name = nil, value = nil)
  lib = Git::Lib.new(nil, nil)
  if(name && value)
    # set value
    lib.global_config_set(name, value)
  elsif (name)
    # return value
    lib.global_config_get(name)
  else
    # return hash
    lib.global_config_list
  end
end

def self.init(directory = '.', options = {})

Other tags:
    See: https://git-scm.com/docs/git-init - git init

Other tags:
    Example: Initialize a repository in a non-default location (outside of the working copy) -
    Example: Initialize a bare repository -
    Example: Initialize a repository in some other directory -
    Example: Initialize a repository in the current directory -

Returns:
  • (Git::Base) - an object that can execute git commands in the context

Options Hash: (**options)
  • :log (Logger) -- A logger to use for Git operations. Git
  • :repository (Pathname) -- the path to put the newly initialized
  • :initial_branch (String) -- Use the specified name for the
  • :bare (Boolean) -- Instead of creating a repository at

Parameters:
  • options (Hash) -- The options for this command (see list of valid
  • directory (Pathname) -- If the `:bare` option is NOT given or is not
def self.init(directory = '.', options = {})
  Base.init(directory, options)
end

def self.ls_remote(location = nil, options = {})

Returns:
  • ({String=>Hash}) - the available references of the target repo.

Parameters:
  • location (String|NilClass) -- the target repository location or nil for '.'
def self.ls_remote(location = nil, options = {})
  Git::Lib.new.ls_remote(location, options)
end

def self.open(working_dir, options = {})

Returns:
  • (Git::Base) - an object that can execute git commands in the context

Options Hash: (**options)
  • :log (Logger) -- A logger to use for Git operations. Git
  • :index (Pathname) -- used to specify a non-standard path to an
  • :repository (Pathname) -- used to specify a non-standard path to

Parameters:
  • options (Hash) -- The options for this command (see list of valid
  • working_dir (Pathname) -- the path to the working directory to use

Other tags:
    Example: Open a working copy whose repository is in a non-standard directory -
    Example: Use a logger to see what is going on -
    Example: Open a Git working directory in some other directory -
    Example: Open the Git working directory in the current directory -
def self.open(working_dir, options = {})
  Base.open(working_dir, options)
end

def config(name = nil, value = nil)

g.config # returns whole config hash
g.config('user.name') # returns 'Scott Chacon'
g.config('user.email', 'email@email.com') # sets value
g.config('user.name', 'Scott Chacon') # sets value
def config(name = nil, value = nil)
  lib = Git::Lib.new
  if(name && value)
    # set value
    lib.config_set(name, value)
  elsif (name)
    # return value
    lib.config_get(name)
  else
    # return hash
    lib.config_list
  end
end

def global_config(name = nil, value = nil)

def global_config(name = nil, value = nil)
  self.class.global_config(name, value)
end