{"thread":{"id":"46620","subject":"[bug] Git submodule command interprets switch as argument and switch","startedAt":"2017-08-18T05:20:44Z","lastAt":"2017-08-18T21:35:40Z","messageCount":4,"participants":["R0b0t1","Stefan Beller","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"326672","messageId":"CAAD4mYi24dHNhG1MFkPaeVv9P-9UN_FxSvZmX6XFHrfA7K0hoQ@mail.gmail.com","threadId":"46620","inReplyTo":null,"subject":"[bug] Git submodule command interprets switch as argument and switch","fromName":"R0b0t1","fromEmail":"r030t1@gmail.com","sentAt":"2017-08-18T05:16:53Z","receivedAt":"2017-08-18T05:20:44Z","isPatch":false,"sender":{"key":"r030t1@gmail.com","avatar":null},"body":"The issue is as follows:\n\nR0b0t1@host:~/devel/project$ git submodule add\nhttps://github.com/user/project -f\nCloning into '/home/R0b0t1/devel/project/-f'...\n\nMy .gitignore's first line is *, and then I explicitly allow things.\nDespite the presence of \"project/\" in the .gitignore the submodule\ncommand says it is ignored. The \"force\" flag is interpreted as a flag\nand also as the destination directory.\n\nIt is possible the argument parsing code for other commands exhibits this error.\n\nR0b0t1.\n"},{"id":"326715","messageId":"CAGZ79kb+zuUNNTUb6y9ramEChc5N+vE1mXVxFHEWv6zamEnw7w@mail.gmail.com","threadId":"46620","inReplyTo":"CAAD4mYi24dHNhG1MFkPaeVv9P-9UN_FxSvZmX6XFHrfA7K0hoQ@mail.gmail.com","subject":"Re: [bug] Git submodule command interprets switch as argument and switch","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-08-18T19:33:26Z","receivedAt":"2017-08-18T19:33:32Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Aug 17, 2017 at 10:16 PM, R0b0t1 <r030t1@gmail.com> wrote:\n> The issue is as follows:\n>\n> R0b0t1@host:~/devel/project$ git submodule add\n> https://github.com/user/project -f\n> Cloning into '/home/R0b0t1/devel/project/-f'...\n>\n> My .gitignore's first line is *, and then I explicitly allow things.\n> Despite the presence of \"project/\" in the .gitignore the submodule\n> command says it is ignored.\n\nThat might indicate that another submodule command doesn't\ncope with submodule names that look like a common flag.\n\n> The \"force\" flag is interpreted as a flag\n> and also as the destination directory.\n>\n> It is possible the argument parsing code for other commands exhibits this error.\n\nYes, though these other commands are in C, not in shell.\nNote that Prathamesh is currently porting the \"git submodule\"\ncommand to C, which would allow us to fix this bug easily.\n\nAlso note that the -f is ambigious, what if the user meant\nto have the submodule at path \"-f\" ? (This issue comes\nup in many other commands, for example when a path\nand a branch name is accepted, the path of a potentially\ndeleted file.\n\nTo solve this git accepts a double dash, which signals git\nthat anything after the double dash there are arguments not\nto be interpreted as a command line flag.\n\n\n>\n> R0b0t1.\n"},{"id":"326718","messageId":"20170818203858.GK13924@aiede.mtv.corp.google.com","threadId":"46620","inReplyTo":"CAAD4mYi24dHNhG1MFkPaeVv9P-9UN_FxSvZmX6XFHrfA7K0hoQ@mail.gmail.com","subject":"Re: [bug] Git submodule command interprets switch as argument and switch","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2017-08-18T20:38:58Z","receivedAt":"2017-08-18T20:39:06Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nR0b0t1 wrote:\n\n> The issue is as follows:\n>\n> R0b0t1@host:~/devel/project$ git submodule add\n> https://github.com/user/project -f\n> Cloning into '/home/R0b0t1/devel/project/-f'...\n\nThanks for reporting.  Confusingly, I think this is intended behavior.\n\"git help submodule\" explains:\n\n\tadd [-b <branch>] [-f|--force] [--name <name>]\n\t\t[--reference <repository>] [--depth <depth>] [--]\n\t\t<repository> [<path>]\n\n\t\tAdd the given repository as a submodule at the given\n\t\tpath [etc]\n\nSince the -f comes after <repository>, it is a <path>.\n\nThat said, there are a few related things wrong here.\n\nThe usage string above says I can put \"--\" before the <repository> to\nmake things extra unambiguous.  But when I try that, I get the following\nresult:\n\n\t$ git submodule add -- https://gerrit.googlesource.com/gerrit -f\n\tCloning into '/tmp/t/test/-f'...\n[...]\n\tResolving deltas: 100% (215796/215796), done.\n\t/usr/lib/git-core/git-submodule: line 261: cd: -f: invalid option\n\tcd: usage: cd [-L|[-P [-e]] [-@]] [dir]\n\tUnable to checkout submodule '-f'\n\nIf I try to put the \"--\" between <repository> and <path>, I get another\nconfusing result:\n\n\t$ git submodule add https://gerrit.googlesource.com/gerrit -- -f\n\t'--' already exists in the index\n\n\"git help cli\" is supposed to give advice about this kind of thing as\nwell --- e.g., it gives some sound advice about what form of flags\nscripts should use (e.g., to always use the 'stuck' form --name=<name>\ninstead of --name name).  But it doesn't mention this issue of flags\nbelonging before other arguments.\n\nThoughts?\n\nThanks,\nJonathan\n"},{"id":"326720","messageId":"CAAD4mYhYWa=gB3ZG=Mepx2C+GO_ku7m2Zn6rL2paQBsVK6ya6A@mail.gmail.com","threadId":"46620","inReplyTo":"20170818203858.GK13924@aiede.mtv.corp.google.com","subject":"Re: [bug] Git submodule command interprets switch as argument and switch","fromName":"R0b0t1","fromEmail":"r030t1@gmail.com","sentAt":"2017-08-18T21:35:34Z","receivedAt":"2017-08-18T21:35:40Z","isPatch":false,"sender":{"key":"r030t1@gmail.com","avatar":null},"body":"On Fri, Aug 18, 2017 at 3:38 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Hi,\n>\n> R0b0t1 wrote:\n>\n>> The issue is as follows:\n>>\n>> R0b0t1@host:~/devel/project$ git submodule add\n>> https://github.com/user/project -f\n>> Cloning into '/home/R0b0t1/devel/project/-f'...\n>\n> Thanks for reporting.  Confusingly, I think this is intended behavior.\n> \"git help submodule\" explains:\n>\n>         add [-b <branch>] [-f|--force] [--name <name>]\n>                 [--reference <repository>] [--depth <depth>] [--]\n>                 <repository> [<path>]\n>\n>                 Add the given repository as a submodule at the given\n>                 path [etc]\n>\n> Since the -f comes after <repository>, it is a <path>.\n>\n\nNot to comment on every response to this bug, but I understand. What\nis confusing is that the command was failing without being forced, and\nwithout thinking I added \"-f\" at the end. The command succeeded as if\nI supplied the force flag, but per my experience with other tools, and\nwith other Git commands, \"-f\" should not be a flag. It should be a\npath, as you say. However it appears to be both.\n\nTo reproduce my situation exactly, add \"*\" to your .gitignore. The\ndirectory \"gerrit\" should then be ignored, and Git will warn you that\nthe submodule will not be tracked (I may have another issue to report\nrelated to this, but I'm still trying to figure out what is going on).\nHowever, if you name the directory something else, like \"-f\", it will\nstill be matched by the .gitignore rule and should not succeed. This\nis why I think the path is also being interpreted as a flag.\n\nSomething else may be happening, but either way the behavior does not\nseem to be expected nor consistent with other parts of Git.\n\n> That said, there are a few related things wrong here.\n>\n> The usage string above says I can put \"--\" before the <repository> to\n> make things extra unambiguous.  But when I try that, I get the following\n> result:\n>\n>         $ git submodule add -- https://gerrit.googlesource.com/gerrit -f\n>         Cloning into '/tmp/t/test/-f'...\n> [...]\n>         Resolving deltas: 100% (215796/215796), done.\n>         /usr/lib/git-core/git-submodule: line 261: cd: -f: invalid option\n>         cd: usage: cd [-L|[-P [-e]] [-@]] [dir]\n>         Unable to checkout submodule '-f'\n>\n> If I try to put the \"--\" between <repository> and <path>, I get another\n> confusing result:\n>\n>         $ git submodule add https://gerrit.googlesource.com/gerrit -- -f\n>         '--' already exists in the index\n>\n> \"git help cli\" is supposed to give advice about this kind of thing as\n> well --- e.g., it gives some sound advice about what form of flags\n> scripts should use (e.g., to always use the 'stuck' form --name=<name>\n> instead of --name name).  But it doesn't mention this issue of flags\n> belonging before other arguments.\n>\n> Thoughts?\n>\n\nI have experienced issues with -- before. It has been long enough I\nhave forgotten. Sorry for not being able to provide anything concrete.\n"}]}