Browse files

add enable_checkout attribute; add ability to override 'deploy' with …

…checkout_branch name
  • Loading branch information...
1 parent 4f3ae72 commit baf2031621bc8bf636defab13f261683b40b9ca8 @jgoulah committed Dec 28, 2012
Showing with 25 additions and 4 deletions.
  1. +7 −4 lib/chef/provider/git.rb
  2. +18 −0 lib/chef/resource/scm.rb
View
11 lib/chef/provider/git.rb
@@ -155,10 +155,13 @@ def clone
def checkout
sha_ref = target_revision
- converge_by("checkout ref #{sha_ref} branch #{@new_resource.revision}") do
- # checkout into a local branch rather than a detached HEAD
- shell_out!("git checkout -b deploy #{sha_ref}", run_options(:cwd => @new_resource.destination))
- Chef::Log.info "#{@new_resource} checked out branch: #{@new_resource.revision} reference: #{sha_ref}"
+
+ if @new_resource.enable_checkout
+ converge_by("checkout ref #{sha_ref} branch #{@new_resource.revision}") do
+ # checkout into a local branch rather than a detached HEAD
+ shell_out!("git checkout -b #{@new_resource.checkout_branch} #{sha_ref}", run_options(:cwd => @new_resource.destination))
+ Chef::Log.info "#{@new_resource} checked out branch: #{@new_resource.revision} onto: #{@new_resource.checkout_branch} reference: #{sha_ref}"
+ end
end
end
View
18 lib/chef/resource/scm.rb
@@ -32,12 +32,14 @@ def initialize(name, run_context=nil)
@destination = name
@resource_name = :scm
@enable_submodules = false
+ @enable_checkout = true
@revision = "HEAD"
@remote = "origin"
@ssh_wrapper = nil
@depth = nil
@allowed_actions.push(:checkout, :export, :sync, :diff, :log)
@action = [:sync]
+ @checkout_branch = "deploy"
end
def destination(arg=nil)
@@ -130,6 +132,14 @@ def enable_submodules(arg=nil)
)
end
+ def enable_checkout(arg=nil)
+ set_or_return(
+ :enable_checkout,
+ arg,
+ :kind_of => [TrueClass, FalseClass]
+ )
+ end
+
def remote(arg=nil)
set_or_return(
:remote,
@@ -146,6 +156,14 @@ def ssh_wrapper(arg=nil)
)
end
+ def checkout_branch(arg=nil)
+ set_or_return(
+ :checkout_branch,
+ arg,
+ :kind_of => String
+ )
+ end
+
end
end
end

0 comments on commit baf2031

Please sign in to comment.