3

I'm trying to improve my CI tooling and to do so I'm trying to capture the output of the git clone command, and this is driving me crazy.

In order to simplify the scenario, I reduce the problem to this simple command:

git clone --progress https://github.com/$REPO.git $FOLDER 2>&1 | xargs echo - 

With 2>&1 I'm redirecting the stderr (use by git to output the progress) to the stdout, then I'm trying to pipe that to xargs echo -. In my real life scenario xargs echo will be replaced by something else.

I'm using --progress in order to force git to be verbose even if it is not attached to a real console.

My expected output would be:

- Cloning into 'a3'... - remote: Counting objects: 54130, done. - remote: Compressing objects: 100% (520/520), done. 

My output is instead absolutely nothing. I'm testing this on OSX 10.11.

Does anyone know what's wrong with that command?

Thank you very much in advance.

1
  • Do you never get anything, or do you just not get it real-time, does it just all come at the end? Commented May 8, 2016 at 17:15

4 Answers 4

1

I solved it by using

git clone --progress --branch $TAG_VERSION https://github.com/$REPO ./ 2>&1 | tr '\u000D' '\n'" 
Sign up to request clarification or add additional context in comments.

1 Comment

\r is probably a lot more readable than \u0000D
0

Your command works for me. It outputs something like "- Cloning into repo... remote...". I guess your system fails to capture the output because of output buffering.

Try to turn on flushing after each record(set GIT_FLUSH environment variable to 1). Also, turn off buffering for git clone command:

repo='your-repo-uri' while read -r l; do echo "<<<<<<<<<<" echo "$l" echo ">>>>>>>>>>" done < <(GIT_FLUSH=1 stdbuf -i0 -o0 -e0 git clone --progress "$repo" 2>&1) 

Comments

0

You can use this:

git clone --progress url > clone.txt 2>&1 

The trick is to add the 2>&1 as the last arguments of the command.
It will print out all the command as they would have been printed out to the terminal but now they are written to the desired file instead.

enter image description here

Comments

0

If you use GIT_FLUSH as in Ruslan Osmanov's answer; make sure to use Git 2.44 (Q1 2024): Unlike other environment variables that took the usual true/false/yes/no as well as 0/1, GIT_FLUSH only understood 0/1. This has been fixed

See commit 556e680 (04 Jan 2024) by Chandra Pratap (Pratapchandradeo).
(Merged by Junio C Hamano -- gitster -- in commit b3049bb, 12 Jan 2024)

write-or-die: make GIT_FLUSH a Boolean environment variable

Signed-off-by: Chandra Pratap

Among Git's environment variables, the ones marked as "Boolean" accept values in a way similar to Boolean configuration variables, i.e.
values like 'yes', 'on', 'true' and positive numbers are taken as "on" and values like 'no', 'off', 'false' are taken as "off".

GIT_FLUSH can be used to force Git to use non-buffered I/O when writing to stdout.
It can only accept two values, '1' which causes Git to flush more often and '0' which makes all output buffered.
Make GIT_FLUSH accept more values besides '0' and '1' by turning it into a Boolean environment variable, modifying the required logic.
Update the related documentation.

git now includes in its man page:

If this Boolean environment variable is set to true, then commands such

git now includes in its man page:

variable is set to false, the output of these commands will be done

So: done < <(GIT_FLUSH=on stdbuf -i0 -o0 -e0 git clone --progress "$repo" 2>&1) would work too.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.