gpt4 book ai didi

ruby - 我可以获取以 grit 发出的 git clone 命令的进度,输出到标准输出吗?

转载 作者:数据小太阳 更新时间:2023-10-29 07:36:52 24 4
gpt4 key购买 nike

我相当有信心这是不可能的,或者我错过了一个明显的选择,但在咨询了 grit's Git class 之后,链接的 Gist in this SO post ,以及其他关于 SO 的粗鲁标记问题,我一头雾水。

我正在使用 grit 执行一系列安装我的应用程序的 rake 任务。其中一项任务克隆了一些存储库。

使用 linked 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 年 1 月 23 日以来,截至今天,该版本尚未更新, 2011 年 9 月 26 日(非常感谢 Daniel Brockman 在下方指出这一点)。你必须 clone it from githubbuild it manually.

解决方案

如果您提供 :process_info:progress,Clone 会将正确的信息传递给 stderr(我的原始示例失败,因为我有一个过时的 gem)。以下是工作代码。出于上述原因,您需要手动构建 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.

最佳答案

你只得到第一行输出的原因是它的其余部分被发送到 stderr,而不是 stdout。您可以传递一个 :process_info 选项来获取退出状态、stdout 和 stderr。参见 https://github.com/mojombo/grit/blob/master/lib/grit/git.rb#L290 .

关于ruby - 我可以获取以 grit 发出的 git clone 命令的进度,输出到标准输出吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7561359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com