I'm looking for some code examples, for either rugged or grit, showing how to do a git push
.
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:
git describe --abbrev=0
)git push staging v1.00
)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.
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:
repo.git.remote({},'add','RemoteRepoName','https://github.com//.git')
pusher = repo.git.push({:process_info => true, :progress => true}, 'RemoteRepoName', 'master')