Class: Monolith::Git

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/monolith/git.rb

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initialize(path) ⇒ Git

Returns a new instance of Git.



5
6
7
# File 'lib/monolith/git.rb', line 5

def initialize(path)
  @path = path
end

Instance Method Details

#clone(url) ⇒ Object



9
10
11
# File 'lib/monolith/git.rb', line 9

def clone(url)
  run("clone #{url} .")
end

#cloned?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/monolith/git.rb', line 13

def cloned?
  File.exists?(@path)
end

#fetchObject



17
18
19
# File 'lib/monolith/git.rb', line 17

def fetch
  run("fetch --all")
end

#run(cmd) ⇒ Object



21
22
23
24
25
# File 'lib/monolith/git.rb', line 21

def run(cmd)
  within_working_dir do
    run!(cmd)
  end
end

#run!(cmd) ⇒ Object



27
28
29
# File 'lib/monolith/git.rb', line 27

def run!(cmd)
  command(cmd).run
end

#within_working_dir(&block) ⇒ Object



31
32
33
34
# File 'lib/monolith/git.rb', line 31

def within_working_dir(&block)
  create_working_dir unless cloned?
  cd_working_dir(&block)
end