Class: MDT::Fetchers::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/mdt/fetchers/git.rb

Overview

A class that implements Git fetchers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.keyObject

A method that defines a key for fetchers class. Returns:

  • “git”


11
12
13
# File 'lib/mdt/fetchers/git.rb', line 11

def self.key
  'git'
end

.subkeysObject

A method that defines keys for available fetchers. Returns:

  • [“repository”]


18
19
20
# File 'lib/mdt/fetchers/git.rb', line 18

def self.subkeys
  ['repository']
end

Instance Method Details

#fetch(key, options = {}) ⇒ Object

A method that defines how to fetch project contents to a deploy directory with fetchers. Arguments:

  • key - a key identifier of a particular fetcher

  • options - options for fetchers as a Hash

Returns:

  • Exit code for fetcher key

More information:

  • See README.md for detailed description of fetchers


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mdt/fetchers/git.rb', line 30

def fetch(key, options = {})
  case key
  when 'repository'
    return 1 unless options['url']
    options['branch'] ||= 'master'
    if Dir.exist?('.git')
      puts "Pulling changes from Git remote: origin, branch: #{options['branch']}..."
      system("git pull origin #{options['branch']}")
    else
      puts "Cloning Git repository from #{options['url']}..."
      if system("git clone #{options['url']} .")
        puts "Checking out Git branch: #{options['branch']}..."
        system("git checkout #{options['branch']}")
      end
    end
    $?.exitstatus
  end
end