From: Jeff King <peff@peff.net>
To: Erik Faye-Lund <kusmabite@gmail.com>
Cc: git@vger.kernel.org, steveire@gmail.com,
felipe.contreras@gmail.com, gitster@pobox.com
Subject: Re: [PATCH] only warn about ambiguous refs if stderr is a tty
Date: Mon, 9 May 2011 04:03:15 -0400 [thread overview]
Message-ID: <20110509080315.GA6205@sigill.intra.peff.net> (raw)
In-Reply-To: <1304927478-3112-1-git-send-email-kusmabite@gmail.com>
On Mon, May 09, 2011 at 09:51:18AM +0200, Erik Faye-Lund wrote:
> If there's a branch (either local or remote) called 'HEAD'
> commands that take a ref currently emits a warning, no matter
> if the output is going to a TTY or not.
>
> Fix this by making sure we only output this warning when stderr
> is a TTY. Other git commands or scripts should not care about
> this ambiguity.
>
> This fix prevents gitk from barfing when given no arguments and
> there's a branch called 'HEAD'.
This feels wrong. Gitk should not care about messages on stderr, for
exactly the reason that they may be harmless warnings (if anything, it
should show them to the user in a dialog).
My understanding is that this is a tcl thing, but I just think it's
insane.
> In 2f8acdb ('core.warnambiguousrefs: warns when "name" is used
> and both "name" branch and tag exists.'), a check for collisions
> of refs was introduced. It does not seem to me like the intention
> was to check HEAD for ambiguty (because the commit talks about
> branches and tags), but it does.
>
> Because HEAD cannot be disambiguated like branches and tags can,
> this can lead to an annoying warning, or even an error in the case
> of gitk.
This is a separate issue, isn't it? Gitk should probably handle
ambiguous ref warnings better, no matter what the name. And if
ambiguous HEAD warnings are considered too annoying, they should be
squelched for everyone. I don't personally have an opinion on the
latter, though.
> A branch called HEAD can be 'injected' into another user's repo
> through remotes, and this can cause annoyance (and in the case of
> gitk, brokenness) just by pulling the wrong remote. Yuck.
Can you give an example? If I am fetching your refs into
refs/remotes/$remote/*, how does that create an ambiguity?
> The particular problem of gitk can be fixed by making gitk able
> to parse the warning, and probably forwarding it to the user.
> This strikes me as The Right Thing To Do(tm), but is outside of my
> gitk and TCL/TK skills.
Agreed. And also outside my tcl skills. :)
> One question is if ANY warnings should be output to stderr if it's
> not a TTY. My guess is that there probably are some classes of
> warnings that should, but the vast majority should probably not.
I disagree. If I do:
git foo 2>errors
I would certainly expect any relevant errors to end up in that file. As
for why I would do that, two cases I can think of offhand are:
1. Test scripts, which use this extensively.
2. Sometimes cron jobs will capture chatty output in a file and show
it only in the case of some error condition.
> Another question is if we should come up with a way of
> disambiguating HEAD. Perhaps having something like 'refs/HEAD'
> will do?
Yeah, if we disambiguate, I would be tempted to say that "HEAD" always
unambiguously refers to "HEAD". And "refs/HEAD" should already
work, no?
> So, to recap: The way I see it, these are our options:
>
> 1) Discard this specific warning when stderr isn't a TTY (i.e
> what this patch does)
> 2) Discard all warnings when stderr isn't a TTY
> 3) Make gitk understand and forward warnings to the user
> 4) Have gitk explicitly ignore ambiuous refs
> 5) Come up with a way to disambiguate HEAD, and use that instead
> by default
> 6) Force HEAD to never be ambiguous
> 7) Leave things as they are
>
> I think 3) + 5) might be the most sane solution.
Agreed.
> diff --git a/sha1_name.c b/sha1_name.c
> index faea58d..c7e855e 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -391,7 +391,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
> if (!refs_found)
> return -1;
>
> - if (warn_ambiguous_refs && refs_found > 1)
> + if (warn_ambiguous_refs && refs_found > 1 && isatty(2))
> warning(warn_msg, len, str);
>
I think I have made it clear that I am not in favor of this approach,
but if we were to do it, it is too late to be calling isatty(2) here.
You need to also check pager_in_use(), as we may have redirected stderr
into the pager's pipe.
-Peff
next prev parent reply other threads:[~2011-05-09 8:03 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-17 10:02 Creating remote branch called HEAD corrupts remote clones Stephen Kelly
2011-01-20 11:14 ` Stephen Kelly
2011-01-20 13:03 ` Thomas Rast
2011-01-20 15:05 ` Stephen Kelly
2011-01-20 15:41 ` Erik Faye-Lund
2011-01-20 16:00 ` Stephen Kelly
2011-01-20 17:32 ` Felipe Contreras
2011-01-20 19:21 ` Wesley J. Landaker
2011-01-20 19:53 ` Junio C Hamano
2011-01-20 20:38 ` Jeff King
2011-01-20 21:43 ` Junio C Hamano
2011-01-20 21:54 ` Jeff King
2011-01-20 23:52 ` Felipe Contreras
2011-01-21 17:37 ` Junio C Hamano
2011-01-22 12:46 ` Felipe Contreras
2011-02-20 13:17 ` Stephen Kelly
2011-04-26 12:09 ` Stephen Kelly
2011-04-26 18:18 ` Felipe Contreras
2011-04-27 9:18 ` Stephen Kelly
2011-04-27 9:48 ` Felipe Contreras
2011-04-27 11:29 ` Stephen Kelly
2011-04-27 11:32 ` Felipe Contreras
2011-04-27 11:37 ` Stephen Kelly
2011-04-27 12:26 ` Felipe Contreras
2011-04-27 12:21 ` Erik Faye-Lund
2011-04-27 12:49 ` Erik Faye-Lund
2011-05-02 19:26 ` Stephen Kelly
2011-05-02 19:43 ` Erik Faye-Lund
2011-05-03 17:54 ` Felipe Contreras
2011-05-03 18:08 ` Stephen Kelly
2011-05-03 19:20 ` Felipe Contreras
2011-05-04 12:35 ` Erik Faye-Lund
2011-05-09 7:51 ` [PATCH] only warn about ambiguous refs if stderr is a tty Erik Faye-Lund
2011-05-09 8:03 ` Jeff King [this message]
2011-05-09 8:41 ` Erik Faye-Lund
2011-05-09 10:32 ` Jeff King
2011-05-09 12:37 ` Erik Faye-Lund
2011-05-09 12:49 ` Jeff King
2011-05-09 16:33 ` Junio C Hamano
2011-05-09 22:09 ` Jeff King
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110509080315.GA6205@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kusmabite@gmail.com \
--cc=steveire@gmail.com \
/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.
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 NNTP newsgroup(s).