summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-05-11 09:42:32 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-05-11 09:42:32 -0700
commit6dddf1bdb8677aa1e04e5eac8c5d56fe06687c0d (patch)
tree69d4e77161af2ed5c6cf6d4a3bf4948a3f34d1ef
parent6fe31094c894780116d8438c040e04632d9d01c0 (diff)
parentd14f5b6fe98179ce517e0d1ffd7bd3156e200444 (diff)
downloadchef-6dddf1bdb8677aa1e04e5eac8c5d56fe06687c0d.tar.gz
Merge pull request #4898 from joshburt/jb_git_new_resource_destination_to_cwd
Update usage of @new_resource.destination to `cwd` within the git hwrp
-rw-r--r--lib/chef/provider/git.rb27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index 9516011c3f..004e0b550d 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -25,8 +25,11 @@ class Chef
class Provider
class Git < Chef::Provider
+ extend Forwardable
provides :git
+ def_delegator :@new_resource, :destination, :cwd
+
def whyrun_supported?
true
end
@@ -42,11 +45,11 @@ class Chef
def define_resource_requirements
# Parent directory of the target must exist.
requirements.assert(:checkout, :sync) do |a|
- dirname = ::File.dirname(@new_resource.destination)
+ dirname = ::File.dirname(cwd)
a.assertion { ::File.directory?(dirname) }
a.whyrun("Directory #{dirname} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.")
a.failure_message(Chef::Exceptions::MissingParentDirectory,
- "Cannot clone #{@new_resource} to #{@new_resource.destination}, the enclosing directory #{dirname} does not exist")
+ "Cannot clone #{@new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
end
requirements.assert(:all_actions) do |a|
@@ -79,14 +82,14 @@ class Chef
enable_submodules
add_remotes
else
- Chef::Log.debug "#{@new_resource} checkout destination #{@new_resource.destination} already exists or is a non-empty directory"
+ Chef::Log.debug "#{@new_resource} checkout destination #{cwd} already exists or is a non-empty directory"
end
end
def action_export
action_checkout
- converge_by("complete the export by removing #{@new_resource.destination}.git after checkout") do
- FileUtils.rm_rf(::File.join(@new_resource.destination, ".git"))
+ converge_by("complete the export by removing #{cwd}.git after checkout") do
+ FileUtils.rm_rf(::File.join(cwd, ".git"))
end
end
@@ -109,11 +112,11 @@ class Chef
end
def existing_git_clone?
- ::File.exist?(::File.join(@new_resource.destination, ".git"))
+ ::File.exist?(::File.join(cwd, ".git"))
end
def target_dir_non_existent_or_empty?
- !::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination).sort == [".", ".."]
+ !::File.exist?(cwd) || Dir.entries(cwd).sort == [".", ".."]
end
def find_current_revision
@@ -137,7 +140,7 @@ class Chef
end
def clone
- converge_by("clone from #{@new_resource.repository} into #{@new_resource.destination}") do
+ converge_by("clone from #{@new_resource.repository} into #{cwd}") do
remote = @new_resource.remote
clone_cmd = ["clone"]
@@ -145,9 +148,9 @@ class Chef
clone_cmd << "--depth #{@new_resource.depth}" if @new_resource.depth
clone_cmd << "--no-single-branch" if @new_resource.depth && git_minor_version >= Gem::Version.new("1.7.10")
clone_cmd << "\"#{@new_resource.repository}\""
- clone_cmd << "\"#{@new_resource.destination}\""
+ clone_cmd << "\"#{cwd}\""
- Chef::Log.info "#{@new_resource} cloning repo #{@new_resource.repository} to #{@new_resource.destination}"
+ Chef::Log.info "#{@new_resource} cloning repo #{@new_resource.repository} to #{cwd}"
git clone_cmd
end
end
@@ -311,10 +314,6 @@ class Chef
run_opts
end
- def cwd
- @new_resource.destination
- end
-
def git(*args, **run_opts)
git_command = ["git", args].compact.join(" ")
Chef::Log.debug "running #{git_command}"