Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of a git push using either rugged or grit

Tags:

rugged

grit

I'm looking for some code examples, for either rugged or grit, showing how to do a git push.

Background

I have rake tasks deploy:staging and deploy:production that I use to deploy my app.

I'm deploying to heroku, so these tasks essentially do the following:

  1. Get the most recent tag (eg. git describe --abbrev=0)
  2. Push the version represented by that tag to the specified remote (eg. git push staging v1.00)
  3. Store the version in a heroku config var (eg. heroku config:add APP_VERSION=v1.00)

(There's also some checks in there to make sure I haven't forgotten to create a new tag before pushing etc.)

Initially I was using system calls from my Rakefile for these CLI commands; then I moved to using the git and heroku-api gems.

The git gem appears to be abandoned however (no commits in the past year); it seems that Grit and rugged are now the standard gems for working with Git.

Unfortunately, given the lack of documentation, I can't figure out how to do a git push with either of these libraries.

(In the following examples, assume that the remote/branch I'm pushing to is origin/master, and is already setup as a remote in the local repo)

Starting with rugged:

$ irb
2.0.0-p0 :001 > require 'rugged'
 => true 
2.0.0-p0 :002 > repo = Rugged::Repository.new('/path/to/repo')
 => #<Rugged::Repository:0x007fe8b48821c0 @encoding=#<Encoding:UTF-8>> 
2.0.0-p0 :003 > remote = Rugged::Remote.lookup(repo, 'origin')
 NoMethodError: undefined method `lookup' for Rugged::Remote:Class

Now for grit:

$ irb
2.0.0-p0 :001 > require 'grit'
 => true 
2.0.0-p0 :002 > repo = Grit::Repo.new('/path/to/repo')
 => #<Grit::Repo "/path/to/repo/.git"> 
2.0.0-p0 :004 > remote = repo.remotes.last
 => #<Grit::Remote "origin/master"> 
2.0.0-p0 :005 > repo.git.push(remote)
NoMethodError: undefined method `delete' for #<Grit::Remote "origin/master">

Any help would be greatly appreciated.

like image 240
Scott Avatar asked Mar 01 '13 05:03

Scott


1 Answers

Ok, I think I figured it out, BUT now It's asking me for my gitHub credentials and I can't type my credentials because I receive a 'Timeout' error.

This is what I did:

Add the remote repo to the project:

repo.git.remote({},'add','RemoteRepoName','https://github.com//.git')

Push to github

pusher = repo.git.push({:process_info => true, :progress => true}, 'RemoteRepoName', 'master')

like image 148
mcKain Avatar answered Sep 29 '22 20:09

mcKain