Class: Sabre::Git

Inherits:
Command show all
Defined in:
lib/sabre/git.rb

Instance Method Summary collapse

Methods inherited from Command

#indent, #initialize, #method_missing, #on, #on_error, #on_host, #run, #to_s, #unindent

Methods included from Base

#cd, #cp, #echo, #mv, #set, #synchronize

Constructor Details

This class inherits a constructor from Sabre::Command

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sabre::Command

Instance Method Details

#clone(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/sabre/git.rb', line 4

def clone(options)
  repository = options[:repository]
  directory = options[:directory]

  branch = options[:branch] || "publish"
  remote = options[:remote] || "origin"

  revision = options[:revision] || "#{ remote }/#{ branch }"

  run "mkdir -p #{ directory }"
  run "git clone -o #{ remote } -b #{ branch } #{ repository } #{ directory }"
end

#fetch(options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sabre/git.rb', line 17

def fetch(options)
  repository = options[:repository]
  directory = options[:directory]

  branch = options[:branch] || "publish"
  remote = options[:remote] || "origin"

  revision = options[:revision] || "#{ remote }/#{ branch }"

  cd directory
  run "git config remote.#{ remote }.url #{ repository }"
  run "git config remote.#{ remote }.fetch +refs/heads/*:refs/remotes/#{ remote }/*"
  run "git fetch #{ remote }"
  run "git fetch --tags #{ remote }"
  run "git checkout -f -q #{ branch }"
  run "git reset --hard #{ revision }"
end

#update(options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sabre/git.rb', line 35

def update(options)
  directory = options[:directory]

  fetch_command = Sabre::Git.new { fetch(options) }
  clone_command = Sabre::Git.new { clone(options) }

  run %{
    if [ -d "#{ directory }/.git" ]; then
    #{ indent fetch_command }
    else
    #{ indent clone_command }
    fi
  }
end