Class: Vlad::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/vlad/git.rb

Instance Method Summary collapse

Instance Method Details

#checkout(revision, destination) ⇒ Object

Returns the command that will check out revision from the code repo into directory destination. revision can be any SHA1 or equivalent (e.g. branch, tag, etc…)



11
12
13
14
15
16
17
18
19
20
# File 'lib/vlad/git.rb', line 11

def checkout(revision, destination)
  destination = 'repo' if destination == '.'
  revision = 'HEAD' if revision =~ /head/i

  [ "rm -rf #{destination}",
    "#{git_cmd} clone #{code_repo} #{destination}",
    "cd #{destination}",
    "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}"
  ].join(" && ")
end

#export(revision, destination) ⇒ Object

Returns the command that will export revision from the code repo into the directory destination.



26
27
28
29
30
31
32
# File 'lib/vlad/git.rb', line 26

def export(revision, destination)
  revision = 'HEAD' if revision == "."

  [ "mkdir -p #{destination}",
    "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)"
  ].join(" && ")
end

#revision(revision) ⇒ Object

Returns a command that maps human-friendly revision identifier revision into a git SHA1.



38
39
40
41
42
# File 'lib/vlad/git.rb', line 38

def revision(revision)
  revision = 'HEAD' if revision =~ /head/i

  "`#{git_cmd} rev-parse #{revision}`"
end