Class: FPM::Cookery::SourceHandler::Git

Inherits:
Template
  • Object
show all
Defined in:
lib/fpm/cookery/source_handler/git.rb

Constant Summary collapse

CHECKSUM =
false
NAME =
:git

Instance Attribute Summary

Attributes inherited from Template

#builddir, #cachedir, #has_checksum, #name, #options, #url

Instance Method Summary collapse

Methods inherited from Template

#checksum?, #initialize, #local_path, #source

Constructor Details

This class inherits a constructor from FPM::Cookery::SourceHandler::Template

Instance Method Details

#extractObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fpm/cookery/source_handler/git.rb', line 32

def extract
  extracted_source = (builddir/local_path.basename('.git').to_s).to_s

  Dir.chdir(local_path) do
    if options[:sha]
      git('reset', '--hard', options[:sha])
      extracted_source << "-#{options[:sha]}"
    elsif options[:tag]
      git('checkout', '-f', options[:tag])
      extracted_source << "-tag-#{options[:tag]}"
    elsif options[:branch]
      git('checkout', '-f', "origin/#{options[:branch]}")
      extracted_source << "-branch-#{options[:branch]}"
    else
      git('checkout', '-f', 'origin/HEAD')
      extracted_source << '-HEAD'
    end

    # Trailing '/' is important! (see git-checkout-index(1))
    git('checkout-index', '-a', '-f', "--prefix=#{extracted_source}/")
  end

  extracted_source
end

#fetchObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fpm/cookery/source_handler/git.rb', line 11

def fetch
  rev = options[:sha] || options[:tag]

  if local_path.exist?
    Dir.chdir(local_path) do
      if rev and has_rev?(rev)
        Log.info("Skipping fetch, rev #{rev} exists.")
      else
        git('fetch', url)
        git('fetch', '--tags', url)
      end
    end
  else
    Dir.chdir(cachedir) do
      git('clone', url, local_path)
    end
  end

  local_path
end