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

Re: [bug] Git submodule command interprets switch as argument and switch

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 18, 2017, 20:38 UTC
Message-ID
<20170818203858.GK13924@aiede.mtv.corp.google.com>
In-Reply-To
<CAAD4mYi24dHNhG1MFkPaeVv9P-9UN_FxSvZmX6XFHrfA7K0hoQ@mail.gmail.com>
Hi,
R0b0t1 wrote:
Show 5 quoted lines
> The issue is as follows:
>
> R0b0t1@host:~/devel/project$ git submodule add
> https://github.com/user/project -f
> Cloning into '/home/R0b0t1/devel/project/-f'...

Thanks for reporting. Confusingly, I think this is intended behavior. "git help submodule" explains:

	add [-b <branch>] [-f|--force] [--name <name>]
		[--reference <repository>] [--depth <depth>] [--]
		<repository> [<path>]
		Add the given repository as a submodule at the given
		path [etc]
Since the -f comes after <repository>, it is a <path>.
That said, there are a few related things wrong here.

The usage string above says I can put "--" before the <repository> to make things extra unambiguous. But when I try that, I get the following result:

	$ git submodule add -- https://gerrit.googlesource.com/gerrit -f
	Cloning into '/tmp/t/test/-f'...
[...]
	Resolving deltas: 100% (215796/215796), done.
	/usr/lib/git-core/git-submodule: line 261: cd: -f: invalid option
	cd: usage: cd [-L|[-P [-e]] [-@]] [dir]
	Unable to checkout submodule '-f'

If I try to put the "--" between <repository> and <path>, I get another confusing result:

	$ git submodule add https://gerrit.googlesource.com/gerrit -- -f
	'--' already exists in the index

"git help cli" is supposed to give advice about this kind of thing as well --- e.g., it gives some sound advice about what form of flags scripts should use (e.g., to always use the 'stuck' form --name=<name> instead of --name name). But it doesn't mention this issue of flags belonging before other arguments.

Thoughts?

Thanks, Jonathan

Previous: Stefan BellerNext: R0b0t1
Message 3 of 4 in “[bug] Git submodule command interprets switch as argument and switch”
  1. R0b0t1Aug 18, 2017
  2. Stefan BellerAug 18, 2017
  3. Jonathan NiederAug 18, 2017
  4. R0b0t1Aug 18, 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.