Skip to content

Instantly share code, notes, and snippets.

@cookbooks
Created December 7, 2010 05:24
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save cookbooks/731502 to your computer and use it in GitHub Desktop.
Save cookbooks/731502 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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
Copy link

is it possible to clone a private repository?

@RyanScottLewis
Copy link

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