diff options
author | Ben Ford <ben.ford@puppetlabs.com> | 2013-03-12 16:20:08 -0700 |
---|---|---|
committer | Ben Ford <ben.ford@puppetlabs.com> | 2013-03-12 16:20:08 -0700 |
commit | 0cc694a568cbdc3adf2fea805651f2a30a5c99ac (patch) | |
tree | 21ea251726469c758d21e623e3894df41487b932 | |
parent | b9018d4903f94d2ef694446ad2843327421304fe (diff) | |
parent | 6915fa7e3799ff56233cf7e2c4d24686e435c401 (diff) | |
download | puppet-vcsrepo-0cc694a568cbdc3adf2fea805651f2a30a5c99ac.tar.gz puppet-vcsrepo-0cc694a568cbdc3adf2fea805651f2a30a5c99ac.tar.bz2 |
Merge pull request #56 from raphink/git_update_origin
Update origin if necessary before checking revision
This looks good. Thanks!
-rw-r--r-- | lib/puppet/provider/vcsrepo/git.rb | 11 | ||||
-rw-r--r-- | spec/unit/puppet/provider/vcsrepo/git_spec.rb | 17 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index 6920c75..ad69f7d 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -93,8 +93,18 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) working_copy_exists? || bare_exists? end + def update_remote_origin_url + current = git_with_identity('config', 'remote.origin.url') + unless @resource.value(:source).nil? + if current.nil? or current.strip != @resource.value(:source) + git_with_identity('config', 'remote.origin.url', @resource.value(:source)) + end + end + end + def update_references at_path do + update_remote_origin_url git_with_identity('fetch', @resource.value(:remote)) git_with_identity('fetch', '--tags', @resource.value(:remote)) update_owner_and_excludes @@ -251,6 +261,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) create end at_path do + update_remote_origin_url git_with_identity('fetch', @resource.value(:remote)) git_with_identity('fetch', '--tags', @resource.value(:remote)) end diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 83dbff2..4e4d9f3 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -127,6 +127,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "when its SHA is not different than the current SHA" do it "should return the ref" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('fetch', 'origin') # FIXME provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') @@ -137,6 +138,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "when its SHA is different than the current SHA" do it "should return the current SHA" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('fetch', 'origin') # FIXME provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha') @@ -144,6 +146,20 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.revision.should == 'currentsha' end end + + context "when the source is modified" do + resource_with :source => 'git://git@foo.com/bar.git' do + it "should update the origin url" do + provider.expects(:git).with('config', 'remote.origin.url').returns('old') + provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git') + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') + provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') + provider.expects(:git).with('tag', '-l').returns("Hello") + provider.revision.should == resource.value(:revision) + end + end + end end end @@ -189,6 +205,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "updating references" do it "should use 'git fetch --tags'" do expects_chdir + provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('fetch', 'origin') provider.expects(:git).with('fetch', '--tags', 'origin') provider.update_references |