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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
thanks! tried it and it works perfectly. i'm not sure how the variable output thing works either though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.