{"thread":{"id":"56988","subject":"misleading message printed when worktree add fails","startedAt":"2021-11-28T06:53:30Z","lastAt":"2021-11-30T04:46:28Z","messageCount":6,"participants":["Baruch Burstein","Eric Sunshine","rsbecker@nexbridge.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"442408","messageId":"CA+34VNLj6VB1kCkA=MfM7TZR+6HgqNi5-UaziAoCXacSVkch4A@mail.gmail.com","threadId":"56988","inReplyTo":null,"subject":"misleading message printed when worktree add fails","fromName":"Baruch Burstein","fromEmail":"bmburstein@gmail.com","sentAt":"2021-11-28T06:50:54Z","receivedAt":"2021-11-28T06:53:30Z","isPatch":false,"sender":{"key":"bmburstein@gmail.com","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nrun `git worktree add <path> <branch>`, where <branch> is an already\nchecked-out branch\n\nWhat did you expect to happen? (Expected behavior)\n\nfail to create worktree\n\nWhat happened instead? (Actual behavior)\n\nworktree was not created, but a confusing message was printed:\n\"Preparing worktree (checking out '<branch>')\"\n\nWhat's different between what you expected and what actually happened?\n\nThe printed message seems to indicate that the command was a success,\nwhen in fact\nit was not\n\nAnything else you want to add:\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.33.1.windows.1\ncpu: x86_64\nbuilt from commit: 05d80adb775077d673fab685009ede4a1003ed92\nsizeof-long: 4\nsizeof-size_t: 8\nshell-path: /bin/sh\nfeature: fsmonitor--daemon\nuname: Windows 10.0 18363\ncompiler info: gnuc: 10.3\nlibc info: no libc information available\n$SHELL (typically, interactive shell): C:\\Program Files\\Git\\usr\\bin\\bash.exe\n"},{"id":"442413","messageId":"CAPig+cQ224Tz5iQ5Yt4fMadehLmrJWGzH7kwUSr+UT4hcQf14w@mail.gmail.com","threadId":"56988","inReplyTo":"CA+34VNLj6VB1kCkA=MfM7TZR+6HgqNi5-UaziAoCXacSVkch4A@mail.gmail.com","subject":"Re: misleading message printed when worktree add fails","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-11-28T12:37:31Z","receivedAt":"2021-11-28T12:39:43Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"Thanks for reporting. Inline comments below...\n\nOn Sun, Nov 28, 2021 at 1:53 AM Baruch Burstein <bmburstein@gmail.com> wrote:\n> What did you do before the bug happened? (Steps to reproduce your issue)\n>\n> run `git worktree add <path> <branch>`, where <branch> is an already\n> checked-out branch\n>\n> What happened instead? (Actual behavior)\n>\n> worktree was not created, but a confusing message was printed:\n> \"Preparing worktree (checking out '<branch>')\"\n>\n> What's different between what you expected and what actually happened?\n>\n> The printed message seems to indicate that the command was a success,\n> when in fact\n> it was not\n\nWhen I perform these actions, I see a \"fatal error\" message which\nclearly indicates failure, not success:\n\n    % git worktree add ../foo bar\n    Preparing worktree (checking out 'bar')\n    fatal: 'bar' is already checked out at '.../wherever'\n\nIs your installation not showing the \"fatal error\" message?\n\nOr, are you saying that the \"Preparing worktree\" message is\nmisleading? I read that message as telling me what the command is\ntrying to do (i.e. \"Preparing\"), and the error happens as it makes the\nattempts, which seems logical to me, thus I don't see anything\nmisleading in that.\n\nAre you reading it differently, as if it is saying that it already\nperformed that action (i.e. \"Prepared\")?\n"},{"id":"442415","messageId":"CA+34VNJbOHYhYgN+p7EsGiRAzf+aAQGeMxCzG1dizFjDRVQVbg@mail.gmail.com","threadId":"56988","inReplyTo":"CAPig+cQ224Tz5iQ5Yt4fMadehLmrJWGzH7kwUSr+UT4hcQf14w@mail.gmail.com","subject":"Re: misleading message printed when worktree add fails","fromName":"Baruch Burstein","fromEmail":"bmburstein@gmail.com","sentAt":"2021-11-28T16:47:14Z","receivedAt":"2021-11-28T16:51:26Z","isPatch":false,"sender":{"key":"bmburstein@gmail.com","avatar":null},"body":"I see them in the other order:\n\n    fatal: 'master' is already checked out at 'C:/Users/bmbur/temp'\n    Preparing worktree (checking out 'master')\n\nwhich I understood as \"there was an error, but we managed to recover\nsomehow and set up the worktree anyway\"\n\n\nOn Sun, Nov 28, 2021 at 2:37 PM Eric Sunshine <sunshine@sunshineco.com> wrote:\n>\n> Thanks for reporting. Inline comments below...\n>\n> On Sun, Nov 28, 2021 at 1:53 AM Baruch Burstein <bmburstein@gmail.com> wrote:\n> > What did you do before the bug happened? (Steps to reproduce your issue)\n> >\n> > run `git worktree add <path> <branch>`, where <branch> is an already\n> > checked-out branch\n> >\n> > What happened instead? (Actual behavior)\n> >\n> > worktree was not created, but a confusing message was printed:\n> > \"Preparing worktree (checking out '<branch>')\"\n> >\n> > What's different between what you expected and what actually happened?\n> >\n> > The printed message seems to indicate that the command was a success,\n> > when in fact\n> > it was not\n>\n> When I perform these actions, I see a \"fatal error\" message which\n> clearly indicates failure, not success:\n>\n>     % git worktree add ../foo bar\n>     Preparing worktree (checking out 'bar')\n>     fatal: 'bar' is already checked out at '.../wherever'\n>\n> Is your installation not showing the \"fatal error\" message?\n>\n> Or, are you saying that the \"Preparing worktree\" message is\n> misleading? I read that message as telling me what the command is\n> trying to do (i.e. \"Preparing\"), and the error happens as it makes the\n> attempts, which seems logical to me, thus I don't see anything\n> misleading in that.\n>\n> Are you reading it differently, as if it is saying that it already\n> performed that action (i.e. \"Prepared\")?\n"},{"id":"442416","messageId":"CAPig+cTGq-10ZTBts2LXRVdPMf2vNMX8HTuhg_+ZHSiLX-brOQ@mail.gmail.com","threadId":"56988","inReplyTo":"CA+34VNJbOHYhYgN+p7EsGiRAzf+aAQGeMxCzG1dizFjDRVQVbg@mail.gmail.com","subject":"Re: misleading message printed when worktree add fails","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-11-28T17:00:37Z","receivedAt":"2021-11-28T17:02:49Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"[please comment inline on this list rather than top-posting]\n\nOn Sun, Nov 28, 2021 at 11:47 AM Baruch Burstein <bmburstein@gmail.com> wrote:\n> > When I perform these actions, I see a \"fatal error\" message which\n> > clearly indicates failure, not success:\n> >\n> >     % git worktree add ../foo bar\n> >     Preparing worktree (checking out 'bar')\n> >     fatal: 'bar' is already checked out at '.../wherever'\n>\n> I see them in the other order:\n>\n>     fatal: 'master' is already checked out at 'C:/Users/bmbur/temp'\n>     Preparing worktree (checking out 'master')\n>\n> which I understood as \"there was an error, but we managed to recover\n> somehow and set up the worktree anyway\"\n\nOkay, that's happening because the \"Preparing\" message is sent to\nstdout, whereas the \"fatal\" error is sent to stderr, and the streams\nare being flushed on Windows in a different order than what we\ntypically see on Unix platforms even though the \"Preparing\" message is\nactually output first by the code.\n\nA general fix (not specific to git-worktree) might be to have die()\n(or maybe vreportf()?) flush stdout before reporting the error message\non stderr. That should make output order more predictable, such that\ngeneral status messages appear before error messages.\n"},{"id":"442417","messageId":"010001d7e47a$f8b4cae0$ea1e60a0$@nexbridge.com","threadId":"56988","inReplyTo":"CAPig+cTGq-10ZTBts2LXRVdPMf2vNMX8HTuhg_+ZHSiLX-brOQ@mail.gmail.com","subject":"RE: misleading message printed when worktree add fails","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2021-11-28T17:11:18Z","receivedAt":"2021-11-28T17:13:34Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On November 28, 2021 12:01 PM, Eric Sunshine wrote:\n> On Sun, Nov 28, 2021 at 11:47 AM Baruch Burstein <bmburstein@gmail.com>\n> wrote:\n> > > When I perform these actions, I see a \"fatal error\" message which\n> > > clearly indicates failure, not success:\n> > >\n> > >     % git worktree add ../foo bar\n> > >     Preparing worktree (checking out 'bar')\n> > >     fatal: 'bar' is already checked out at '.../wherever'\n> >\n> > I see them in the other order:\n> >\n> >     fatal: 'master' is already checked out at 'C:/Users/bmbur/temp'\n> >     Preparing worktree (checking out 'master')\n> >\n> > which I understood as \"there was an error, but we managed to recover\n> > somehow and set up the worktree anyway\"\n> \n> Okay, that's happening because the \"Preparing\" message is sent to stdout,\n> whereas the \"fatal\" error is sent to stderr, and the streams are being flushed\n> on Windows in a different order than what we typically see on Unix\n> platforms even though the \"Preparing\" message is actually output first by the\n> code.\n> \n> A general fix (not specific to git-worktree) might be to have die() (or maybe\n> vreportf()?) flush stdout before reporting the error message on stderr. That\n> should make output order more predictable, such that general status\n> messages appear before error messages.\n\nThis 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.\n\n-Randall\n\n"},{"id":"442600","messageId":"CAPig+cSRonrX2SUARS=spEnWzapH6osvi3ZvZ2rPURA2zRSkvQ@mail.gmail.com","threadId":"56988","inReplyTo":"CAPig+cTGq-10ZTBts2LXRVdPMf2vNMX8HTuhg_+ZHSiLX-brOQ@mail.gmail.com","subject":"Re: misleading message printed when worktree add fails","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-11-30T04:46:15Z","receivedAt":"2021-11-30T04:46:28Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Nov 28, 2021 at 12:00 PM Eric Sunshine <sunshine@sunshineco.com> wrote:\n> Okay, that's happening because the \"Preparing\" message is sent to\n> stdout, whereas the \"fatal\" error is sent to stderr, and the streams\n> are being flushed on Windows in a different order than what we\n> typically see on Unix platforms even though the \"Preparing\" message is\n> actually output first by the code.\n>\n> A general fix (not specific to git-worktree) might be to have die()\n> (or maybe vreportf()?) flush stdout before reporting the error message\n> on stderr. That should make output order more predictable, such that\n> general status messages appear before error messages.\n\nAn RFC patch has been posted to address this issue.\nhttps://lore.kernel.org/git/20211130043946.19987-1-sunshine@sunshineco.com/\n"}]}