2

如何使用ruby​​-git递归克隆远程仓库?

我使用这段代码:

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

但这不会递归地从 GitHub 克隆 repo。

我需要一个模拟:

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

2 回答 2

4

ruby-git中方法的实现#clone告诉我们目前是不可能的:

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

你最好 fork ruby​​-git 并在那里插入几行。它会解决你的问题,全世界都会说“谢谢”。

于 2013-01-19T06:00:01.150 回答
1

有时最简单的方法是让应用程序自己做。为什么不使用?

`git clone git://github.com/user/repo.git /tmp/repo --recursive`
于 2013-01-19T07:07:09.033 回答