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.
37 38 39 40 41 42 43 |
# File 'lib/fetchers/git.rb', line 37 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 34 35 |
# File 'lib/fetchers/git.rb', line 31 def self.resolve(target, opts = {}) if target.respond_to?(:has_key?) &&target.key?(:git) new(target[:git], opts.merge(target)) end end |
Instance Method Details
#archive_path ⇒ Object
65 66 67 |
# File 'lib/fetchers/git.rb', line 65 def archive_path @repo_directory end |
#cache_key ⇒ Object
61 62 63 |
# File 'lib/fetchers/git.rb', line 61 def cache_key resolved_ref end |
#fetch(dir) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fetchers/git.rb', line 45 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
69 70 71 |
# File 'lib/fetchers/git.rb', line 69 def resolved_source { git: @remote_url, ref: resolved_ref } end |