Class: Fetchers::Git
- Inherits:
-
Object
- Object
- Fetchers::Git
- Defined in:
- lib/fetchers/git.rb
Overview
The git fetcher uses the git binary to fetch remote git sources. Git-based sources should be specified with the ‘git:` key in the source hash. Additionally, we accept `:branch`, `:ref`, and `:tag` keys to allow users to pin to a particular revision.
Parts of this class are derived from:
https://github.com/chef/omnibus/blob/master/lib/omnibus/fetchers/git_fetcher.rb
which is Copyright 2012-2014 Chef Software, Inc. and offered under the same Apache 2 software license as inspec.
Many thanks to the omnibus authors!
Note that we haven’t replicated all of omnibus’ features here. If you got to this file during debugging, you may want to look at the omnibus source for hints.
Class Method Summary collapse
Instance Method Summary collapse
- #archive_path ⇒ Object
- #cache_key ⇒ Object
- #fetch(dir) ⇒ Object
-
#initialize(remote_url, opts = {}) ⇒ Git
constructor
A new instance of Git.
- #resolved_source ⇒ Object
Constructor Details
#initialize(remote_url, opts = {}) ⇒ Git
Returns a new instance of Git.
35 36 37 38 39 40 41 |
# File 'lib/fetchers/git.rb', line 35 def initialize(remote_url, opts = {}) @branch = opts[:branch] @tag = opts[:tag] @ref = opts[:ref] @remote_url = remote_url @repo_directory = nil end |
Class Method Details
.resolve(target, opts = {}) ⇒ Object
31 32 33 |
# File 'lib/fetchers/git.rb', line 31 def self.resolve(target, opts = {}) new(target[:git], opts.merge(target)) if target.respond_to?(:has_key?) && target.key?(:git) end |
Instance Method Details
#archive_path ⇒ Object
63 64 65 |
# File 'lib/fetchers/git.rb', line 63 def archive_path @repo_directory end |
#cache_key ⇒ Object
59 60 61 |
# File 'lib/fetchers/git.rb', line 59 def cache_key resolved_ref end |
#fetch(dir) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fetchers/git.rb', line 43 def fetch(dir) @repo_directory = dir FileUtils.mkdir_p(dir) unless Dir.exist?(dir) if cloned? checkout else Dir.mktmpdir do |tmpdir| checkout(tmpdir) Inspec::Log.debug("Checkout of #{resolved_ref} successful. Moving checkout to #{dir}") FileUtils.cp_r(tmpdir + '/.', @repo_directory) end end @repo_directory end |
#resolved_source ⇒ Object
67 68 69 |
# File 'lib/fetchers/git.rb', line 67 def resolved_source { git: @remote_url, ref: resolved_ref } end |