Class: XCCache::GitStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/xccache/storage/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config::Mixin

#config

Constructor Details

#initialize(options = {}) ⇒ GitStorage

Returns a new instance of GitStorage.



7
8
9
10
11
12
13
14
15
# File 'lib/xccache/storage/git.rb', line 7

def initialize(options = {})
  super
  if (@remote = options[:remote])
    schemes = ["http://", "https://", "git@"]
    @remote = File.expand_path(@remote) unless schemes.any? { |x| @remote.start_with?(x) }
    ensure_remote
  end
  @branch = options[:branch]
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



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

def branch
  @branch
end

Instance Method Details

#pullObject



17
18
19
20
21
22
23
24
# File 'lib/xccache/storage/git.rb', line 17

def pull
  git.fetch("--depth 1 origin #{branch}")
  git.switch("--detach FETCH_HEAD", capture: true)
  git.clean("-dfx", capture: true)
  # Re-create local branch so that it has the latest from remote
  git.branch("-D #{branch} || true", capture: true)
  git.checkout("-b #{branch}", capture: true)
end

#pushObject



26
27
28
29
30
31
32
# File 'lib/xccache/storage/git.rb', line 26

def push
  return UI.info("No changes to push, cache repo is clean".magenta) if git.clean?

  git.add(".")
  git.commit("-m \"Update cache at #{Time.new}\"")
  git.push("-u origin #{branch}")
end