diff --git a/app/models/manageiq/providers/embedded_automation_manager/configuration_script_source.rb b/app/models/manageiq/providers/embedded_automation_manager/configuration_script_source.rb index 19e041b5985..60632e90690 100644 --- a/app/models/manageiq/providers/embedded_automation_manager/configuration_script_source.rb +++ b/app/models/manageiq/providers/embedded_automation_manager/configuration_script_source.rb @@ -85,11 +85,22 @@ def sync raise NotImplementedError, N_("sync must be implemented in a subclass") end - def checkout_git_repository(target_directory) + def checkout_git_repository(target_directory = nil) return if git_repository.nil? + target_directory_given = !!target_directory + target_directory ||= Pathname.new(Dir.mktmpdir) + git_repository.update_repo git_repository.checkout(scm_branch, target_directory) + + return target_directory unless block_given? + + begin + yield target_directory + ensure + FileUtils.rm_rf(target_directory) unless target_directory_given + end end private