Class: FPM::Cookery::SourceHandler::Git
- 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
#extract(config = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fpm/cookery/source_handler/git.rb', line 35 def extract(config = {}) extracted_source = (builddir/local_path.basename('.git').to_s).to_s Dir.chdir(local_path) do if [:sha] git('reset', '--hard', [:sha]) extracted_source << "-#{[:sha]}" elsif [:tag] git('checkout', '-f', [:tag]) extracted_source << "-tag-#{[:tag]}" elsif [:branch] git('checkout', '-f', "origin/#{[:branch]}") extracted_source << "-branch-#{[:branch]}" else git('checkout', '-f', 'origin/HEAD') extracted_source << '-HEAD' end case .fetch(:extract, :default).to_s.to_sym when :clone if File.exist?(extracted_source) Log.info("Source directory has already been cloned into #{extracted_source}") else git('clone', '-l', '--recurse-submodules', Dir.pwd, extracted_source) end else # Trailing '/' is important! (see git-checkout-index(1)) git('checkout-index', '-a', '-f', "--prefix=#{extracted_source}/") if [:submodule] git('submodule', 'foreach', "mkdir -p #{extracted_source}/$path && cp -r . #{extracted_source}/$path") end end end extracted_source end |
#fetch(config = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fpm/cookery/source_handler/git.rb', line 11 def fetch(config = {}) rev = [:sha] || [: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 Dir.chdir(local_path) do git('submodule', 'update', '--init') if [:submodule] end end local_path end |