Strange git behavior - any suggestion is welcome

Hi

I use this resource to check out my private git project onto to an ec2
instance.

role = ENV[‘TARGET_ROLE’]

git “/home/zeeting/apps/docverter” do
repository "git@github.com:acme/project.git"
revision role == “uat” ? “dev” : "master"
action :sync
end

However when I log in to the box and check the branch, it prints this:

$ git branch

  • deploy

    dev

I don’t understand why the branch is set to deploy. It must be a locally
created branch because I do not even have a branch called deploy.

I am expecting the branch to be either ‘dev’ or ‘master’

What can cause this behaviour?

Thanks, Tony

Tony,

This is the default behavior for the git resource. If you take a look at the docs, you’ll see the checkout_branch attribute, whose description reads: “Use to specify the name of a branch to be checked out. Default value: deploy.”

So, instead of using the revision attribute, you may, instead, want to specify the checkout_branch attribute.

What is happening right now is that it’s checking out a branch called deploy from the revision you’ve set, but that’s a bit confusing, based on what you’re expecting to see.


Jeff Byrnes
@thejeffbyrnes
Lead DevOps Engineer
EverTrue
704.516.4628

On March 16, 2015 at 3:05:20 AM, Anthony Kong (anthony.hw.kong@gmail.com) wrote:

Hi

I use this resource to check out my private git project onto to an ec2 instance.

role = ENV[‘TARGET_ROLE’]

git “/home/zeeting/apps/docverter” do
repository "git@github.com:acme/project.git"
revision role == “uat” ? “dev” : "master"
action :sync
end

However when I log in to the box and check the branch, it prints this:

$ git branch

  • deploy

    dev

I don’t understand why the branch is set to deploy. It must be a locally created branch because I do not even have a branch called deploy.

I am expecting the branch to be either ‘dev’ or ‘master’

What can cause this behaviour?

Thanks, Tony

On Monday, March 16, 2015 at 5:49 AM, Jeff Byrnes wrote:

Tony,

This is the default behavior for the git resource. If you take a look at the docs, you’ll see the checkout_branch attribute, whose description reads: “Use to specify the name of a branch to be checked out. Default value: deploy.”

So, instead of using the revision attribute, you may, instead, want to specify the checkout_branch attribute.

What is happening right now is that it’s checking out a branch called deploy from the revision you’ve set, but that’s a bit confusing, based on what you’re expecting to see.

-- Jeff Byrnes
Jeff is correct. The deploy resource does this because you may check out tags or pull from branches in a way that would normally cause a git error, for example if you force pushed to a branch. If you’re just pulling a git repo to a server, you don’t need to care about the deploy branch, since it will be forcibly set to the correct git rev based on the reference you specified (which you can verify for yourself with git log and git rev-parse and git ls-remote).

The checkout_branch feature is useful if you’e setting up developer laptops and you want to fetch all your git repos to a standard location and leave them on master.

--
Daniel DeLeo

Hi Jeff and Daniel,

Thanks very much for the answer!

According to an example on the resource_git page (reproduced here)

if node.chef_environment == "QA"
branch_name = "staging"else
branch_name = "master"end
git "/home/user/deployment" do
repository "git@github.com:gitsite/deployment.git"
revision branch_name
action :sync
user "user"
group "test"end

It seems to suggest revision can be used to specify a branch.

Now I switched to use checkout_branch, and I get this error:

==> default: [2015-03-17T00:09:53+00:00] ERROR: Converge failed with error
message git[/home/work/apps/project] (work::project line 19) had an error:
Mixlib::ShellOut::ShellC**ommandFailed: Expected process to exit with [0],
but received '128'

==> default: ---- Begin output of git branch -f master
6c97fdd97a814dc5db5523322d9b4b90196645bf ----

*==> default: STDOUT: *

==> default: STDERR: fatal: Cannot force update the current branch.

Is the 'sync' action not compatible to the checkout_branch?

Cheers

On Tue, Mar 17, 2015 at 3:12 AM, Daniel DeLeo dan@kallistec.com wrote:

On Monday, March 16, 2015 at 5:49 AM, Jeff Byrnes wrote:

Tony,

This is the default behavior for the git resource. If you take a look at
the docs, you’ll see the checkout_branch attribute, whose description
reads: “Use to specify the name of a branch to be checked out. Default
value: deploy.”

So, instead of using the revision attribute, you may, instead, want to
specify the checkout_branch attribute.

What is happening right now is that it’s checking out a branch called
deploy from the revision you’ve set, but that’s a bit confusing, based on
what you’re expecting to see.

-- Jeff Byrnes
Jeff is correct. The deploy resource does this because you may check out
tags or pull from branches in a way that would normally cause a git error,
for example if you force pushed to a branch. If you’re just pulling a git
repo to a server, you don’t need to care about the deploy branch, since it
will be forcibly set to the correct git rev based on the reference you
specified (which you can verify for yourself with git log and git rev-parse
and git ls-remote).

The checkout_branch feature is useful if you’e setting up developer
laptops and you want to fetch all your git repos to a standard location and
leave them on master.

--
Daniel DeLeo

On Monday, March 16, 2015 at 5:32 PM, Anthony Kong wrote:

Hi Jeff and Daniel,

Thanks very much for the answer!

According to an example on the resource_git page (reproduced here)

if node.chef_environment == "QA" branch_name = "staging" else branch_name = "master" end git "/home/user/deployment" do repository "git@github.com (mailto:git@github.com):gitsite/deployment.git" revision branch_name action :sync user "user" group "test" end

It seems to suggest revision can be used to specify a branch.

Now I switched to use checkout_branch, and I get this error:

==> default: [2015-03-17T00:09:53+00:00] ERROR: Converge failed with error message git[/home/work/apps/project] (work::project line 19) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '128'
==> default: ---- Begin output of git branch -f master 6c97fdd97a814dc5db5523322d9b4b90196645bf ----
==> default: STDOUT:
==> default: STDERR: fatal: Cannot force update the current branch.

Is the 'sync' action not compatible to the checkout_branch?

Cheers

I forgot you need to set enable_checkout false as well, or else you get the same behavior as before except the branch is named whatever you specified in checkout_branch rather than “deploy”

Again, this is really just a special case for setting up developer laptops, if the branch name doesn’t REALLY matter, then the default behavior is what you should be using.

HTH,

--
Daniel DeLeo