git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RE: misleading message printed when worktree add fails

From
rsbecker@nexbridge.com <rsbecker@nexbridge.com>
Date
Nov 28, 2021, 17:11 UTC
Message-ID
<010001d7e47a$f8b4cae0$ea1e60a0$@nexbridge.com>
In-Reply-To
<CAPig+cTGq-10ZTBts2LXRVdPMf2vNMX8HTuhg_+ZHSiLX-brOQ@mail.gmail.com>
On November 28, 2021 12:01 PM, Eric Sunshine wrote:
Show 27 quoted lines
> On Sun, Nov 28, 2021 at 11:47 AM Baruch Burstein <bmburstein@gmail.com>
> wrote:
> > > When I perform these actions, I see a "fatal error" message which
> > > clearly indicates failure, not success:
> > >
> > >     % git worktree add ../foo bar
> > >     Preparing worktree (checking out 'bar')
> > >     fatal: 'bar' is already checked out at '.../wherever'
> >
> > I see them in the other order:
> >
> >     fatal: 'master' is already checked out at 'C:/Users/bmbur/temp'
> >     Preparing worktree (checking out 'master')
> >
> > which I understood as "there was an error, but we managed to recover
> > somehow and set up the worktree anyway"
> 
> Okay, that's happening because the "Preparing" message is sent to stdout,
> whereas the "fatal" error is sent to stderr, and the streams are being flushed
> on Windows in a different order than what we typically see on Unix
> platforms even though the "Preparing" message is actually output first by the
> code.
> 
> A general fix (not specific to git-worktree) might be to have die() (or maybe
> vreportf()?) flush stdout before reporting the error message on stderr. That
> should make output order more predictable, such that general status
> messages appear before error messages.
This is probably a good idea. There is no guarantee even in Unix regarding stream buffer flushing. If there is a reason to sequence output between stdout and stderr, then fflush is important.
-Randall
Previous: Eric SunshineNext: Eric Sunshine
Message 5 of 6 in “misleading message printed when worktree add fails”
  1. Baruch BursteinNov 28, 2021
  2. Eric SunshineNov 28, 2021
  3. Baruch BursteinNov 28, 2021
  4. Eric SunshineNov 28, 2021
  5. rsbecker@nexbridge.comNov 28, 2021
  6. Eric SunshineNov 30, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.