git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [Bug?] "git diff --no-rename A B"

From
Jeff King <peff@peff.net>
Date
Jan 22, 2024, 23:00 UTC
Message-ID
<20240122230051.GB814674@coredump.intra.peff.net>
In-Reply-To
<579fd5bc-3bfd-427f-b22d-dab5e7e56eb2@web.de>
On Sat, Jan 20, 2024 at 03:39:38PM +0100, René Scharfe wrote:
Show 9 quoted lines
> > The issue is that we have "--rename-empty", which of course also
> > provides "--no-rename-empty". And parse-options is happy to let you
> > abbreviate names as long as they are unambiguous. But "--no-rename" _is_
> > ambiguous with "--no-renames". Why don't we catch it?
> 
> Because diff_opt_parse() passes PARSE_OPT_KEEP_UNKNOWN_OPT, which makes
> parse_long_opt() skip abbreviation detection.  Which it does since
> baa4adc66a (parse-options: disable option abbreviation with
> PARSE_OPT_KEEP_UNKNOWN, 2019-01-27).

OK, it makes sense to me that we should avoid abbreviation entirely with KEEP_UNKNOWN_OPT, for the reasons given in that commit. But if adding --rename fixed it, is there another bug lurking? That is, would we do the wrong thing on a case without KEEP_UNKNOWN_OPT but which had "--renames" and "--no-rename" defined? Or was it simply the inconsistency in how KEEP_UNKNOWN_OPT is being applied?

I think it might just be the latter. If I do this:
diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
index ded8116cc5..e908c7386d 100644
--- a/t/helper/test-parse-options.c
+++ b/t/helper/test-parse-options.c
@@ -124,6 +124,7 @@ int cmd__parse_options(int argc, const char **argv)
 	struct option options[] = {
 		OPT_BOOL(0, "yes", &boolean, "get a boolean"),
 		OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"),
+		OPT_BOOL(0, "do-it", &boolean, "'do' ambiguous with 'doubt'"),
 		{ OPTION_SET_INT, 'B', "no-fear", &boolean, NULL,
 		  "be brave", PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
 		OPT_COUNTUP('b', "boolean", &boolean, "increment by one"),

then running:

  t/helper/test-tool parse-options --do

correctly complains about the ambiguity (though amusingly it mentions
"--no-no-doubt" in the error message). And if I add KEEP_UNKNOWN_OPT,
then it gives the wrong behavior. But curiously it does so even with
your patch applied. So I think there may be further fixes needed.

-Peff
Previous: René ScharfeNext: Jeff King
Message 7 of 8 in “[Bug?] "git diff --no-rename A B"”
  1. Junio C HamanoJan 18, 2024
  2. Dragan SimicJan 18, 2024
  3. Jeff KingJan 20, 2024
  4. René ScharfeJan 20, 2024
  5. Junio C HamanoJan 20, 2024
  6. René ScharfeJan 21, 2024
  7. Jeff KingJan 22, 2024
  8. Jeff KingJan 23, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.