Class: Monolith::GitLocation

Inherits:
BaseLocation show all
Includes:
Berkshelf::Mixin::Git
Defined in:
lib/monolith/locations/git.rb

Direct Known Subclasses

GithubLocation

Instance Method Summary collapse

Methods inherited from BaseLocation

#clean, #initialize

Constructor Details

This class inherits a constructor from Monolith::BaseLocation

Instance Method Details

#installObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/monolith/locations/git.rb', line 8

def install
  unless File.directory?(@destination)
    Monolith.formatter.install(@cookbook, @destination)
    # Clone from the cache. We've already done an install by this point, so
    # berkshelf already made sure the cache exists and is up to date.
    git %|clone "#{cache_path}" "#{@destination}"|

    # Make sure the origin is correct and doesn't point to the cached
    # version.
    cached_origin_url = origin_url(cache_path)
    set_origin_url(@destination, cached_origin_url)

    # Not sure if I want to do this - should probably be an option
    #git %|reset --hard #{@revision}|
    true
  else
    rel_dest = Monolith.formatter.rel_dir(@destination)
    Monolith.formatter.skip(@cookbook, "#{rel_dest} already exists")
    nil
  end
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/monolith/locations/git.rb', line 30

def update
  if File.directory?(@destination)
    Monolith.formatter.update(@cookbook, @destination)
    Dir.chdir(@destination) do
      git %|pull|
    end
    true
  else
    rel_dest = Monolith.formatter.rel_dir(@destination)
    Monolith.formatter.skip(@cookbook, "#{rel_dest} doesn't exist")
    nil
  end
end