Example of pressing git using solid or hard

I am looking for code examples for rugged or grit , showing how to do git push .

Background

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

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

  • Get the last tag (e.g. git describe --abbrev=0 )
  • Click the version represented by this tag on the specified remote (for example, git push staging v1.00 )
  • Save the version in the heroku var configurator (for example, heroku config:add APP_VERSION=v1.00 )

(There are also some checks there to make sure I remember to create a new tag before clicking, etc.)

Initially, I used the system calls from my Rakefile for these CLI commands; then I switched to using git and the api hero .

However, the git stone seems abandoned (no commitment for the last year); It seems that Grit and Durable are now the standard gems for working with Git.

Unfortunately, given the lack of documentation, I cannot figure out how to do git push with any of these libraries.

(In the following examples, suppose the remote / branch that I click on is the source / master and is already configured as remote in the local repo)

Since lasting:

 $ 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.

+7
source share
2 answers

Ok, I think I figured it out, but now he asks me for the gitHub credentials, and I canโ€™t enter my credentials because I get a "Timeout" error.

This is what I did:

Add remote repo to project:

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

Click on github

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

+1
source

Using grit repo.git.push actually calls Git #native using the method_missing method. His signature is as follows:

 def native(cmd, options = {}, *args, &block) 

so instead you want to do the following:

 repo.git.push({}, remote) 

Yes, itโ€™s foolish to introduce optional options at the beginning, but thatโ€™s exactly how it is written.

+1
source

All Articles