【问题标题】:Git clone doesn't show progressGit克隆不显示进度
【发布时间】:2019-06-13 20:34:04
【问题描述】:

我正在尝试获取 git clone 的进度但没有成功。

我尝试使用git clone --progress <path> 2>stderr.txt,但它只返回:

Cloning into 'project-name'...
done.

我需要的输出是这样的:

Progress: 1/100
Progress: 2/100
Progress: 3/100

我的 git 版本是 2.21.0.windows.1

编辑:

我使用 child_process 从 NodeJS 调用 git clone,代码如下:

let cloneSpawn = spawn("git", ["clone", "--progress", path], {shell: true});
cloneSpawn.stderr.on("data", d => {
  console.log(d.toString());
});

【问题讨论】:

标签: windows git cmd progress


【解决方案1】:

克隆进度输出到标准错误。即使 stderr 不是 tty 设备,--progress 标志也会强制它发生(例如,C library isatty() function 返回 false/0)。

不幸的是,git clone 内部的--progress 通过调用其他 Git 程序来工作,它无法将 --progress 标志传递给 那些 程序。这些程序会进行自己单独的isatty() 测试,这表明您重定向的 stderr 不是 tty,因此 那些 程序不会打印任何进度消息。

解决此问题需要修复底层 Git 错误。如果您选择这样做,解决方法是将您的git clone 连接到满足isatty 测试的东西:Linux 和类似系统上的伪tty。 (我不知道在 Windows 上有什么技巧。)

【讨论】:

  • 我实际上是从 nodejs 读取标准错误。我用代码更新了主帖。
  • 我不知道它在 Windows 上的作用。 Unix-ish 等价物是通过管道定向输出的 fork 和 exec,并且管道对象不是“tty-ish”,因此无法通过 isatty() 测试。 (大约三年前,我编写了一个大型 Python 程序来维护一堆存储库,并希望它能够获取进度指示,结果遇到了同样的问题。)
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2020-03-04
  • 2013-08-07
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多