From c714947908b69c538ea9d050d4375e2b3f19e7ac Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Sat, 13 Mar 2010 17:32:17 -0800 Subject: Support Mercurial tags, restructure examples --- README.HG.markdown | 19 +++++++--- examples/cvs/init.pp | 17 --------- examples/cvs/local.pp | 11 ++++++ examples/cvs/remote.pp | 5 +++ examples/git/bare_init.pp | 4 +++ examples/git/clone.pp | 5 +++ examples/git/init.pp | 15 -------- examples/git/working_copy_init.pp | 4 +++ examples/hg/clone.pp | 6 ++++ examples/hg/init.pp | 11 ------ examples/hg/init_repo.pp | 4 +++ examples/svn/checkout.pp | 6 ++++ examples/svn/init.pp | 4 --- examples/svn/server.pp | 4 +++ lib/puppet/provider/vcsrepo/hg.rb | 19 +++++++++- spec/fixtures/hg_tags.txt | 18 ++++++++++ spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 52 +++++++++++++++++++++++++--- 17 files changed, 146 insertions(+), 58 deletions(-) delete mode 100644 examples/cvs/init.pp create mode 100644 examples/cvs/local.pp create mode 100644 examples/cvs/remote.pp create mode 100644 examples/git/bare_init.pp create mode 100644 examples/git/clone.pp delete mode 100644 examples/git/init.pp create mode 100644 examples/git/working_copy_init.pp create mode 100644 examples/hg/clone.pp delete mode 100644 examples/hg/init.pp create mode 100644 examples/hg/init_repo.pp create mode 100644 examples/svn/checkout.pp delete mode 100644 examples/svn/init.pp create mode 100644 examples/svn/server.pp create mode 100644 spec/fixtures/hg_tags.txt diff --git a/README.HG.markdown b/README.HG.markdown index 9585ea4..e96db89 100644 --- a/README.HG.markdown +++ b/README.HG.markdown @@ -7,7 +7,7 @@ To create a blank repository Define a `vcsrepo` without a `source` or `revision`: vcsrepo { "/path/to/repo": - ensure => present, + ensure => present, provider => hg } @@ -17,16 +17,25 @@ To clone/pull & update a repository To get the default branch tip: vcsrepo { "/path/to/repo": - ensure => present, + ensure => present, provider => hg, - source => "http://hg.example.com/myrepo" + source => "http://hg.example.com/myrepo" } For a specific changeset, use `revision`: vcsrepo { "/path/to/repo": - ensure => present, + ensure => present, provider => hg, - source => "http://hg.example.com/myrepo" + source => "http://hg.example.com/myrepo" revision => '21ea4598c962' } + +You can also set `revision` to a tag: + + vcsrepo { "/path/to/repo": + ensure => present, + provider => hg, + source => "http://hg.example.com/myrepo" + revision => '1.1.2' + } diff --git a/examples/cvs/init.pp b/examples/cvs/init.pp deleted file mode 100644 index a3b9685..0000000 --- a/examples/cvs/init.pp +++ /dev/null @@ -1,17 +0,0 @@ -vcsrepo { "/tmp/vcstest-cvs-repo": - ensure => present, - provider => cvs -} - -vcsrepo { "/tmp/vcstest-cvs-workspace-local": - ensure => present, - provider => cvs, - source => "/tmp/vcstest-cvs-repo", - require => Vcsrepo["/tmp/vcstest-cvs-repo"] -} - -vcsrepo { "/tmp/vcstest-cvs-workspace-remote": - ensure => present, - provider => cvs, - source => ":pserver:anonymous@cvs.sv.gnu.org:/sources/leetcvrt" -} diff --git a/examples/cvs/local.pp b/examples/cvs/local.pp new file mode 100644 index 0000000..290616c --- /dev/null +++ b/examples/cvs/local.pp @@ -0,0 +1,11 @@ +vcsrepo { "/tmp/vcstest-cvs-repo": + ensure => present, + provider => cvs +} + +vcsrepo { "/tmp/vcstest-cvs-workspace-local": + ensure => present, + provider => cvs, + source => "/tmp/vcstest-cvs-repo", + require => Vcsrepo["/tmp/vcstest-cvs-repo"] +} diff --git a/examples/cvs/remote.pp b/examples/cvs/remote.pp new file mode 100644 index 0000000..d5dc702 --- /dev/null +++ b/examples/cvs/remote.pp @@ -0,0 +1,5 @@ +vcsrepo { "/tmp/vcstest-cvs-workspace-remote": + ensure => present, + provider => cvs, + source => ":pserver:anonymous@cvs.sv.gnu.org:/sources/leetcvrt" +} diff --git a/examples/git/bare_init.pp b/examples/git/bare_init.pp new file mode 100644 index 0000000..c70e705 --- /dev/null +++ b/examples/git/bare_init.pp @@ -0,0 +1,4 @@ +vcsrepo { "/tmp/vcstest-git-bare": + ensure => bare, + provider => git +} diff --git a/examples/git/clone.pp b/examples/git/clone.pp new file mode 100644 index 0000000..fe706cc --- /dev/null +++ b/examples/git/clone.pp @@ -0,0 +1,5 @@ +vcsrepo { "/tmp/vcstest-git-clone": + ensure => present, + provider => git, + source => "git://github.com/bruce/rtex.git" +} diff --git a/examples/git/init.pp b/examples/git/init.pp deleted file mode 100644 index 7763a91..0000000 --- a/examples/git/init.pp +++ /dev/null @@ -1,15 +0,0 @@ -vcsrepo { "/tmp/vcstest-git-bare": - ensure => bare, - provider => git -} - -vcsrepo { "/tmp/vcstest-git-wc": - ensure => present, - provider => git -} - -vcsrepo { "/tmp/vcstest-git-clone": - ensure => present, - provider => git, - source => "git://github.com/bruce/rtex.git" -} diff --git a/examples/git/working_copy_init.pp b/examples/git/working_copy_init.pp new file mode 100644 index 0000000..f92fbee --- /dev/null +++ b/examples/git/working_copy_init.pp @@ -0,0 +1,4 @@ +vcsrepo { "/tmp/vcstest-git-wc": + ensure => present, + provider => git +} diff --git a/examples/hg/clone.pp b/examples/hg/clone.pp new file mode 100644 index 0000000..c7a7ab5 --- /dev/null +++ b/examples/hg/clone.pp @@ -0,0 +1,6 @@ +vcsrepo { "/tmp/vcstest-hg-clone": + ensure => present, + provider => hg, + source => "http://hg.basho.com/riak", + revision => 'riak-0.5.3' +} diff --git a/examples/hg/init.pp b/examples/hg/init.pp deleted file mode 100644 index 620806e..0000000 --- a/examples/hg/init.pp +++ /dev/null @@ -1,11 +0,0 @@ -vcsrepo { "/tmp/vcstest-hg-init": - ensure => present, - provider => hg -} - -vcsrepo { "/tmp/vcstest-hg-clone": - ensure => present, - provider => hg, - source => "http://hg.basho.com/riak/", - revision => '34e6012c783a' -} diff --git a/examples/hg/init_repo.pp b/examples/hg/init_repo.pp new file mode 100644 index 0000000..660a78a --- /dev/null +++ b/examples/hg/init_repo.pp @@ -0,0 +1,4 @@ +vcsrepo { "/tmp/vcstest-hg-init": + ensure => present, + provider => hg +} diff --git a/examples/svn/checkout.pp b/examples/svn/checkout.pp new file mode 100644 index 0000000..10af8a7 --- /dev/null +++ b/examples/svn/checkout.pp @@ -0,0 +1,6 @@ +vcsrepo { "/tmp/vcstest-svn-checkout": + ensure => present, + provider => svn, + source => 'http://svn.edgewall.org/repos/babel/trunk' +} + diff --git a/examples/svn/init.pp b/examples/svn/init.pp deleted file mode 100644 index b48415b..0000000 --- a/examples/svn/init.pp +++ /dev/null @@ -1,4 +0,0 @@ -vcsrepo { "/tmp/vcstest-svn-server": - ensure => present, - provider => svn -} diff --git a/examples/svn/server.pp b/examples/svn/server.pp new file mode 100644 index 0000000..b48415b --- /dev/null +++ b/examples/svn/server.pp @@ -0,0 +1,4 @@ +vcsrepo { "/tmp/vcstest-svn-server": + ensure => present, + provider => svn +} diff --git a/lib/puppet/provider/vcsrepo/hg.rb b/lib/puppet/provider/vcsrepo/hg.rb index 7263b4f..928049f 100644 --- a/lib/puppet/provider/vcsrepo/hg.rb +++ b/lib/puppet/provider/vcsrepo/hg.rb @@ -24,7 +24,24 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d def revision at_path do - hg('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + current = hg('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + desired = @resource.value(:revision) + if current == desired + current + else + mapped = hg('tags')[/^#{Regexp.quote(desired)}\s+\d+:(\S+)/m, 1] + if mapped + # A tag, return that tag if it maps to the current nodeid + if current == mapped + desired + else + current + end + else + # Use the current nodeid + current + end + end end end diff --git a/spec/fixtures/hg_tags.txt b/spec/fixtures/hg_tags.txt new file mode 100644 index 0000000..53792e5 --- /dev/null +++ b/spec/fixtures/hg_tags.txt @@ -0,0 +1,18 @@ +tip 1019:bca3f20b249b +0.9.1 1017:76ce7cca95d8 +0.9 1001:dbaa6f4ec585 +0.8 839:65b66ac0fc83 +0.7.1 702:e1357f00129f +0.7 561:7b2af3b4c968 +0.6.3 486:e38077f4e4aa +0.6.2 405:07bb099b7b10 +0.6.1 389:93750f3fbbe2 +0.6 369:34e6012c783a +0.5.3 321:5ffa6ae7e699 +0.5.2 318:fdc2c2e4cebe +0.5.1 315:33a5ea0cbe7a +0.5 313:47490716f4c9 +0.4 240:47fa3a14cc63 +0.3.1 132:bc231db18e1c +0.3 130:661615e510dd +0.2 81:f98d13b442f6 diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index 56189a3..0df796e 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -70,12 +70,54 @@ describe provider_class do describe "when checking the revision property" do before do - @resource.expects(:value).with(:path).returns(@path) - end - it "should use 'hg tip'" do - @provider.expects('hg').with('parents').returns(fixture(:hg_parents)) + @resource.expects(:value).with(:path).returns(@path).at_least_once Dir.expects(:chdir).with(@path).yields - @provider.revision.should == '34e6012c783a' + end + context "when given a non-SHA as the resource revision" do + before do + @provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) + end + context "when its SHA is not different than the current SHA" do + before do + @resource.expects(:value).with(:revision).returns('0.6').at_least_once + end + it "should return the ref" do + @provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) + @provider.revision.should == '0.6' + end + end + context "when its SHA is different than the current SHA" do + before do + @resource.expects(:value).with(:revision).returns('0.5.3').at_least_once + end + it "should return the current SHA" do + @provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) + @provider.revision.should == '34e6012c783a' + end + end + end + context "when given a SHA as the resource revision" do + before do + @provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) + end + context "when it is the same as the current SHA" do + before do + @resource.expects(:value).with(:revision).returns('34e6012c783a').at_least_once + end + it "should return it" do + @provider.expects(:hg).with('tags').never + @provider.revision.should == '34e6012c783a' + end + end + context "when it is not the same as the current SHA" do + before do + @resource.expects(:value).with(:revision).returns('34e6012c7').at_least_once + end + it "should return the current SHA" do + @provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) + @provider.revision.should == '34e6012c783a' + end + end end end -- cgit v1.2.3