lib/fetchers/git.rb in inspec-4.3.2 vs lib/fetchers/git.rb in inspec-4.6.3
- old
+ new
@@ -1,10 +1,9 @@
-# encoding: utf-8
-require 'tmpdir'
-require 'fileutils'
-require 'mixlib/shellout'
-require 'inspec/log'
+require "tmpdir"
+require "fileutils"
+require "mixlib/shellout"
+require "inspec/log"
module Fetchers
#
# The git fetcher uses the git binary to fetch remote git sources.
# Git-based sources should be specified with the `git:` key in the
@@ -23,16 +22,16 @@
# 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 Git < Inspec.fetcher(1)
- name 'git'
+ name "git"
priority 200
def self.resolve(target, opts = {})
if target.is_a?(String)
- new(target, opts) if target.start_with?('git@') || target.end_with?('.git')
+ 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
@@ -52,11 +51,11 @@
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)
+ FileUtils.cp_r(tmpdir + "/.", @repo_directory)
end
end
@repo_directory
end
@@ -80,11 +79,11 @@
elsif @branch
resolve_ref(@branch)
elsif @tag
resolve_ref(@tag)
else
- resolve_ref('master')
+ resolve_ref("master")
end
end
def resolve_ref(ref_name)
command_string = "git ls-remote \"#{@remote_url}\" \"#{ref_name}*\""
@@ -128,11 +127,11 @@
pairs.find { |m| m[1].end_with?(ref_name.to_s) }&.first
end
end
def cloned?
- File.directory?(File.join(@repo_directory, '.git'))
+ File.directory?(File.join(@repo_directory, ".git"))
end
def clone(dir = @repo_directory)
git_cmd("clone #{@remote_url} ./", dir) unless cloned?
@repo_directory
@@ -147,23 +146,23 @@
def git_cmd(cmd, dir = @repo_directory)
cmd = shellout("git #{cmd}", cwd: dir)
cmd.error!
cmd.status
rescue Errno::ENOENT
- raise 'To use git sources, you must have git installed.'
+ raise "To use git sources, you must have git installed."
end
def shellout(cmd, opts = {})
Inspec::Log.debug("Running external command: #{cmd} (#{opts})")
cmd = Mixlib::ShellOut.new(cmd, opts)
cmd.run_command
Inspec::Log.debug("External command: completed with exit status: #{cmd.exitstatus}")
- Inspec::Log.debug('External command: STDOUT BEGIN')
+ Inspec::Log.debug("External command: STDOUT BEGIN")
Inspec::Log.debug(cmd.stdout)
- Inspec::Log.debug('External command: STDOUT END')
- Inspec::Log.debug('External command: STDERR BEGIN')
+ Inspec::Log.debug("External command: STDOUT END")
+ Inspec::Log.debug("External command: STDERR BEGIN")
Inspec::Log.debug(cmd.stderr)
- Inspec::Log.debug('External command: STDERR END')
+ Inspec::Log.debug("External command: STDERR END")
cmd
end
end
end