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

An annoying "Bug" that we would probably leave as-is

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 6, 2026, 23:10 UTC
Message-ID
<xmqqh5qswo45.fsf@gitster.g>

"git show -U" does not complain. In an ideal world, it should say "-U wants a number", just like "git show -Unan" does.

Unfortunately t/t4013/ actually has tests that break if we start tightening the command line parser for this.

This falls into the "if it hurts, do not do it" category that somebody might be taking advantage of out there that we might be better off leaving them broken.

 diff.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git c/diff.c w/diff.c
index a1961526c0..ff79a41cfc 100644
--- c/diff.c
+++ w/diff.c
@@ -5581,15 +5581,14 @@ static int diff_opt_unified(const struct option *opt,
 			    const char *arg, int unset)
 {
 	struct diff_options *options = opt->value;
-	char *s;
+	char *s = NULL;
 
 	BUG_ON_OPT_NEG(unset);
 
-	if (arg) {
+	if (arg)
 		options->context = strtol(arg, &s, 10);
-		if (*s)
-			return error(_("%s expects a numerical value"), "--unified");
-	}
+	if (!s || *s)
+		return error(_("%s expects a numerical value"), "--unified");
 	enable_patch_output(&options->output_format);
 
 	return 0;
Next: Tian Yuchen
Message 1 of 14 in “An annoying "Bug" that we would probably leave as-is”
  1. Junio C HamanoMar 6, 2026
  2. Tian YuchenMar 9, 2026
  3. diff: document -U without <n> as using default contextTian Yuchen, Mar 9, 2026
  4. D. Ben KnobleMar 9, 2026
  5. Tian YuchenMar 10, 2026
  6. Junio C HamanoMar 9, 2026
  7. Tian YuchenMar 10, 2026
  8. diff: document -U without <n> as using default contextTian Yuchen, Mar 10, 2026
  9. Oswald BuddenhagenMar 10, 2026
  10. Tian YuchenMar 10, 2026
  11. Junio C HamanoMar 10, 2026
  12. diff: document -U without <n> as using default contextTian Yuchen, Mar 10, 2026
  13. Jean-Noël AVILAMar 10, 2026
  14. Tian YuchenMar 11, 2026

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.