Class: Vagabund::Settler::Sources::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/vagabund/settler/sources/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



5
6
7
# File 'lib/vagabund/settler/sources/git.rb', line 5

def origin
  @origin
end

Instance Method Details

#clone(machine, target_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagabund/settler/sources/git.rb', line 7

def clone(machine, target_path)
  machine.ui.detail "Cloning #{origin} into #{target_path}..."
  unless machine.communicate.test "[ -d #{File.dirname(target_path)} ]"
    machine.communicate.sudo "mkdir -p #{File.dirname(target_path)}"
    machine.communicate.sudo "chown -R #{machine.ssh_info[:username]} #{File.dirname(target_path)}"
    machine.communicate.sudo "chgrp -R #{machine.ssh_info[:username]} #{File.dirname(target_path)}"
  end
  machine.communicate.execute "git clone #{origin} #{target_path}" do |type,data|
    color = type == :stderr ? :red : :green
    options = {
      color: color,
      new_line: false,
      prefix: false
    }

    machine.ui.detail(data, options)
  end
  target_path
end

#pull(machine, target_path) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/vagabund/settler/sources/git.rb', line 42

def pull(machine, target_path)
  if machine.communicate.test "[ -d #{target_path} ]"
    update machine, target_path
  else
    clone machine, target_path
  end
end

#update(machine, target_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagabund/settler/sources/git.rb', line 27

def update(machine, target_path)
  machine.ui.detail "Updating #{target_path} from #{origin}..."
  machine.communicate.execute "cd #{target_path}; git pull" do |type,data|
    color = type == :stderr ? :red : :green
    options = {
      color: color,
      new_line: false,
      prefix: false
    }

    machine.ui.detail(data, options)
  end
  target_path
end