Why is "<2020 add submodule ..." written in stderr and not stdout?

Message

 Cloning into 'sub-mod'... done. 

after the git submodule add... command is written to stderr. I was expecting the message to be written to stdout, since I do not think this indicates that something went wrong with the command.

I can reproduce this with the following sequence of commands:

 rm -rf /tmp/repo /tmp/module mkdir /tmp/repo /tmp/module cd /tmp/module git init > /dev/null echo "foo" > foo; git add foo > /dev/null git commit . -m "+ foo" > /dev/null cd /tmp/repo git init > /dev/null git submodule add /tmp/module/ sub-mod 1> /dev/null 

If I change the redirection in the last command to ... 2> /dev/null , nothing is printed.

+1
source share
1 answer

This is not limited to submodules, as noted here :

Submodule registration will be reported to stderr, as this is in accordance with the rest of the Git progress report .

This helps us in a later fix when we want to reuse the init_submodule function in update_clone , whose stage will be a pipeline for a shell that reads parameters with stdout in a very specific way.

You can also see this in this recent patch :

Cancel the output of stdout to stderr as it is just informative of messages that should not be consumed by machines .

We want to initialize the submodules from the helper for submodule update in a later patch, and we get the stdout output of the helper for parts of the submodule update that are still written in the shell.

Therefore, we must be careful which messages are in stdout mode.

+1
source

Source: https://habr.com/ru/post/1274869/


All Articles