Below is my code for checking out my repo. I want the development branch in my chef dev environment.
git "/home/ubuntu/workspace/repo" do
repository "[email protected]:me/repo.git"
revision "development"
action :sync
user "root"
end
when I look at the checkout branch I get:
* deploy
master
if I run git checkout development on the box I get:
deploy
* development
master
So....how do I get git to checkout my dev branch from chef?
I am using the example from the chef wiki. chef wiki git example
if node.chef_environment == "QA"
branch_name = "staging"
else
branch_name = "master"
end
git "/home/user/deployment" do
repository "[email protected]:gitsite/deployment.git"
revision branch_name
action :sync
user "user"
group "test"
end
The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.
The git checkout command operates upon three different entities which are files, commits, and branches. Sometimes this command can be dangerous because there is no undo option available on this command.
Create a new branch in Visual Studio 2019 You can choose an existing local or remote branch as the base. The Checkout branch checkbox automatically switches you to the newly created branch. The equivalent command for this action is git checkout -b <new-branch><existing-branch> .
Your development branch gets deployed. It is only named deploy
because chef checks out into a local branch instead of a detached HEAD.
Here's an excerpt from the actual code:
#File: chef-0.10.8/lib/chef/provider/git.rb
def checkout
sha_ref = target_revision
# 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}"
end
You'd also see an info messages within your chef client's log from which the deployed branch can be seen:
[Sun, 01 Jul 2012 18:07:40 +0200] INFO: git[/usr/local/rbenv] checked out branch: master reference: 6778c8e905d774d4dc70724c455e6fcff4c1d3e1
Also, the link to the docs in your question clearly says:
Keep in mind that if you use the command "git status" after running this recipe it will return the branch name as "deploy" regardless, as this is a default value. You should be able to see it checking out the correct branch when you run chef-client with debugging on:
sudo chef-client -l debug
More information on a detached HEAD state can be found e.g. at AlBlue's blog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With