From b73e622178a1dbf4e15d3046439a374c69e0daaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Tue, 27 Jan 2015 18:15:59 +0100 Subject: [PATCH] =?UTF-8?q?(na=C3=AFvely)=20replace=20git=20clone=20execs?= =?UTF-8?q?=20with=20vcsrepo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifests/install.pp | 17 ++++++----------- manifests/plugin.pp | 25 +++++-------------------- spec/defines/rbenv__install_spec.rb | 4 ++-- spec/defines/rbenv__plugin_spec.rb | 24 +++++------------------- 4 files changed, 18 insertions(+), 52 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 6454ede..9e8bf5a 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -17,15 +17,10 @@ require rbenv::dependencies } - exec { "rbenv::checkout ${user}": - command => "git clone https://github.com/sstephenson/rbenv.git ${root_path}", - user => $user, - group => $group, - creates => $root_path, - path => ['/bin', '/usr/bin', '/usr/sbin'], - timeout => 100, - cwd => $home_path, - require => Package['git'], + vcsrepo { $root_path: + source => 'https://github.com/sstephenson/rbenv.git', + owern => $user, + group => $group, } file { "rbenv::rbenvrc ${user}": @@ -33,7 +28,7 @@ owner => $user, group => $group, content => template('rbenv/dot.rbenvrc.erb'), - require => Exec["rbenv::checkout ${user}"], + require => Vcsrepo[$root_path], } exec { "rbenv::shrc ${user}": @@ -50,6 +45,6 @@ owner => $user, group => $group, path => "${root_path}/cache", - require => Exec["rbenv::checkout ${user}"] + require => Vcsrepo[$root_path] } } diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 31ddc2e..5d90ada 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -23,30 +23,15 @@ path => $plugins, owner => $user, group => $group, - require => Exec["rbenv::checkout ${user}"], + require => Vcsrepo[$root_path], } } - exec { "rbenv::plugin::checkout ${user} ${plugin_name}": - command => "git clone ${source} ${destination}", - user => $user, + vcsrepo { $destination: + ensure => latest, + source => $source, + owner => $user, group => $group, - creates => $destination, - path => ['/bin', '/usr/bin', '/usr/sbin'], - timeout => $timeout, - cwd => $home_path, require => File["rbenv::plugins ${user}"], } - - exec { "rbenv::plugin::update ${user} ${plugin_name}": - command => 'git pull', - user => $user, - group => $group, - path => ['/bin', '/usr/bin', '/usr/sbin'], - timeout => $timeout, - cwd => $destination, - require => Exec["rbenv::plugin::checkout ${user} ${plugin_name}"], - onlyif => 'git remote update; if [ "$(git rev-parse @{0})" = "$(git rev-parse @{u})" ]; then return 0; else return 1; fi ]', - } - } diff --git a/spec/defines/rbenv__install_spec.rb b/spec/defines/rbenv__install_spec.rb index 0bc5917..d327752 100644 --- a/spec/defines/rbenv__install_spec.rb +++ b/spec/defines/rbenv__install_spec.rb @@ -7,8 +7,8 @@ context 'install rbenv' do it "clones rbenv from the official repository" do - should contain_exec("rbenv::checkout #{user}"). - with_command("git clone https://github.com/sstephenson/rbenv.git /home/#{user}/.rbenv") + should contain_vcsrepo(" /home/#{user}/.rbenv"). + with_source("https://github.com/sstephenson/rbenv.git") end it "appends in a rc file, a command to include .rbenv/bin folder in PATH env variable" do diff --git a/spec/defines/rbenv__plugin_spec.rb b/spec/defines/rbenv__plugin_spec.rb index 20181af..27a0d5f 100644 --- a/spec/defines/rbenv__plugin_spec.rb +++ b/spec/defines/rbenv__plugin_spec.rb @@ -10,26 +10,12 @@ let(:target_path) { "#{dot_rbenv}/plugins/#{plugin_name}" } - it 'clones repository to the right path' do - should contain_exec("rbenv::plugin::checkout #{user} #{plugin_name}").with( - :command => "git clone #{source} #{target_path}", - :user => user, - :creates => target_path, + it 'clones repository to the right path (in the latest version)' do + should contain_vcsrepo(target_path).with( + :source => source, + :ensure => :latest, + :owner => user, :require => /rbenv::plugins #{user}/, - :path => ['/bin','/usr/bin','/usr/sbin'] - ) - end - - it 'pulls the latest plugin changes from their git repos' do - should contain_exec("rbenv::plugin::update #{user} #{plugin_name}").with( - :command => 'git pull', - :user => user, - :cwd => target_path, - :require => /rbenv::plugin::checkout #{user} #{plugin_name}/, - :path => ['/bin','/usr/bin','/usr/sbin'], - :onlyif => 'git remote update; ' \ - 'if [ "$(git rev-parse @{0})" = "$(git rev-parse @{u})" ]; ' \ - 'then return 0; else return 1; fi ]' ) end