diff --git a/lib/librarian/puppet/simple/cli.rb b/lib/librarian/puppet/simple/cli.rb index 3c4bb50..2fb4888 100644 --- a/lib/librarian/puppet/simple/cli.rb +++ b/lib/librarian/puppet/simple/cli.rb @@ -43,22 +43,7 @@ def update @custom_module_path = options[:path] eval(File.read(File.expand_path(options[:puppetfile]))) each_module_of_type(:git) do |repo| - if Dir.exists?(File.join(module_path, repo[:name])) - Dir.chdir(File.join(module_path, repo[:name])) do - remote = repo[:git] - # if no ref is given, assume master - branch = repo[:ref] || 'master' - if branch =~ /^origin\/(.*)$/ - branch = $1 - end - co_cmd = 'git checkout FETCH_HEAD' - update_cmd = "git fetch #{repo[:git]} #{branch} && #{co_cmd}" - print_verbose "\n\n#{repo[:name]} -- #{update_cmd}" - git_pull_cmd = system_cmd(update_cmd) - end - else - install_git module_path, repo[:name], repo[:git], repo[:ref] - end + install_git module_path, repo[:name], repo[:git], repo[:ref] end end diff --git a/lib/librarian/puppet/simple/installer.rb b/lib/librarian/puppet/simple/installer.rb index 8506365..be47295 100644 --- a/lib/librarian/puppet/simple/installer.rb +++ b/lib/librarian/puppet/simple/installer.rb @@ -49,11 +49,24 @@ def install_git(module_path, module_name, repo, ref = nil) module_dir = File.join(module_path, module_name) Dir.chdir(module_path) do - print_verbose "cloning #{repo}" - system_cmd("git clone #{repo} #{module_name}") + unless Dir.exists?(File.join(module_path, repo)) + print_verbose "cloning #{repo}" + system_cmd("git clone #{repo} #{module_name}") + end Dir.chdir(module_dir) do - system_cmd('git branch -r') - system_cmd("git checkout #{ref}") if ref + # if no ref is given, assume master + ref ||= 'master' + if ref =~ /^origin\/(.*)$/ + ref = $1 + end + if ref.start_with? 'refs/changes/' + co_cmd = 'git checkout FETCH_HEAD' + update_cmd = "git fetch origin #{ref} && #{co_cmd}" + else + co_cmd = "git checkout #{ref}" + update_cmd = "git fetch --all --tags && #{co_cmd}" + end + system_cmd(update_cmd) end end end