Git
库将2>&1
添加到所有命令。所以你的克隆命令最终被执行如下:
git clone ... 2>&1
哪个结束抑制所有输出。您只需要在Git::Lib
中覆盖一个名为run_command
的方法,然后删除那个2>&1
。你可以在irb
试试这个:
class Git::Lib
class << self
attr_accessor :verbose
end
def run_command(git_cmd, &block)
git_cmd = git_cmd.gsub("2>&1", "").chomp if self.class.verbose
if block_given?
IO.popen(git_cmd, &block)
else
`#{git_cmd}`.chomp
end
end
end
我定义了一个额外的属性verbose
。因此,只要您需要实际的git输出,只需设置Git::Lib.verbose = true
并运行Git.clone
或任何其他命令,实际输出将被打印。
这将完成,一旦你设置Git::Lib.verbose = true
然后调用Git.clone
,它会显示git的进度条是这样的:
Cloning into 'rapidftr-addon-cpims'...
remote: Counting objects: 207, done.
remote: Compressing objects: 100% (108/108), done.
remote: Total 207 (delta 95), reused 201 (delta 90)
Receiving objects: 50% (105/207), 83.10 KiB | 112 KiB/s...
# ^^ The above line is git's progress bar, it will keep updating
它可能不会显示在您所期望的特定格式的进度条,但它会在下载过程中显示动态更新。
编辑:新增样本输出
嗯,好了,所以忘了,如果我使用Ruby-git的宝石和我正常使用'混帐混帐克隆:// github.com/ankit8898/rubymotion-inspect.git'。我怎样才能找到克隆的进度条。我的主要目标是通过使用ruby-git gem或简单的git clone来捕获进度条。 – AnkitG 2013-05-19 18:27:58
尝试阅读并解释此shell命令的输出。也许你会很幸运。 – 2013-05-19 18:29:54
好吧,那是一个备份计划。 :)但仍然没有任何其他方式来使用git clone和progressbar gem。因为我有兴趣看到使用git clone的实际进度条。 – AnkitG 2013-05-20 06:55:06