diff --git a/Puppetfile b/Puppetfile index a19d70a6b..d8e804fc7 100644 --- a/Puppetfile +++ b/Puppetfile @@ -219,7 +219,7 @@ mod 'tuskar', :git => 'https://github.com/openstack/puppet-tuskar.git' mod 'vcsrepo', - :commit => 'fd63cd94caae3aedcce53b8fad9fd1d5f29139da', + :commit => 'dd4b638a420c75eb3a3a2badceffc720be231096', :git => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git' mod 'vlan', diff --git a/vcsrepo/CHANGELOG.md b/vcsrepo/CHANGELOG.md index ad10e9730..7d1060c7b 100644 --- a/vcsrepo/CHANGELOG.md +++ b/vcsrepo/CHANGELOG.md @@ -1,6 +1,16 @@ # Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.3.1] - 2015-07-28 Supported Release +###Summary +This release includes a number of bugfixes along with some test updates. + +### Fixed +- Fix for detached HEAD on git 2.4+ +- Git provider doesn't ignore revision property when depth is used (MODULES-2131) +- Test fixes +- Check if submodules == true before calling update_submodules + ## [1.3.0] - 2015-05-19 Supported Release ### Summary This release adds git provider remote handling, svn conflict resolution, and fixes the git provider when /tmp is mounted noexec. @@ -125,6 +135,7 @@ our many contributors for all of these fixes! - CVS: - Documented the "module" attribute. +[1.3.1]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.3.0...1.3.1 [1.3.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.2.0...1.3.0 [1.2.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.1.0...1.2.0 [1.1.0]: https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/1.0.2...1.1.0 diff --git a/vcsrepo/lib/puppet/provider/vcsrepo/git.rb b/vcsrepo/lib/puppet/provider/vcsrepo/git.rb index 807495045..4623f8e1c 100644 --- a/vcsrepo/lib/puppet/provider/vcsrepo/git.rb +++ b/vcsrepo/lib/puppet/provider/vcsrepo/git.rb @@ -45,7 +45,11 @@ def latest? # # @return [String] Returns the target sha/tag/branch def latest - @resource.value(:revision) + if not @resource.value(:revision) and branch = on_branch? + return branch + else + return @resource.value(:revision) + end end # Get the current revision of the repo (tag/branch/sha) @@ -72,7 +76,11 @@ def revision=(desired) #updated and authoritative. #TODO might be worthwhile to have an allow_local_changes param to decide #whether to reset or pull when we're ensuring latest. - at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") } + if @resource.value(:source) + at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") } + else + at_path { git_with_identity('reset', '--hard', "#{desired}") } + end end #TODO Would this ever reach here if it is bare? if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true @@ -103,7 +111,7 @@ def default_url def working_copy_exists? if @resource.value(:source) and File.exists?(File.join(@resource.value(:path), '.git', 'config')) - File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{default_url}/).any? + File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{Regexp.escape(default_url)}/).any? else File.directory?(File.join(@resource.value(:path), '.git')) end @@ -281,7 +289,7 @@ def commits_in?(dot_git) # handle upstream branch changes # @!visibility private def checkout(revision = @resource.value(:revision)) - if !local_branch_revision? && remote_branch_revision? + if !local_branch_revision?(revision) && remote_branch_revision?(revision) #non-locally existant branches (perhaps switching to a branch that has never been checked out) at_path { git_with_identity('checkout', '--force', '-b', revision, '--track', "#{@resource.value(:remote)}/#{revision}") } else @@ -329,11 +337,13 @@ def branches at_path { git_with_identity('branch', '-a') }.gsub('*', ' ').split(/\n/).map { |line| line.strip } end + # git < 2.4 returns 'detached from' + # git 2.4+ returns 'HEAD detached at' # @!visibility private def on_branch? at_path { matches = git_with_identity('branch', '-a').match /\*\s+(.*)/ - matches[1] unless matches[1].match /(\(detached from|\(no branch)/ + matches[1] unless matches[1].match /(\(detached from|\(HEAD detached at|\(no branch)/ } end @@ -386,7 +396,17 @@ def latest_revision # @return [String] Returns the tag/branch of the current repo if it's up to # date; otherwise returns the sha of the requested revision. def get_revision(rev = 'HEAD') - update_references + if @resource.value(:source) + update_references + else + status = at_path { git_with_identity('status')} + is_it_new = status =~ /Initial commit/ + if is_it_new + status =~ /On branch (.*)/ + branch = $1 + return branch + end + end current = at_path { git_with_identity('rev-parse', rev).strip } if @resource.value(:revision) if tag_revision? diff --git a/vcsrepo/metadata.json b/vcsrepo/metadata.json index ef74e8695..1552840af 100644 --- a/vcsrepo/metadata.json +++ b/vcsrepo/metadata.json @@ -1,12 +1,15 @@ { "name": "puppetlabs-vcsrepo", - "version": "1.3.0", + "version": "1.3.1", "author": "Puppet Labs", "summary": "Puppet module providing a type to manage repositories from various version control systems", "license": "GPLv2", "source": "https://github.com/puppetlabs/puppetlabs-vcsrepo", "project_page": "https://github.com/puppetlabs/puppetlabs-vcsrepo", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", + "dependencies": [ + + ], "operatingsystem_support": [ { "operatingsystem": "RedHat", @@ -67,14 +70,11 @@ "requirements": [ { "name": "pe", - "version_requirement": "3.x" + "version_requirement": ">= 3.0.0 < 2015.3.0" }, { "name": "puppet", - "version_requirement": "3.x" + "version_requirement": ">= 3.0.0 < 5.0.0" } - ], - "dependencies": [ - ] } diff --git a/vcsrepo/spec/acceptance/create_repo_spec.rb b/vcsrepo/spec/acceptance/create_repo_spec.rb index db0cd2954..53a93c971 100644 --- a/vcsrepo/spec/acceptance/create_repo_spec.rb +++ b/vcsrepo/spec/acceptance/create_repo_spec.rb @@ -30,6 +30,22 @@ end end + context 'no source but revision provided' do + it 'should not fail (MODULES-2125)' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/testrepo_blank_with_revision_repo": + ensure => present, + provider => git, + revision => 'master' + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + end + context 'bare repo' do it 'creates a bare repo' do pp = <<-EOS diff --git a/vcsrepo/spec/acceptance/files/server.crt b/vcsrepo/spec/acceptance/files/server.crt index ef1de5a92..270f65c0f 100644 --- a/vcsrepo/spec/acceptance/files/server.crt +++ b/vcsrepo/spec/acceptance/files/server.crt @@ -1,13 +1,13 @@ -----BEGIN CERTIFICATE----- -MIICATCCAWoCCQCS3fQotV10LzANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB -VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0 -cyBQdHkgTHRkMB4XDTE0MDQyMzIyMzEyM1oXDTE1MDQyMzIyMzEyM1owRTELMAkG -A1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0 +MIICATCCAWoCCQDRobnOvvkStDANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB +VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 +cyBQdHkgTHRkMB4XDTE1MDQwODE3MjM1NVoXDTI1MDQwNTE3MjM1NVowRTELMAkG +A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0 IFdpZGdpdHMgUHR5IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyRTv uX6328aQ5Auc8PI+xNaCiE0UZNYcs+xq3AEkR/Tnz0HGXdx3+PnFG7MIRSS65hXA VGenZk3wP4vNIe9gu+G9jtOFTJOgoOBUnJ/Hcs79Zgcmz3cAWQpqww+CZpyngUDS msZ5HoEbNS+qaIron3IrYCgPsy1BHFs5ze7JrtcCAwEAATANBgkqhkiG9w0BAQUF -AAOBgQA2uLvdc1cf+nt7d8Lmu0SdaoIsCzh6DjVscCpFJKXdDjGT2Ys40iKbLRnY -Tt98wa6uRzEhSKfx+zVi8n3PSkQHlER7jzKFXMVx8NEt2/O/APKXVizmLFjk5WcT -FvGmmbkqX+Nj9TUTuSRZEmF776r5k8U5ABu/VarxvAzyoXAhqA== +AAOBgQCaYVv8WbFbrnLMOcyjE7GjSmVh68fEN+AqntZa1Z5GOv6OQIN9mVSoNxWo +lb/9xmldfMQThgKckHHvB5Q9kf923nMQZOi8yxyaoeYWrkglkFFU/sdF6yuFBdUU +D+rXmHnS754FLTGDzESmlRVUCYuwVgrRdm+P+wu2+lZT3x85VA== -----END CERTIFICATE----- diff --git a/vcsrepo/spec/acceptance/modules_1800_spec.rb b/vcsrepo/spec/acceptance/modules_1800_spec.rb new file mode 100644 index 000000000..12415e803 --- /dev/null +++ b/vcsrepo/spec/acceptance/modules_1800_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper_acceptance' + +tmpdir = default.tmpdir('vcsrepo') + +describe 'clones a remote repo' do + before(:all) do + my_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + shell("mkdir -p #{tmpdir}") # win test + end + + after(:all) do + shell("rm -rf #{tmpdir}/vcsrepo") + end + + context 'ensure latest with no revision' do + it 'clones from default remote' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/vcsrepo": + ensure => present, + provider => git, + source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git", + } + EOS + + apply_manifest(pp, :catch_failures => true) + shell("cd #{tmpdir}/vcsrepo; /usr/bin/git reset --hard HEAD~2") + end + + it 'updates' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/vcsrepo": + ensure => latest, + provider => git, + source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git", + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + end +end diff --git a/vcsrepo/spec/acceptance/modules_2326_spec.rb b/vcsrepo/spec/acceptance/modules_2326_spec.rb new file mode 100644 index 000000000..d62dbb093 --- /dev/null +++ b/vcsrepo/spec/acceptance/modules_2326_spec.rb @@ -0,0 +1,69 @@ +require 'spec_helper_acceptance' + +tmpdir = default.tmpdir('vcsrepo') + +describe 'clones with special characters' do + + before(:all) do + my_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + shell("mkdir -p #{tmpdir}") # win test + scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir) + shell("cd #{tmpdir} && ./create_git_repo.sh") + end + + after(:all) do + shell("rm -rf #{tmpdir}/testrepo.git") + end + + context 'as a user with ssh' do + before(:all) do + # create user + pp = <<-EOS + group { 'testuser-ssh': + ensure => present, + } + user { 'testuser-ssh': + ensure => present, + groups => 'testuser-ssh', + managehome => true, + } + EOS + apply_manifest(pp, :catch_failures => true) + + # create ssh keys + shell('mkdir -p /home/testuser-ssh/.ssh') + shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""') + + # copy public key to authorized_keys + shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys') + shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config') + shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh') + shell("chown testuser-ssh:testuser-ssh #{tmpdir}") + end + + it 'applies the manifest' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/testrepo_user_ssh": + ensure => present, + provider => git, + source => "git+ssh://testuser-ssh@localhost#{tmpdir}/testrepo.git", + user => 'testuser-ssh', + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + after(:all) do + pp = <<-EOS + user { 'testuser-ssh': + ensure => absent, + managehome => true, + } + EOS + apply_manifest(pp, :catch_failures => true) + end + end +end diff --git a/vcsrepo/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/vcsrepo/spec/unit/puppet/provider/vcsrepo/git_spec.rb index a240b50c6..87113fa50 100644 --- a/vcsrepo/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/vcsrepo/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -206,7 +206,7 @@ def branch_a_list(include_branch = nil?) before do expects_chdir('/tmp/test') resource[:revision] = 'currentsha' - resource.delete(:source) + resource[:source] = 'http://example.com' provider.stubs(:git).with('config', 'remote.origin.url').returns('') provider.stubs(:git).with('fetch', 'origin') # FIXME provider.stubs(:git).with('fetch', '--tags', 'origin') @@ -272,6 +272,14 @@ def branch_a_list(include_branch = nil?) end end + context "when there's no source" do + it 'should return the revision' do + resource.delete(:source) + provider.expects(:git).with('status') + provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') + expect(provider.revision).to eq(resource.value(:revision)) + end + end end context "setting the revision property" do