Class: Redmine::Installer::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine-installer/git.rb

Class Method Summary collapse

Class Method Details

.clone(remote, target, branch = 'master') ⇒ Object

Simple git clone. Create a shallow clone with 1 revision.

  • download specific branch

  • single branch

  • store repository to target



10
11
12
13
14
15
16
# File 'lib/redmine-installer/git.rb', line 10

def self.clone(remote, target, branch='master')
  success = Kernel.system("git clone --branch #{branch} --single-branch --depth 1 #{remote} #{target}")

  unless success
    error :git_repository_cannot_be_clonned
  end
end

.copy_and_fetch(repository, target) ⇒ Object

Git repository is locally clonned to target. On copied git is executed ‘git fetch` (for preserve changes)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/redmine-installer/git.rb', line 21

def self.copy_and_fetch(repository, target)
  url = ''
  # Store original remote url because copied repository will
  # have remote set to local repo
  Dir.chdir(repository) do
    url = `git config --get remote.origin.url`.strip
  end

  success = Kernel.system("git clone --depth 1 --no-local #{repository} #{target}")

  unless success
    error :git_repository_cannot_be_localy_clonned
  end

  # Change remote to origin and run fetch
  Dir.chdir(target) do
    Kernel.system("git remote set-url origin #{url}")
    success = Kernel.system('git fetch')
  end

  unless success
    error :git_repository_cannot_be_fetched
  end
end

.error(message) ⇒ Object



46
47
48
# File 'lib/redmine-installer/git.rb', line 46

def self.error(message)
  raise Redmine::Installer::Error, I18n.translate(message)
end