Reputation: 5223
I want to write a ruby script that is a command line tool that takes a tag ID as a parameter and then runs the equivalent of "git checkout tag_id". I would then use rsync to push the checked out directory to servers. I've looked at the rugged gem and the git gem, but they seem to interact with git in a way that isn't intuitive in doing something like this. Should I just use the system call or is there a more ruby way to do what I'm trying to do?
I have /User/git_repo cloned from say [email protected]/company/this_repo.git. Manually I would "git fetch --tags" and then "git checkout tag_id". I would want to then rsync the result over to the servers.
Upvotes: 2
Views: 901
Reputation: 25697
There's the ruby-git gem - install it with $ gem install git
. It handles the system command line calls - here's an example for Ruby >= 1.9:
require 'git'
g = Git.init
Git.init('project')
Git.init('/home/schacon/proj',
{ :repository => '/opt/git/proj.git',
:index => '/tmp/index'} )
g.fetch
g.checkout('tag_id')
You can get an array of tags from g.tags
. I'd use this over writing my own system calls, as this repo seems to be currently maintained (last commit two days ago).
Upvotes: 3