git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Marc Branchaud <marcnarc@xiplink.com>
To: Baptiste Chocot <baptiste.chocot@gmail.com>, git@vger.kernel.org
Subject: Re: Troubles redirecting git output
Date: Fri, 9 Jul 2021 09:40:17 -0400	[thread overview]
Message-ID: <87f4a68e-3a74-eddf-c4ad-e6674d9f7994@xiplink.com> (raw)
In-Reply-To: <57ebeb1d-f467-6cbd-5ad9-a55cf04dde34@gmail.com>

On 2021-07-09 7:59 a.m., Baptiste Chocot wrote:
> Hello guys, hope you're doing great.
> 
> I'm reaching out today because I cannot find a fix for my issue. I'm 
> using git 2.25.1 from the debian repo. I'm having difficulties to 
> redirect git stderr, here is an example:
> 
> ---
> $ git init
> Initialized empty lol/.git/
> $ git branch >&2 2>/dev/null

Try swapping the two redirections:
	git branch 2>/dev/null >&2

I believe that standard shell behaviour is to apply a redirection 
immediately when it appears while parsing the command.  I believe that 
although the man pages say "redirect" internally the code just 
*replaces* the old file descriptor, e.g. basically something equivalent to
	stdout = 2

So when you say

	git branch >&2 2>/dev/null

The shell sees

">&2" -- The shell redirects stdout to file descriptor 2.

"2>/dev/null" -- The shell opens /dev/null (as descriptor 3) and 
*replaces* descriptor 2 with the new descriptor.  But at this point, 
stdout is still being sent to the original descriptor 2.

When I redirect, I'm in the habit of setting stdout first, then set 
stderr to stdout. The numerical ordering helps me avoid this mistake:
	git branch >/dev/null 2>&1

		M.


> fatal: your current branch 'master' does not have any commits yet
> ---
> 
> Is this an expected behavior? I find it weird not to be able to silent 
> git. Are you aware of a workaround? I've been browsing a bit but did not 
> find an answer yet.
> 
> Thanks for your time!
> 
> Baptiste
> 

  reply	other threads:[~2021-07-09 13:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09 11:59 Troubles redirecting git output Baptiste Chocot
2021-07-09 13:40 ` Marc Branchaud [this message]
2021-07-09 19:20   ` Baptiste Chocot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87f4a68e-3a74-eddf-c4ad-e6674d9f7994@xiplink.com \
    --to=marcnarc@xiplink.com \
    --cc=baptiste.chocot@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).