我很有信心地认为这要么是不可能的,要么我错过了一个明显的选项,但在查阅grit's Git class、链接到的这个SO post和其他grit标记的SO问题后,我一无所获。
我正在使用grit执行一系列rake任务来安装我的应用程序。其中一个任务克隆了几个存储库。
使用链接的gist中的代码作为示例,在grit中进行git克隆的输出如下(在irb、ruby 1.9.2中进行
我的问题是:我能否在克隆命令实际运行时恢复其余的标准输出?"Cloning into /tmp/aws...\n"是输出的第一行,只有当克隆完成时才返回。
第二个问题是:如果使用grit无法在克隆过程中恢复克隆进度,是否有其他方法可以显示命令在进行时的进度?我的担忧是我们的一些存储库非常大,我想给我的rakefile用户一些东西,这样他们就不会认为脚本只是在尝试与远程通信时挂起。
供参考,git clone命令的“正常”输出如下:
我正在使用grit执行一系列rake任务来安装我的应用程序。其中一个任务克隆了几个存储库。
使用链接的gist中的代码作为示例,在grit中进行git克隆的输出如下(在irb、ruby 1.9.2中进行
gem install grit
后应该可以直接使用):> require 'grit'
> gritty = Grit::Git.new('/tmp/filling-in')
=> #<Grit::Git:0x007f93ae105df8 @git_dir="/tmp/filling-in", @work_tree="/tmp/filling-in", @bytes_read=0>
> gritty.clone({:quiet => false, :verbose => true, :progress => true, :branch => '37s', :timeout => false}, "git://github.com/cookbooks/aws.git", "/tmp/aws")
=> "Cloning into /tmp/aws...\n"
我的问题是:我能否在克隆命令实际运行时恢复其余的标准输出?"Cloning into /tmp/aws...\n"是输出的第一行,只有当克隆完成时才返回。
第二个问题是:如果使用grit无法在克隆过程中恢复克隆进度,是否有其他方法可以显示命令在进行时的进度?我的担忧是我们的一些存储库非常大,我想给我的rakefile用户一些东西,这样他们就不会认为脚本只是在尝试与远程通信时挂起。
供参考,git clone命令的“正常”输出如下:
$ git clone git://github.com/cookbooks/aws.git /tmp/test-aws
Cloning into /tmp/test-aws...
remote: Counting objects: 12364, done.
remote: Compressing objects: 100% (3724/3724), done.
remote: Total 12364 (delta 7220), reused 12330 (delta 7203)
Receiving objects: 100% (12364/12364), 5.92 MiB | 70 KiB/s, done.
Resolving deltas: 100% (7220/7220), done.
快速提示:这里描述的一些功能,特别是:process_info
,需要一个最新版本的gem,截至今日2011年9月26日,该gem自2011年1月23日以来未更新(非常感谢Daniel Brockman在下面指出)。您需要从github克隆并手动构建它。
解决方案
如果您使用:process_info
和:progress
给Clone提供正确的信息(我的原始示例失败了,因为我使用了过时的gem),则Clone将正确地将信息传递到stderr。以下是可行的代码。由于上述原因,至少目前,您需要手动构建gem。
> require 'grit'
> repo = Grit::Git.new('/tmp/throw-away')
> process = repo.clone({:process_info => true, :progress => true, :timeout => false}, 'git://github.com/cookbooks/aws.git', '/tmp/testing-aws-again') # output supressed
> print process[2] # i.e. the stderr string of the output
remote: Counting objects: 12364, done.
remote: Compressing objects: 100% (3724/3724), done.
remote: Total 12364 (delta 7220), reused 12330 (delta 7203)
Receiving objects: 100% (12364/12364), 5.92 MiB | 801 KiB/s, done.
Resolving deltas: 100% (7220/7220), done.
git clone git://github.com/cookbooks/aws.git /tmp/test-aws 2>/dev/null
,您将看到输出的哪些部分将转到stderr。 - Daniel Brockmanrepo.fetch({:process_info => true})
(之前忘记运行了),并得到了结果[0, "", ""]
。 - Christopher:progress
到克隆引起了这个问题。 - Christopher