1

I'm just trying to run git clone from node and stream the output into stdout just like running from shell normally would, but after using child_process.spawn, I can't get the output to pipe into stdout. Currently I'm using:

child = spawn('git', ['clone', url]);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);

But I only see "Cloning into 'directory'" message and not the remote messages and "Receiving objects...".

What am I doing wrong?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
dsynkd
  • 1,999
  • 4
  • 26
  • 40

1 Answers1

2

By default, git clone only shows progress when it's running in a terminal. When it's not running in a terminal progress can be enabled with the --progress argument:

Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.

However I'm not sure that that will do exactly what you expect. The progress output isn't simple output; values change in place. I'm not exactly sure how nicely that will play with child_process.spawn().

Note also that output is to STDERR, not STDOUT.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 1
    Clone and fetch also don't pass the `--progress` argument on to `git receive-pack` so things don't work right here in general. The cure is to allocate a pseudo-tty, but it's rarely worth all the work. – torek Aug 21 '18 at 22:31
  • thanks! tried it and it works perfectly. i'm not sure how the variable output thing works either though – dsynkd Aug 22 '18 at 00:24