Module: RubyGit

Defined in:
lib/ruby_git.rb,
lib/ruby_git/error.rb,
lib/ruby_git/version.rb,
lib/ruby_git/worktree.rb,
lib/ruby_git/git_binary.rb,
lib/ruby_git/file_helpers.rb

Overview

RubyGit is an object-oriented wrapper for the git command line tool for working with Worktrees and Repositories. It tries to make more sense out of the Git command line.

Defined Under Namespace

Modules: FileHelpers Classes: Error, GitBinary, Worktree

Constant Summary collapse

VERSION =

The ruby_git gem version

'0.2.0'

Class Method Summary collapse

Class Method Details

.clone(repository_url, to_path: '') ⇒ RubyGit::Worktree

Copy the remote repository and checkout the default branch

Clones the repository referred to by repository_url into a newly created directory, creates remote-tracking branches for each branch in the cloned repository, and checks out the default branch in the worktree whose root directory is to_path.

to_path will be created if it does not exist. An error is raised if to_path exists and not an empty directory.

Examples:

Using default for Worktree path

FileUtils.pwd
 => "/Users/jsmith"
worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git')
worktree.path
  => "/Users/jsmith/ruby_git"

Using a specified worktree_path

FileUtils.pwd
 => "/Users/jsmith"
worktree_path = '/tmp/project'
worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git', to_path: worktree_path)
worktree.path
  => "/tmp/project"

Parameters:

  • repository_url (String)

    a reference to a Git repository

  • to_path (String) (defaults to: '')

    where to put the checked out worktree once the repository is cloned

Returns:

Raises:

  • (RubyGit::Error)

    if (1) repository_url is not valid or does not point to a valid repository OR (2) to_path is not an empty directory.

See Also:



101
102
103
# File 'lib/ruby_git.rb', line 101

def self.clone(repository_url, to_path: '')
  RubyGit::Worktree.clone(repository_url, to_path: to_path)
end

.gitRubyGit::GitBinary

Return information about the git binary used by this library

Use this object to set the path to the git binary to use or to see the path being used.

Examples:

Setting the git binary path

RubyGit.git.path = '/usr/local/bin/git'

Returns:



26
27
28
# File 'lib/ruby_git.rb', line 26

def self.git
  (@git ||= RubyGit::GitBinary.new)
end

.init(worktree_path) ⇒ RubyGit::Worktree

Create an empty Git repository under the root worktree path

If the repository already exists, it will not be overwritten.

Examples:

worktree = Worktree.init(worktree_path)

Parameters:

  • worktree_path (String)

    the root path of a worktree

Returns:

Raises:

See Also:



45
46
47
# File 'lib/ruby_git.rb', line 45

def self.init(worktree_path)
  RubyGit::Worktree.init(worktree_path)
end

.open(worktree_path) ⇒ RubyGit::Worktree

Open an existing Git worktree that contains worktree_path

Examples:

worktree = Worktree.open(worktree_path)

Parameters:

  • worktree_path (String)

    the root path of a worktree

Returns:

Raises:

  • (RubyGit::Error)

    if worktree_path does not exist, is not a directory, or is not within a Git worktree.

See Also:



62
63
64
# File 'lib/ruby_git.rb', line 62

def self.open(worktree_path)
  RubyGit::Worktree.open(worktree_path)
end