Class: Rip::GitPackage

Inherits:
Package show all
Includes:
Sh::Git
Defined in:
lib/rip/packages/git_package.rb

Instance Attribute Summary

Attributes inherited from Package

#files, #source

Instance Method Summary collapse

Methods included from Sh::Git

#git_cat_file, #git_clone, #git_fetch, #git_ls_remote, #git_reset_hard, #git_rev_parse, #git_submodule_init, #git_submodule_update

Methods inherited from Package

#cache_name, #cache_path, #dependencies, #dependencies!, #fetch, #files!, for, handles, #initialize, #installed?, #packages_path, #run_hook, #to_s, #ui, #unpack

Methods included from PackageAPI

#cached?, #dependencies!, #files!, #meta_package?

Methods included from Memoize

included, #memoize, #method_added

Constructor Details

This class inherits a constructor from Rip::Package

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rip/packages/git_package.rb', line 21

def exists?
  case source
  when /^file:/
    file_exists?
  when /^git:/
    remote_exists?
  when /\.git$/
    file_exists? || remote_exists?
  else
    false
  end
end

#fetch!Object



34
35
36
37
38
39
40
41
42
# File 'lib/rip/packages/git_package.rb', line 34

def fetch!
  if File.exists? cache_path
    Dir.chdir cache_path do
      git_fetch('origin')
    end
  else
    git_clone(source, cache_path)
  end
end

#nameObject



8
9
10
# File 'lib/rip/packages/git_package.rb', line 8

def name
  source.split('/').last.chomp('.git')
end

#unpack!Object



44
45
46
47
48
49
50
# File 'lib/rip/packages/git_package.rb', line 44

def unpack!
  Dir.chdir cache_path do
    git_reset_hard version_is_branch? ? "origin/#{version}" : version
    git_submodule_init
    git_submodule_update
  end
end

#versionObject



12
13
14
15
16
17
18
19
# File 'lib/rip/packages/git_package.rb', line 12

def version
  return @version if @version

  fetch!
  Dir.chdir cache_path do
    @version = git_rev_parse('origin/master')[0,7]
  end
end