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

Re: No "invalid option" message with git diff --cached --invalid-option

From
Jeff King <peff@peff.net>
Date
Jun 22, 2017, 14:13 UTC
Message-ID
<20170622141305.lpso6r6yxejymvel@sigill.intra.peff.net>
In-Reply-To
<20170622124458.ilokr7acas2bzq4z@ruderich.org>
On Thu, Jun 22, 2017 at 02:44:58PM +0200, Simon Ruderich wrote:
Show 15 quoted lines
> I'm using Git 2.13.1 (from the Debian sid repository) and noticed
> the following issue when upgrading.
> 
>     $ git diff --compaction-heuristic
>     error: invalid option: --compaction-heuristic
> 
>     $ git diff --cached --compaction-heuristic
>     usage: git diff [<options>] [<commit> [<commit>]] [--] [<path>...]
> 
> I know that --compaction-heuristic is no longer supported but I
> was using it an alias and was confused that I got no proper error
> message warning me which option was wrong.
> 
> It seems to happen for any invalid option which is used in
> combination with --cached or --staged.

The diff command splits off into several sub-functions based on whether we're doing an index-to-file diff, an index-to-tree diff, etc. It looks like builtin_diff_files() and builtin_diff_index() just handle this case differently. Probably both should issue an error() mentioning the unknown option _and_ call usage().

I started on a patch, but maybe this would be good micro-project for somebody wanting to get their feet wet with contributing to Git. Bonus points for checking the other functions (builtin_diff_blobs, builtin_diff_tree, builtin_diff_b_f) and making sure they all give appropriate messages when showing the usage string.

-Peff
Previous: Simon Ruderich
Message 2 of 2 in “No "invalid option" message with git diff --cached --invalid-option”
  1. Simon RuderichJun 22, 2017
  2. Jeff KingJun 22, 2017

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.