Sergey Blohin
Sergey Blohin

Reputation: 620

How I can use ruby-git to recursively clone a remote repo?

How can I use ruby-git to recursively clone a remote repo?

I use this code:

require "git"
Git.clone "git://github.com/user/repo.git", "/tmp/repo"

but this does not recursively clone the repo from GitHub.

I need an analog for:

$ git clone git://github.com/user/repo.git /tmp/repo --recursive

Upvotes: 2

Views: 2049

Answers (2)

the Tin Man
the Tin Man

Reputation: 160551

Sometimes the simplest path is to let the app do it itself. Why not use?

`git clone git://github.com/user/repo.git /tmp/repo --recursive`

Upvotes: 1

Daniel Vartanov
Daniel Vartanov

Reputation: 3267

Implementation of the #clone method in ruby-git tells us that it is currently impossible:

https://github.com/schacon/ruby-git/blob/master/lib/git/lib.rb#L44

def clone(repository, name, opts = {})
  @path = opts[:path] || '.'
  clone_dir = opts[:path] ? File.join(@path, name) : name

  arr_opts = []
  arr_opts << "--bare" if opts[:bare]
  arr_opts << "-o" << opts[:remote] if opts[:remote]
  arr_opts << "--depth" << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0

  arr_opts << '--'
  arr_opts << repository
  arr_opts << clone_dir

  command('clone', arr_opts)

  opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir}
end

You better fork ruby-git and insert a couple of lines there. It will solve your problem and the world will say "thank you".

Upvotes: 4

Related Questions