如何使用ruby-git遞歸克隆遠程回購?如何使用ruby-git遞歸克隆遠程回購?
我用這個代碼:
require "git"
Git.clone "git://github.com/user/repo.git", "/tmp/repo"
但這並不遞歸克隆從GitHub回購。
我需要一個模擬爲:
$ git clone git://github.com/user/repo.git /tmp/repo --recursive
如何使用ruby-git遞歸克隆遠程回購?如何使用ruby-git遞歸克隆遠程回購?
我用這個代碼:
require "git"
Git.clone "git://github.com/user/repo.git", "/tmp/repo"
但這並不遞歸克隆從GitHub回購。
我需要一個模擬爲:
$ git clone git://github.com/user/repo.git /tmp/repo --recursive
在紅寶石的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
你最好叉紅寶石在這裏插入幾行文字。它會解決你的問題,世界會說「謝謝你」。
有時最簡單的路徑是讓應用程序自己做。爲什麼不使用?
`git clone git://github.com/user/repo.git /tmp/repo --recursive`
這是首先想到的,但由於我的程序充滿了正確的代碼(在我看來),我決定繼續以正確的方式,而不是使用exec/system。 –
去「正確的方式」?如何使用可用的工具是錯誤的,特別是當你想要做的事情沒有「正確」的方式時?代碼經常使用'exec'和'system';如果那些「錯誤」,他們將無法使用。 –
謝謝你,我也跟着你的建議,並添加到現有的圖書館我拉請求(https://github.com/schacon/ruby-git/pull/58) –