Subject: Re: [WIP v1 3/4] mv: add advise_to_reapply hint for moving file into cone

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Fri, 01 Apr 2022 10:02:56 +0200

On Fri, Apr 01 2022, Shaoxuan Yuan wrote:

> On Thu, Mar 31, 2022 at 6:31 PM Ævar Arnfjörð Bjarmason
> <[email-masked]> wrote:
>>
>> More odd indentation, and the braces aren't needed.
>
> Got me again :-( Will make a change.
>
>> >       }
>> >
>> >       if (gitmodules_modified)
>> > @@ -392,6 +398,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
>> >                              COMMIT_LOCK | SKIP_IF_UNCHANGED))
>> >               die(_("Unable to write new index file"));
>> >
>> > +     if (advise_to_reapply)
>> > +             printf(_("Please use \"git sparse-checkout reapply\" to reapply the sparsity.\n"));
>> > +
>>
>> Please see 93026558512 (tracking branches: add advice to ambiguous
>> refspec error, 2022-03-28) (the OID may change after I send this, as
>> it's in "seen") for how to add new advise, i.e. we use advise(), add an
>> enum field, config var etc.
>
> I actually did use advise(), but I noticed that it prints to stderr
> and ... nevermind,
> I realized that printing to stderr is OK. But can I print to stdout
> since I think users should
> be "reminded" instead of "warned"?
>
> Anyway, I think using advice() is probably better.

We've typically used stderr in git not to mean "error", but to
distinguish "chatty" and non-primary output from non-chatty.

So (leaving aside that we're unlikely to add advice to plumbing) if you
emitted a warning() or advice from git-ls-tree you should be able to run
something like:

    git ls-tree -r HEAD >output-for-a-script

And get the advise() on stderr, while the "primary" output is on stdout.

There's a recent-ish (last year or so) thread where I think Jeff King
explained this better than I'm doing here, but I couldn't find it with a
quick search.

In other words, you can just use advise() here, don't worry about it
writing to stderr.