Skip to content

Commit

Permalink
(PDK-1033) Handle git fixture remote url changing
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Jun 20, 2018
1 parent 9b87f3f commit 4e8e992
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/puppetlabs_spec_helper/tasks/fixtures.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'yaml'
require 'open3'

module PuppetlabsSpecHelper; end
module PuppetlabsSpecHelper::Tasks; end
Expand Down Expand Up @@ -156,6 +157,22 @@ def revision(scm, target, ref)
system("cd #{target} && #{scm} #{args.flatten.join ' '}")
end

def valid_repo?(scm, target, remote)
return false unless File.directory?(target)
return true if scm == 'hg'

return true if git_remote_url(target) == remote

warn "Git remote for #{target} has changed, recloning repository"
FileUtils.rm_rf(target)
false
end

def git_remote_url(target)
output, status = Open3.capture2e('git', '-C', target, 'remote', 'get-url', 'origin')
status.success? ? output.strip : nil
end

def remove_subdirectory(target, subdir)
unless subdir.nil?
Dir.mktmpdir do |tmpdir|
Expand Down Expand Up @@ -265,7 +282,7 @@ def check_directory_for_symlinks(dir = '.')
logger.debug "New Thread started for #{remote}"
# start up a new thread and store it in the opts hash
opts[:thread] = Thread.new do
if File.directory?(target)
if valid_repo?(scm, target, remote)
update_repo(scm, target)
else
clone_repo(scm, remote, target, subdir, ref, branch, flags)
Expand Down

0 comments on commit 4e8e992

Please sign in to comment.