Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef will not checkout development branch from git

Tags:

git

chef-infra

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
like image 281
Tampa Avatar asked Apr 03 '12 14:04

Tampa


People also ask

How do I make checkout to a new branch?

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.

What Cannot be done with git checkout?

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.

How do I checkout a branch in git using Visual Studio?

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> .


1 Answers

Your development branch gets deployed. It is only named deploy because chef checks out into a local branch instead of a detached HEAD.

The git provider

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

Documentation

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

like image 100
fooforge Avatar answered Oct 02 '22 13:10

fooforge