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