\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7<F<2PFAFZUP_xxnnx\F5\AF\B9\91\C8\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\DB\00CUZZxix‚\EB\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\C0\00\00b\00d\00\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00\001A!Q\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00!1AQ\FF\DA\00\00\00?\00\F6\00\00\00\00\00\00\00\00\00\00\A0\00\00\C5\CF\F8\E7Ó\FCjD~\B9^\AD\%\B3]\D8cs-\BBs,-\A0\00"\80\00%\B83rÏ^K~F\A4ea\00E\00\C6\EE=u\B1\9B\D1\00@\00r\BE8\F9:\FE5#.M\00\E7\CB\C9q\CBq\D6\F2\BE\B7\C7>\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7	\8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh
\00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€
\00$\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95
59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>C///</title>
</head>
require "tmpdir"
require "fileutils"
require "mixlib/shellout"
require "inspec/log"

module Inspec::Fetcher
  #
  # 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 Git < Inspec.fetcher(1)
    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")
      elsif target.respond_to?(:has_key?) && target.key?(:git)
        new(target[:git], opts.merge(target))
      end
    end

    def initialize(remote_url, opts = {})
      @branch = opts[:branch]
      @tag = opts[:tag]
      @ref = opts[:ref]
      @remote_url = expand_local_path(remote_url)
      @repo_directory = nil
      @relative_path = opts[:relative_path] if opts[:relative_path] && !opts[:relative_path].empty?
    end

    def expand_local_path(url_or_file_path)
      # This paths to local on-disk repos, not relative paths within repos.
      # This is especially needed with testing.

      # We could try to do something clever with URI
      # processing, but then again, if you passed a relative path
      # to an on-disk repo, you probably expect it to exist.
      return url_or_file_path unless File.exist?(url_or_file_path)

      # It's important to expand this path, because it may be specified
      # locally in the metadata files, and when we clone, we will be
      # in a temp dir.
      File.expand_path(url_or_file_path)
    end

    def fetch(destination_path)
      @repo_directory = destination_path # Might be the cache, or vendoring, or something else
      FileUtils.mkdir_p(destination_path) unless Dir.exist?(destination_path)

      if cloned?
        checkout
      else
        Dir.mktmpdir do |working_dir|
          checkout(working_dir)
          if @relative_path
            perform_relative_path_fetch(destination_path, working_dir)
          else
            Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \
                              "Moving checkout to #{destination_path}")
            FileUtils.cp_r(working_dir + "/.", destination_path)
          end
        end
      end
      @repo_directory
    end

    def perform_relative_path_fetch(destination_path, working_dir)
      Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \
                        "Moving #{@relative_path} to #{destination_path}")
      unless File.exist?("#{working_dir}/#{@relative_path}")
        # Cleanup the destination path - otherwise we'll have an empty dir
        # in the cache, which is enough to confuse the cache reader
        # This is a courtesy, assuming we're writing to the cache; if we're
        # vendoring to something more complex, don't bother.
        FileUtils.rmdir(destination_path) if Dir.empty?(destination_path)

        raise Inspec::FetcherFailure, "Cannot find relative path '#{@relative_path}' " \
                                      "within profile in git repo specified by '#{@remote_url}'"
      end
      FileUtils.cp_r("#{working_dir}/#{@relative_path}", destination_path)
    end

    def cache_key
      return resolved_ref unless @relative_path

      OpenSSL::Digest.hexdigest("SHA256", resolved_ref + @relative_path)
    end

    def archive_path
      @repo_directory
    end

    def resolved_source
      source = { git: @remote_url, ref: resolved_ref }
      source[:relative_path] = @relative_path if @relative_path
      source
    end

    def update_from_opts(opts)
      %i{branch tag ref}.map { |opt_name| update_ivar_from_opt(opt_name, opts) }.any?
    end

    private

    def resolved_ref
      @resolved_ref ||= if @ref
                          @ref
                        elsif @branch
                          resolve_ref(@branch)
                        elsif @tag
                          resolve_ref(@tag)
                        else
                          resolve_ref("master")
                        end
    end

    def resolve_ref(ref_name)
      command_string = "git ls-remote \"#{@remote_url}\" \"#{ref_name}*\""
      cmd = shellout(command_string)
      raise(Inspec::FetcherFailure, "Profile git dependency failed for #{@remote_url} - error running '#{command_string}': #{cmd.stderr}") unless cmd.exitstatus == 0

      ref = parse_ls_remote(cmd.stdout, ref_name)
      unless ref
        raise Inspec::FetcherFailure, "Profile git dependency failed - unable to resolve #{ref_name} to a specific git commit for #{@remote_url}"
      end

      ref
    end

    #
    # The following comment is a minor modification of the comment in
    # the omnibus source for a similar function:
    #
    # Dereference annotated tags.
    #
    # The +remote_list+ parameter is assumed to look like this:
    #
    #   a2ed66c01f42514bcab77fd628149eccb4ecee28        refs/tags/rel-0.11.0
    #   f915286abdbc1907878376cce9222ac0b08b12b8        refs/tags/rel-0.11.0^{}
    #
    # The SHA with ^{} is the commit pointed to by an annotated
    # tag. If ref isn't an annotated tag, there will not be a line
