Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Grit clone example
# Since Git is well structured, Grit uses a method missing (Grit::Git#method_missing) to 'systematically' execute Git commands:
require 'grit'
include Grit
gritty = Grit::Git.new('/tmp/filling-in')
gritty.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s'}, "git://github.com/cookbooks/cc-aws.git", "/tmp/cc-aws2")
# => "Initialized empty Git repository in /tmp/cc-aws2/.git/\n"
Dir.entries('/tmp/cc-aws2').size
# => 10
@jfoshee

This comment has been minimized.

Show comment Hide comment
@jfoshee

jfoshee May 8, 2011

Trying the above, I get the following error:

eError: can't convert nil into String
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:290:in `spawn'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:290:in `spawn'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:271:in `popen4'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:97:in `exec!'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:68:in `initialize'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git.rb:301:in `new'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git.rb:301:in `native'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git.rb:325:in `method_missing'
     from (irb):10
     from C:/Ruby192/bin/irb:12:in `<main>'

jfoshee commented May 8, 2011

Trying the above, I get the following error:

eError: can't convert nil into String
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:290:in `spawn'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:290:in `spawn'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:271:in `popen4'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:97:in `exec!'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/process.rb:68:in `initialize'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git.rb:301:in `new'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git.rb:301:in `native'
     from C:/Ruby192/lib/ruby/gems/1.9.1/gems/grit-2.4.1/lib/grit/git.rb:325:in `method_missing'
     from (irb):10
     from C:/Ruby192/bin/irb:12:in `<main>'
@hedgehog

This comment has been minimized.

Show comment Hide comment
@hedgehog

hedgehog May 8, 2011

Sorry, that repo you are pointing at: git://github.com/cookbooks/cc-aws.git
no longer exists.

try:
gritty.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s'}, "git://github.com/cookbooks/aws.git", "/tmp/aws2")

HTH?

PS Just in case there is a misunderstanding, this gist is to illustrate Grit usage not Chef or cookbooks access.

hedgehog commented May 8, 2011

Sorry, that repo you are pointing at: git://github.com/cookbooks/cc-aws.git
no longer exists.

try:
gritty.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s'}, "git://github.com/cookbooks/aws.git", "/tmp/aws2")

HTH?

PS Just in case there is a misunderstanding, this gist is to illustrate Grit usage not Chef or cookbooks access.

@rtacconi

This comment has been minimized.

Show comment Hide comment
@rtacconi

rtacconi Jan 22, 2013

is it possible to clone a private repository?

is it possible to clone a private repository?

@RyanScottLewis

This comment has been minimized.

Show comment Hide comment
@RyanScottLewis

RyanScottLewis Mar 19, 2013

I believe that this is simply a "magic" interface to standard git commands, so:

gritty.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s'}, "git://github.com/cookbooks/cc-aws.git", "/tmp/cc-aws2")

equates to the git command line:

git clone -v --progress -b 37s git://github.com/cookbooks/cc-aws.git /tmp/cc-aws2

So, if your git user is authenticated to clone from that repo, then you should be able to with the Ruby snippet just as if you were running the command line.

I believe that this is simply a "magic" interface to standard git commands, so:

gritty.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s'}, "git://github.com/cookbooks/cc-aws.git", "/tmp/cc-aws2")

equates to the git command line:

git clone -v --progress -b 37s git://github.com/cookbooks/cc-aws.git /tmp/cc-aws2

So, if your git user is authenticated to clone from that repo, then you should be able to with the Ruby snippet just as if you were running the command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment