Class: R10K::Git::ShellGit::WorkingRepository

Inherits:
BaseRepository show all
Defined in:
lib/r10k/git/shellgit/working_repository.rb

Overview

Manage a non-bare Git repository

Direct Known Subclasses

ThinRepository

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRepository

#branches, #ref_type, #remotes, #resolve, #tags

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Constructor Details

#initialize(basedir, dirname) ⇒ WorkingRepository

Returns a new instance of WorkingRepository.



17
18
19
# File 'lib/r10k/git/shellgit/working_repository.rb', line 17

def initialize(basedir, dirname)
  @path = Pathname.new(File.join(basedir, dirname))
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/r10k/git/shellgit/working_repository.rb', line 10

def path
  @path
end

Instance Method Details

#alternatesObject



72
73
74
# File 'lib/r10k/git/shellgit/working_repository.rb', line 72

def alternates
  R10K::Git::Alternates.new(git_dir)
end

#checkout(ref) ⇒ Object

Check out the given Git ref

Parameters:

  • ref (String)

    The git reference to check out



50
51
52
# File 'lib/r10k/git/shellgit/working_repository.rb', line 50

def checkout(ref)
  git ['checkout', ref], :path => @path.to_s
end

#clone(remote, opts = {}) ⇒ void

This method returns an undefined value.

Clone this git repository

Parameters:

  • remote (String)

    The Git remote to clone

  • opts (Hash) (defaults to: {})


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

  proxy = R10K::Git.get_proxy_for_remote(remote)

  R10K::Git.with_proxy(proxy) do
    git argv
  end

  if opts[:ref]
    checkout(opts[:ref])
  end
end

#exist?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/r10k/git/shellgit/working_repository.rb', line 63

def exist?
  @path.exist?
end

#fetch(remote_name = 'origin') ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/r10k/git/shellgit/working_repository.rb', line 54

def fetch(remote_name='origin')
  remote = remotes[remote_name]
  proxy = R10K::Git.get_proxy_for_remote(remote)

  R10K::Git.with_proxy(proxy) do
    git ['fetch', remote_name, '--prune'], :path => @path.to_s
  end
end

#git_dirPathname

Returns The path to the Git directory inside of this repository.

Returns:

  • (Pathname)

    The path to the Git directory inside of this repository



13
14
15
# File 'lib/r10k/git/shellgit/working_repository.rb', line 13

def git_dir
  @path + '.git'
end

#headString

Returns The currently checked out ref.

Returns:

  • (String)

    The currently checked out ref



68
69
70
# File 'lib/r10k/git/shellgit/working_repository.rb', line 68

def head
  resolve('HEAD')
end

#originString

Returns The origin remote URL.

Returns:

  • (String)

    The origin remote URL



77
78
79
80
81
82
# File 'lib/r10k/git/shellgit/working_repository.rb', line 77

def origin
  result = git(['config', '--get', 'remote.origin.url'], :path => @path.to_s, :raise_on_fail => false)
  if result.success?
    result.stdout
  end
end