I'm writing a Puppet module which manages the branch or tag that is currently checked out on a local Git repository. I'd basically like to enable users to specify which version of a repository they'd like checked out. This could be master
(a branch) or v3.6.2
(a tag).
Here's what I've got so far:
exec { 'gitolite_select_version':
command => "git checkout ${actual_version}",
cwd => '/usr/src/gitolite',
path => '/bin:/usr/bin',
unless => "test \"$(git describe --contains --all HEAD)\" == ${actual_version}""
}
This works fine on branches like master
, but gives bad output when on a detached HEAD like a tag. Example on master
$ git describe --contains --all HEAD
master
Example on tag:
$ git describe --contains --all HEAD
tags/v3.6.2^0
Is there a Git command which will get me the branch name or current tag in a simple, unified format?