2

I am using puppet to clone a repo on an agent node. My site.pp contains

node foobar{
   vcsrepo{"home/user1/gitrepo1":
     provider=>git, 
     source=>"https://github.com/foobar/foo.git",
     revision => "remotes/origin/bar",
   }   
}

On the agent when I do git branch after the catalog has been applied, it shows

*(no branch)
master

When I do git branch -a it shows

master
remotes/origin/HEAD -> origin/master  
remotes/origin/bar

I want to be able to checkout the remote "bar" branch. Only specifying the revision=>bar gives the following error. The documentation is not too clear on this either.

err: /Stage[main]//Node[foobar]/Vcsrepo[/home/user1/gitrepo1]: Could not evaluate: Execution of '/usr/bin/git rev-parse bar' returned 128: fatal: ambiguous argument 'bar': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
bar

EDIT: There was a typo in what I had initially posted. I had in fact specified revision=>bar in my site.pp

Thank you.

Spart
  • 69
  • 1
  • 2
  • 7
  • What happens if you clone the repository on the command line and manually run `git checkout bar`? – larsks Aug 06 '13 at 15:13
  • This works fine. It just says switched to new branch "bar". I was wondering if there was way to this using vcsrepo only. It seems it would be best to clone the repo using vcsrepo, and then do exec{'checkout': command=>"git checkout -b bar origin/bar" } to checkout the branch. – Spart Aug 06 '13 at 18:00

1 Answers1

1

The branch can be specified with 'revision' (can be a commit SHA, tag or branch name):

vcsrepo { "/path/to/repo":
    ensure => present,
    provider => git,
    source => 'git://example.com/repo.git',
    revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31'
}

vcsrepo { "/path/to/repo":
    ensure => present,
    provider => git,
    source => 'git://example.com/repo.git',
    revision => '1.1.2rc1'
}

vcsrepo { "/path/to/repo":
    ensure => present,
    provider => git,
    source => 'git://example.com/repo.git',
    revision => 'development'
}

https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/master/README.GIT.markdown

Chris Montanaro
  • 808
  • 1
  • 7
  • 8
  • I had a typo in my initial posting. I was in fact using the revision attribute. In my case the 'development' branch is a remote branch, and I want to do a checkout. Doing a revision=>'foo' is giving me an error ambiguous argument 'foo': unknown revision or path not in the working tree. – Spart Aug 06 '13 at 15:58
  • What happens if you change 'revision => "remotes/origin/bar"' to 'revision => "bar"'? – Chris Montanaro Aug 06 '13 at 16:51
  • err: /Stage[main]//Node[foobar]/Vcsrepo[/home/user1/gitrepo1]: Could not evaluate: Execution of '/usr/bin/git rev-parse savi-1.1' returned 128: fatal: ambiguous argument 'bar': unknown revision or path not in the working tree. Use '--' to separate paths from revisions bar – Spart Aug 06 '13 at 18:06
  • It seems it would be best to clone the repo using vcsrepo, and then do exec{'checkout': command=>"git checkout -b bar origin/bar" } to checkout the branch. – Spart Aug 06 '13 at 18:07