{"thread":{"id":"56081","subject":"Troubles redirecting git output","startedAt":"2021-07-09T11:59:50Z","lastAt":"2021-07-09T19:20:55Z","messageCount":3,"participants":["Baptiste Chocot","Marc Branchaud"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"429539","messageId":"57ebeb1d-f467-6cbd-5ad9-a55cf04dde34@gmail.com","threadId":"56081","inReplyTo":null,"subject":"Troubles redirecting git output","fromName":"Baptiste Chocot","fromEmail":"baptiste.chocot@gmail.com","sentAt":"2021-07-09T11:59:47Z","receivedAt":"2021-07-09T11:59:50Z","isPatch":false,"sender":{"key":"baptiste.chocot@gmail.com","avatar":null},"body":"Hello guys, hope you're doing great.\n\nI'm reaching out today because I cannot find a fix for my issue. I'm \nusing git 2.25.1 from the debian repo. I'm having difficulties to \nredirect git stderr, here is an example:\n\n---\n$ git init\nInitialized empty lol/.git/\n$ git branch >&2 2>/dev/null\nfatal: your current branch 'master' does not have any commits yet\n---\n\nIs this an expected behavior? I find it weird not to be able to silent \ngit. Are you aware of a workaround? I've been browsing a bit but did not \nfind an answer yet.\n\nThanks for your time!\n\nBaptiste\n\n"},{"id":"429543","messageId":"87f4a68e-3a74-eddf-c4ad-e6674d9f7994@xiplink.com","threadId":"56081","inReplyTo":"57ebeb1d-f467-6cbd-5ad9-a55cf04dde34@gmail.com","subject":"Re: Troubles redirecting git output","fromName":"Marc Branchaud","fromEmail":"marcnarc@xiplink.com","sentAt":"2021-07-09T13:40:17Z","receivedAt":"2021-07-09T13:40:21Z","isPatch":false,"sender":{"key":"marcnarc@xiplink.com","avatar":"https://avatars.githubusercontent.com/u/14980203?v=4"},"body":"On 2021-07-09 7:59 a.m., Baptiste Chocot wrote:\n> Hello guys, hope you're doing great.\n> \n> I'm reaching out today because I cannot find a fix for my issue. I'm \n> using git 2.25.1 from the debian repo. I'm having difficulties to \n> redirect git stderr, here is an example:\n> \n> ---\n> $ git init\n> Initialized empty lol/.git/\n> $ git branch >&2 2>/dev/null\n\nTry swapping the two redirections:\n\tgit branch 2>/dev/null >&2\n\nI believe that standard shell behaviour is to apply a redirection \nimmediately when it appears while parsing the command.  I believe that \nalthough the man pages say \"redirect\" internally the code just \n*replaces* the old file descriptor, e.g. basically something equivalent to\n\tstdout = 2\n\nSo when you say\n\n\tgit branch >&2 2>/dev/null\n\nThe shell sees\n\n\">&2\" -- The shell redirects stdout to file descriptor 2.\n\n\"2>/dev/null\" -- The shell opens /dev/null (as descriptor 3) and \n*replaces* descriptor 2 with the new descriptor.  But at this point, \nstdout is still being sent to the original descriptor 2.\n\nWhen I redirect, I'm in the habit of setting stdout first, then set \nstderr to stdout. The numerical ordering helps me avoid this mistake:\n\tgit branch >/dev/null 2>&1\n\n\t\tM.\n\n\n> fatal: your current branch 'master' does not have any commits yet\n> ---\n> \n> Is this an expected behavior? I find it weird not to be able to silent \n> git. Are you aware of a workaround? I've been browsing a bit but did not \n> find an answer yet.\n> \n> Thanks for your time!\n> \n> Baptiste\n> \n"},{"id":"429579","messageId":"356c442a-5b21-39ed-ca58-dc9c67727089@gmail.com","threadId":"56081","inReplyTo":"87f4a68e-3a74-eddf-c4ad-e6674d9f7994@xiplink.com","subject":"Re: Troubles redirecting git output","fromName":"Baptiste Chocot","fromEmail":"baptiste.chocot@gmail.com","sentAt":"2021-07-09T19:20:50Z","receivedAt":"2021-07-09T19:20:55Z","isPatch":false,"sender":{"key":"baptiste.chocot@gmail.com","avatar":null},"body":"Marc,\n\nThanks for your help... :facepalm: I look like a noob but at least I've \nlearnt something useful.\n\nHave a good day!\n\nOn 7/9/21 9:40 AM, Marc Branchaud wrote:\n> On 2021-07-09 7:59 a.m., Baptiste Chocot wrote:\n>> Hello guys, hope you're doing great.\n>>\n>> I'm reaching out today because I cannot find a fix for my issue. I'm \n>> using git 2.25.1 from the debian repo. I'm having difficulties to \n>> redirect git stderr, here is an example:\n>>\n>> ---\n>> $ git init\n>> Initialized empty lol/.git/\n>> $ git branch >&2 2>/dev/null\n>\n> Try swapping the two redirections:\n>     git branch 2>/dev/null >&2\n>\n> I believe that standard shell behaviour is to apply a redirection \n> immediately when it appears while parsing the command.  I believe that \n> although the man pages say \"redirect\" internally the code just \n> *replaces* the old file descriptor, e.g. basically something \n> equivalent to\n>     stdout = 2\n>\n> So when you say\n>\n>     git branch >&2 2>/dev/null\n>\n> The shell sees\n>\n> \">&2\" -- The shell redirects stdout to file descriptor 2.\n>\n> \"2>/dev/null\" -- The shell opens /dev/null (as descriptor 3) and \n> *replaces* descriptor 2 with the new descriptor.  But at this point, \n> stdout is still being sent to the original descriptor 2.\n>\n> When I redirect, I'm in the habit of setting stdout first, then set \n> stderr to stdout. The numerical ordering helps me avoid this mistake:\n>     git branch >/dev/null 2>&1\n>\n>         M.\n>\n>\n>> fatal: your current branch 'master' does not have any commits yet\n>> ---\n>>\n>> Is this an expected behavior? I find it weird not to be able to \n>> silent git. Are you aware of a workaround? I've been browsing a bit \n>> but did not find an answer yet.\n>>\n>> Thanks for your time!\n>>\n>> Baptiste\n>>\n"}]}