diff options
author | Joshua C. Burt <joshburt@shapeandshare.com> | 2016-04-29 08:23:41 -0600 |
---|---|---|
committer | Joshua C. Burt <joshburt@shapeandshare.com> | 2016-04-29 08:23:41 -0600 |
commit | 51cac6df6838ae4fe8d0981da2093e632d49d5f9 (patch) | |
tree | f98438acb255ff9ca92182246d5759b2b508bafd | |
parent | ff75709d5dcc583f609a2ce4facefc88f23d1650 (diff) | |
download | chef-51cac6df6838ae4fe8d0981da2093e632d49d5f9.tar.gz |
refactored to take advantage of (*) splat, and (**) double splat for git arguments
-rw-r--r-- | lib/chef/provider/git.rb | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index 3f26879b91..9516011c3f 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -120,7 +120,7 @@ class Chef Chef::Log.debug("#{@new_resource} finding current git revision") if ::File.exist?(::File.join(cwd, ".git")) # 128 is returned when we're not in a git repo. this is fine - result = git(["rev-parse", "HEAD"], { cwd: cwd, returns: [0, 128] }).stdout.strip + result = git("rev-parse", "HEAD", cwd: cwd, returns: [0, 128]).stdout.strip end sha_hash?(result) ? result : nil end @@ -157,8 +157,8 @@ class Chef converge_by("checkout ref #{sha_ref} branch #{@new_resource.revision}") do # checkout into a local branch rather than a detached HEAD - git(["branch", "-f", @new_resource.checkout_branch, sha_ref], { cwd: cwd }) - git(["checkout", @new_resource.checkout_branch], { cwd: cwd }) + git("branch", "-f", @new_resource.checkout_branch, sha_ref, cwd: cwd) + git("checkout", @new_resource.checkout_branch, cwd: cwd) Chef::Log.info "#{@new_resource} checked out branch: #{@new_resource.revision} onto: #{@new_resource.checkout_branch} reference: #{sha_ref}" end end @@ -167,10 +167,10 @@ class Chef if @new_resource.enable_submodules converge_by("enable git submodules for #{@new_resource}") do Chef::Log.info "#{@new_resource} synchronizing git submodules" - git(%w{submodule sync}, { cwd: cwd }) + git("submodule", "sync", cwd: cwd) Chef::Log.info "#{@new_resource} enabling git submodules" # the --recursive flag means we require git 1.6.5+ now, see CHEF-1827 - git(["submodule", "update", "--init", "--recursive"], { cwd: cwd }) + git("submodule", "update", "--init", "--recursive", cwd: cwd) end end end @@ -180,9 +180,9 @@ class Chef converge_by("fetch updates for #{@new_resource.remote}") do # since we're in a local branch already, just reset to specified revision rather than merge Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}" - git(["fetch", @new_resource.remote], { cwd: cwd }) - git(["fetch", @new_resource.remote, "--tags"], { cwd: cwd }) - git(["reset", "--hard", target_revision], { cwd: cwd }) + git("fetch", @new_resource.remote, cwd: cwd) + git("fetch", @new_resource.remote, "--tags", cwd: cwd) + git("reset", "--hard", target_revision, cwd: cwd) end end @@ -190,7 +190,7 @@ class Chef converge_by("set up remote tracking branches for #{remote_url} at #{remote_name}") do Chef::Log.debug "#{@new_resource} configuring remote tracking branches for repository #{remote_url} " + "at remote #{remote_name}" check_remote_command = ["config", "--get", "remote.#{remote_name}.url"] - remote_status = git(check_remote_command, { cwd: cwd, returns: [0, 1, 2] }) + remote_status = git(check_remote_command, cwd: cwd, returns: [0, 1, 2]) case remote_status.exitstatus when 0, 2 # * Status 0 means that we already have a remote with this name, so we should update the url @@ -199,10 +199,10 @@ class Chef # which we can fix by replacing them all with our target url (hence the --replace-all option) if multiple_remotes?(remote_status) || !remote_matches?(remote_url, remote_status) - git(["config", "--replace-all", "remote.#{remote_name}.url", remote_url], { cwd: cwd }) + git("config", "--replace-all", "remote.#{remote_name}.url", remote_url, cwd: cwd) end when 1 - git(["remote", "add", remote_name, remote_url], { cwd: cwd }) + git("remote", "add", remote_name, remote_url, cwd: cwd) end end end @@ -279,7 +279,7 @@ class Chef end def git_ls_remote(rev_pattern) - git(["ls-remote", "\"#{@new_resource.repository}\"", "\"#{rev_pattern}\""]).stdout + git("ls-remote", "\"#{@new_resource.repository}\"", "\"#{rev_pattern}\"").stdout end def refs_search(refs, pattern) @@ -315,8 +315,8 @@ class Chef @new_resource.destination end - def git(args, run_opts = {}) - git_command = ["git", *args].compact.join(" ") + def git(*args, **run_opts) + git_command = ["git", args].compact.join(" ") Chef::Log.debug "running #{git_command}" shell_out!(git_command, run_options(run_opts)) end |