Module: MSPRelease::Git::ClassMethods

Included in:
MSPRelease::Git
Defined in:
lib/msp_release/git.rb

Overview

methods that don’t require a local clone

Instance Method Summary collapse

Instance Method Details

#clone(git_url, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/msp_release/git.rb', line 16

def clone(git_url, options={})
  out_to = options[:out_to]
  exec_options = options[:exec] || {}
  depth_arg = options[:depth].nil?? '' : "--depth #{options[:depth]}"
  branch = options[:branch].nil?? '' : "--branch #{options[:branch]}"

  heads = StringIO.new
  MSPRelease::Exec.exec("git ls-remote --heads #{git_url}", :output => heads)

  unless heads.string.match(/#{options[:branch]}/)
    raise MSPRelease::CLI::Exit, "Git pathspec 'origin/#{options[:branch]}' does not exist"
  end

  single_branch = if version_gte(1, 7, 10)
    options[:no_single_branch] ? '--no-single-branch' :
      options[:single_branch] ? '--single-branch' :
      ''
  end

  MSPRelease::Exec.
    exec("git clone #{depth_arg} #{single_branch} #{branch} #{git_url} #{out_to.nil?? '' : out_to}", exec_options)
end

#versionObject



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

def version()
  MSPRelease::Exec.exec("git version", :output => StringIO.new)
end

#version_gte(maj, min = 0, bug = 0) ⇒ Object



9
10
11
12
13
14
# File 'lib/msp_release/git.rb', line 9

def version_gte(maj, min=0, bug=0)
  match = version.match(/(\d+)\.(\d+)\.(\d+)\..*/)
  match[1].to_i >= maj &&
    match[2].to_i >= min &&
    match[3].to_i >= bug
end