From: Junio C Hamano Date: Fri, 24 Dec 2021 19:42:27 GMT Subject: Re: bug: git name-rev --stdin --no-undefined on detached head Message-ID: In-Reply-To: John Cai writes: > It seems like this bug can be generalized to “git name-rev > --stdin” does not work with --no-undefined nor --name-only > > The --name-only case seems clear to me that we should fix > it. It’s misleading to return the sha instead of “undefined” > for a rev without a symbolic name, as a sha could be a symbolic > name. > > I think we can also make the argument that --no-undefined should > also die in --stdin mode when given a rev without any symbolic > names. Hmph, the manual page documents: --stdin:: Transform stdin by substituting all the 40-character SHA-1 hexes (say $hex) with "$hex ($rev_name)". When used with --name-only, substitute with "$rev_name", omitting $hex altogether. Intended for the scripter's use. It is unfortunate that the way this option works is confusingly a bit different from what we learned to expect from the --stdin option other subcommands like "git pack-objects --stdin" takes. In short, these are not equivalent: git name-rev [] $string printf "%s" "$string" | xargs git name-rev [] printf "%s" "$string" | git name-rev --stdin [] The first two are supposed to be the equivalent, but the third one is different by design. Its `--stdin` mode is expected to read something like this [*]: $ cat sample.txt A revision that exists 2ae0a9cb82 is shown here, and its full name is 2ae0a9cb8298185a94e5998086f380a355dd8907 while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad which probably is undescribable hexdigits. and its designed use is to annotate its input into a more reader friendly from with refnames where possible. Here is what we get: $ git name-rev --stdin sample.txt <