3

The message

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

after a git submodule add... command is written to stderr. I expected the message to be written to stdout since I don't think it indicates 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.

René Nyffenegger
  • 35,550
  • 26
  • 140
  • 232

1 Answers1

3

This is not limited to submodules, as noted here:

The registration of the submodule will be reported to stderr, as that is consistent with the rest of progress reporting within Git.

This helps us in a later patch when we want to reuse the init_submodule function in update_clone whose stdout will be piped to shell which reads parameters off stdout in a very specific way.

You can see it also in this recent patch:

Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.

We want to init submodules from the helper for submodule update in a later patch and the stdout output of said helper is consumed by the parts of submodule update which are still written in shell.

So we have to be careful which messages are on stdout.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Surprised they didn't think to add a flag for machine-readable output... – aleclarson Sep 04 '17 at 17:47
  • 1
    @aleclarson machine-readable output is the default in Git, and goes to stdout. Anything else goes to stderr. – VonC Sep 04 '17 at 19:12
  • Maybe, but I would prefer the approach of `git status` with its `--porcelain` flag, instead of abusing stderr. But maybe that's just me. – aleclarson Sep 04 '17 at 20:13
  • @aleclarson I understand. I present the `--porcelain` option in https://stackoverflow.com/a/6978402/6309. – VonC Sep 04 '17 at 20:15
  • Perhaps a special character for identifying output that should not be machine-read would be better than abusing stderr. – aleclarson Sep 04 '17 at 20:17