summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/git.rb19
-rw-r--r--spec/unit/provider/git_spec.rb140
2 files changed, 81 insertions, 78 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index 689366db6b..c12b752d25 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -27,7 +27,7 @@ class Chef
class Git < Chef::Provider
include Chef::Mixin::ShellOut
-
+
def whyrun_supported?
true
end
@@ -41,7 +41,7 @@ class Chef
end
def define_resource_requirements
- # Parent directory of the target must exist.
+ # Parent directory of the target must exist.
requirements.assert(:checkout, :sync) do |a|
dirname = ::File.dirname(@new_resource.destination)
a.assertion { ::File.directory?(dirname) }
@@ -61,16 +61,16 @@ class Chef
end
requirements.assert(:all_actions) do |a|
- # this can't be recovered from in why-run mode, because nothing that
- # we do in the course of a run is likely to create a valid target_revision
+ # this can't be recovered from in why-run mode, because nothing that
+ # we do in the course of a run is likely to create a valid target_revision
# if we can't resolve it up front.
a.assertion { target_revision != nil }
- a.failure_message Chef::Exceptions::UnresolvableGitReference,
+ a.failure_message Chef::Exceptions::UnresolvableGitReference,
"Unable to parse SHA reference for '#{@new_resource.revision}' in repository '#{@new_resource.repository}'. " +
- "Verify your (case-sensitive) repository URL and revision.\n" +
+ "Verify your (case-sensitive) repository URL and revision.\n" +
"`git ls-remote` output: #{@resolved_reference}"
end
- end
+ end
def action_checkout
if target_dir_non_existent_or_empty?
@@ -85,7 +85,7 @@ class Chef
def action_export
action_checkout
- converge_by("complete the export by removing #{@new_resource.destination}.git after checkout") do
+ converge_by("complete the export by removing #{@new_resource.destination}.git after checkout") do
FileUtils.rm_rf(::File.join(@new_resource.destination,".git"))
end
end
@@ -134,7 +134,7 @@ class Chef
end
end
- def clone
+ def clone
converge_by("clone from #{@new_resource.repository} into #{@new_resource.destination}") do
remote = @new_resource.remote
@@ -164,7 +164,6 @@ class Chef
Chef::Log.info "#{@new_resource} synchronizing git submodules"
command = "git submodule sync"
shell_out!(command, run_options(:cwd => @new_resource.destination))
-
Chef::Log.info "#{@new_resource} enabling git submodules"
# the --recursive flag means we require git 1.6.5+ now, see CHEF-1827
command = "git submodule update --init --recursive"
diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb
index 9215bbab43..1777ceb03e 100644
--- a/spec/unit/provider/git_spec.rb
+++ b/spec/unit/provider/git_spec.rb
@@ -301,78 +301,82 @@ SHAS
@provider.converge
end
- it "adds a new remote when one with this name hasn't been configured yet" do
- command_response = double('shell_out')
- command_response.stub(:exitstatus) { 1 }
- check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug,
- :returns => [0,1,2]).and_return(command_response)
- expected_command = "git remote add #{@resource.remote} #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(expected_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug)
- @provider.setup_remote_tracking_branches
- @provider.converge
+ describe "when a remote with a given name hasn't been configured yet" do
+ it "adds a new remote " do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 1 }
+ check_remote_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(check_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ expected_command = "git remote add #{@resource.remote} #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
+ @provider.setup_remote_tracking_branches
+ @provider.converge
+ end
end
- it "updates remote url when one with the same name exists and the url is different" do
- command_response = double('shell_out')
- command_response.stub(:exitstatus) { 0 }
- command_response.stub(:stdout) { "some_other_url" }
- check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug,
- :returns => [0,1,2]).and_return(command_response)
- expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(expected_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug)
- @provider.setup_remote_tracking_branches
- @provider.converge
- end
+ describe "when a remote with a given name has already been configured" do
+ it "updates remote url when the url is different" do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 0 }
+ command_response.stub(:stdout) { "some_other_url" }
+ check_remote_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(check_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
+ @provider.setup_remote_tracking_branches
+ @provider.converge
+ end
- it "doesn't update remote url when one with the same name exists and the url is the same" do
- command_response = double('shell_out')
- command_response.stub(:exitstatus) { 0 }
- command_response.stub(:stdout) { @resource.repository }
- check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug,
- :returns => [0,1,2]).and_return(command_response)
- unexpected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
- @provider.should_not_receive(:shell_out!).with(unexpected_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug)
- @provider.setup_remote_tracking_branches
- @provider.converge
- end
+ it "doesn't update remote url when the url is the same" do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 0 }
+ command_response.stub(:stdout) { @resource.repository }
+ check_remote_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(check_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ unexpected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
+ @provider.should_not_receive(:shell_out!).with(unexpected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
+ @provider.setup_remote_tracking_branches
+ @provider.converge
+ end
- it "resets remote url when it has multiple values" do
- command_response = double('shell_out')
- command_response.stub(:exitstatus) { 2 }
- check_remote_command = "git config --get remote.#{@resource.remote}.url"
- @provider.should_receive(:shell_out!).with(check_remote_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug,
- :returns => [0,1,2]).and_return(command_response)
- expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
- @provider.should_receive(:shell_out!).with(expected_command,
- :cwd => "/my/deploy/dir",
- :log_tag => "git[web2.0 app]",
- :log_level => :debug)
- @provider.setup_remote_tracking_branches
- @provider.converge
+ it "resets remote url when it has multiple values" do
+ command_response = double('shell_out')
+ command_response.stub(:exitstatus) { 2 }
+ check_remote_command = "git config --get remote.#{@resource.remote}.url"
+ @provider.should_receive(:shell_out!).with(check_remote_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug,
+ :returns => [0,1,2]).and_return(command_response)
+ expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}"
+ @provider.should_receive(:shell_out!).with(expected_command,
+ :cwd => "/my/deploy/dir",
+ :log_tag => "git[web2.0 app]",
+ :log_level => :debug)
+ @provider.setup_remote_tracking_branches
+ @provider.converge
+ end
end
it "accepts remote name and url as optional parameters" do