Class: Jxedt::GitCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-jxedt/git_helper/git_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(cache_path) ⇒ GitCommand

Returns a new instance of GitCommand.



3
4
5
6
# File 'lib/cocoapods-jxedt/git_helper/git_command.rb', line 3

def initialize(cache_path)
  @cache_path = File.expand_path(cache_path)
  prepare_cache_dir
end

Instance Method Details

#git(cmd, ignore_output: false, can_fail: false, git_dir: true) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/cocoapods-jxedt/git_helper/git_command.rb', line 12

def git(cmd, ignore_output: false, can_fail: false, git_dir: true)
  comps = ["git"]
  comps << "-C" << @cache_path if git_dir
  comps << cmd
  comps << "&> /dev/null" if ignore_output
  comps << "|| true" if can_fail
  cmd = comps.join(" ")
  raise "Fail to run command '#{cmd}'" unless system(cmd)
end

#git_clone(cmd, options = {}) ⇒ Object



22
23
24
# File 'lib/cocoapods-jxedt/git_helper/git_command.rb', line 22

def git_clone(cmd, options = {})
  git("clone #{cmd}", :git_dir => false)
end

#git_commit_and_push(branch) ⇒ Object



40
41
42
43
44
45
# File 'lib/cocoapods-jxedt/git_helper/git_command.rb', line 40

def git_commit_and_push(branch)
  commit_message = "Update prebuilt cache"
  git("add .")
  git("commit -m '#{commit_message}'")
  git("push origin #{branch}")
end

#git_fetch(repo, branch) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cocoapods-jxedt/git_helper/git_command.rb', line 26

def git_fetch(repo, branch)
  Pod::UI.puts "Fetching cache from #{repo} (branch: #{branch})".green
  dest_dir = @cache_path
  if Dir.exist?(dest_dir + "/.git")
    git("fetch origin #{branch}")
    git("checkout -f FETCH_HEAD", ignore_output: true)
    git("branch -D #{branch}", ignore_output: true, can_fail: true)
    git("checkout -b #{branch}")
  else
    FileUtils.rm_rf(dest_dir)
    git_clone("--depth=1 --branch=#{branch} #{repo} #{dest_dir}")
  end
end

#prepare_cache_dirObject



8
9
10
# File 'lib/cocoapods-jxedt/git_helper/git_command.rb', line 8

def prepare_cache_dir
  FileUtils.mkdir_p(@cache_path) if @cache_path
end