class R10K::Git::ShellGit::WorkingRepository

Manage a non-bare Git repository

Attributes

path[R]

@attribute [r] path

@return [Pathname]

Public Class Methods

new(basedir, dirname) click to toggle source
# File lib/r10k/git/shellgit/working_repository.rb, line 17
def initialize(basedir, dirname)
  @path = Pathname.new(File.join(basedir, dirname))
end

Public Instance Methods

alternates() click to toggle source
# File lib/r10k/git/shellgit/working_repository.rb, line 62
def alternates
  R10K::Git::Alternates.new(git_dir)
end
checkout(ref) click to toggle source

Check out the given Git ref

@param ref [String] The git reference to check out

# File lib/r10k/git/shellgit/working_repository.rb, line 45
def checkout(ref)
  git ['checkout', ref], :path => @path.to_s
end
clone(remote, opts = {}) click to toggle source

Clone this git repository

@param remote [String] The Git remote to clone @param opts [Hash]

@options opts [String] :ref The git ref to check out on clone @options opts [String] :reference A Git repository to use as an alternate object database

@return [void]

# File lib/r10k/git/shellgit/working_repository.rb, line 30
def clone(remote, opts = {})
  argv = ['clone', remote, @path.to_s]
  if opts[:reference]
    argv += ['--reference', opts[:reference]]
  end
  git argv

  if opts[:ref]
    checkout(opts[:ref])
  end
end
exist?() click to toggle source
# File lib/r10k/git/shellgit/working_repository.rb, line 53
def exist?
  @path.exist?
end
fetch() click to toggle source
# File lib/r10k/git/shellgit/working_repository.rb, line 49
def fetch
  git ['fetch'], :path => @path.to_s
end
git_dir() click to toggle source

@return [Pathname] The path to the Git directory inside of this repository

# File lib/r10k/git/shellgit/working_repository.rb, line 13
def git_dir
  @path + '.git'
end
head() click to toggle source

@return [String] The currently checked out ref

# File lib/r10k/git/shellgit/working_repository.rb, line 58
def head
  resolve('HEAD')
end
origin() click to toggle source

@return [String] The origin remote URL

# File lib/r10k/git/shellgit/working_repository.rb, line 67
def origin
  result = git(['config', '--get', 'remote.origin.url'], :path => @path.to_s, :raise_on_fail => false)
  if result.success?
    result.stdout
  end
end