Class: Pipeline::GitMounter

Inherits:
BaseMounter show all
Defined in:
lib/pipeline/mounters/git_mounter.rb

Instance Attribute Summary

Attributes inherited from BaseMounter

#description, #errors, #name, #trigger

Instance Method Summary collapse

Methods inherited from BaseMounter

#error

Constructor Details

#initialize(trigger, options) ⇒ GitMounter

Returns a new instance of GitMounter.



8
9
10
11
12
13
# File 'lib/pipeline/mounters/git_mounter.rb', line 8

def initialize trigger, options
  super(trigger)
  @options = options
  @name = "Git"
  @description = "Pull a repo."
end

Instance Method Details

#mount(target) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pipeline/mounters/git_mounter.rb', line 15

def mount target
  base = @options[:working_dir]

  Pipeline.debug "Making base."
  FileUtils.mkdir_p base

  # Grap the path part of the git url.
  protocol, path, suffix = target.match(/\A(.*\/\/)(.*)(.git)\z/i).captures
  working_target = File.expand_path(base + "" + path + "/")
  
  Pipeline.notify "Cleaning directory: #{working_target}"
  if ! Dir.exists? working_target      
    Pipeline.notify "#{working_target} is not a directory."              
    FileUtils.mkdir_p working_target
  else
    Pipeline.debug "Removing : #{working_target}"  
    FileUtils.rm_rf working_target 
    FileUtils.mkdir_p working_target
  end
    # result = `rm -rf #{working_target}`
    # puts result
  Pipeline.debug "Cloning into: #{working_target}"
  result = `git clone -q #{target} #{working_target}`
  # puts result
  #end
  return working_target
end

#supports?(target) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
# File 'lib/pipeline/mounters/git_mounter.rb', line 43

def supports? target
  last = target.slice(-4,target.length)
  if last === ".git"
    return true
  else
    return false
  end
end