1

I'm trying to get the progress of git clone without success.

I tried with git clone --progress <path> 2>stderr.txt but it only returns:

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

The output that I need would be something like:

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

My git version is 2.21.0.windows.1

Edit:

I'm calling git clone from NodeJS using child_process with the following code:

let cloneSpawn = spawn("git", ["clone", "--progress", path], {shell: true});
cloneSpawn.stderr.on("data", d => {
  console.log(d.toString());
});
Lucas
  • 11
  • 3
  • 1
    Possible duplicate of [Progress indicator for git clone](https://stackoverflow.com/questions/4640020/progress-indicator-for-git-clone) – René Höhle Jun 13 '19 at 20:36
  • Tried that, didn't work – Lucas Jun 13 '19 at 20:40
  • @lucas, which answer(s) to [Progress indicator for git clone](https://stackoverflow.com/questions/4640020/progress-indicator-for-git-clone) did you try, and what problems did you have with it (them)? – Preacher Jun 13 '19 at 20:51
  • @Preacher Tried with --progress flag. Monitoring folder size isn't an option because the execution blocks the program. – Lucas Jun 13 '19 at 21:01

1 Answers1

2

Clone progress is output to stderr. The --progress flag forces it to occur even if stderr is not a tty device (as in, the C library isatty() function returns false/0).

Unfortunately, --progress inside git clone works by invoking other Git programs, and it fails to pass the --progress flag to those programs. Those programs do their own separate isatty() test, which says that your redirected stderr is not a tty, so those programs don't print any progress messages.

Fixing this requires fixing the underlying Git bug. The workaround, should you choose to do that, is to connect your git clone to something that satisfies the isatty test: a pseudo-tty, on Linux and similar systems. (I don't know what does the trick on Windows.)

torek
  • 448,244
  • 59
  • 642
  • 775
  • I'm actually reading the stderr from nodejs. I updated the main post with the code. – Lucas Jun 13 '19 at 20:52
  • I don't know what that does on Windows. The Unix-ish equivalent is to fork and exec with output directed through a pipe, and pipe objects are not "tty-ish" and hence fail the isatty() test. (About three years ago, I wrote a big Python program to maintain a bunch of repositories, and wanted to have it grab progress indications, and ran into this very same issue.) – torek Jun 13 '19 at 20:55