diff --git a/.codeclimate.yml b/.codeclimate.yml index 6d90eae38..bfa974e69 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -5,6 +5,9 @@ checks: identical-code: config: threshold: 40 # Unfortunately, we have a lot of duplicate code in places like lib/inspec/control_eval_context.rb + method-complexity: # 'Cognitive Complexity' in the UI + config: + threshold: 10 # 5 Default 5 is really tight plugins: fixme: enabled: true diff --git a/lib/fetchers/git.rb b/lib/fetchers/git.rb index 01a14633c..a78b55f9f 100644 --- a/lib/fetchers/git.rb +++ b/lib/fetchers/git.rb @@ -68,19 +68,7 @@ module Fetchers Dir.mktmpdir do |working_dir| checkout(working_dir) if @relative_path - 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 acourtesy, assuming we're writing to the cache; if we're - # vendoring to somthing more complex, don't bother. - FileUtils.rmdir(destination_path) if Dir.empty?(destination_path) - - raise ArgumentError.new("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) + perform_relative_path_fetch(destination_path, working_dir) else Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \ "Moving checkout to #{destination_path}") @@ -91,6 +79,22 @@ module Fetchers @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 acourtesy, assuming we're writing to the cache; if we're + # vendoring to somthing more complex, don't bother. + FileUtils.rmdir(destination_path) if Dir.empty?(destination_path) + + raise ArgumentError.new("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::SHA256.hexdigest(resolved_ref + @relative_path) diff --git a/test/functional/git_fetcher_test.rb b/test/functional/git_fetcher_test.rb index bb8b18cd4..a93bddd09 100644 --- a/test/functional/git_fetcher_test.rb +++ b/test/functional/git_fetcher_test.rb @@ -68,7 +68,7 @@ describe "running profiles with git-based dependencies" do #======================================================================# # Revision Selection #======================================================================# - # TODO: test branch, rev, and tag capabilities + # NOTE: test branch, rev, and tag capabilities are tested in unit tests #======================================================================# # Relative Path Support @@ -99,9 +99,6 @@ describe "running profiles with git-based dependencies" do #------------ Edge Cases for Relative Path Support -------------------# - # TODO: These next two tests trigger a bug, in which the profile appears - # to have a key collision in the cache. - describe "running a profile with an '' relative path dependency" do it "should find the top-level profile in the git-referenced child profile and execute that" do assert_relative_fetch_works("relative-empty", ["relative-empty", "basic-local"], ["relative-empty-01", "basic-local-01"])