{"thread":{"id":"48481","subject":"Re: [PATCH 1/3] checkout.c: add strict usage of -- before file_path","startedAt":"2018-05-13T16:52:35Z","lastAt":"2018-05-13T16:52:35Z","messageCount":1,"participants":["Matthieu Moy"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"347547","messageId":"191675463.13930902.1526230351223.JavaMail.zimbra@inria.fr","threadId":"48481","inReplyTo":"9e3a36eea5d34dc2941560b96046dc27@BPMBX2013-01.univ-lyon1.fr","subject":"Re: [PATCH 1/3] checkout.c: add strict usage of -- before file_path","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@univ-lyon1.fr","sentAt":"2018-05-13T16:52:31Z","receivedAt":"2018-05-13T16:52:35Z","isPatch":true,"sender":{"key":"matthieu.moy@univ-lyon1.fr","avatar":"https://gravatar.com/avatar/8ab83b763226bd297b59ddd1463a8bfc852924577191233f73a953b86888fe0c?d=mp&s=160"},"body":"\"Dannier Castro L\" <danniercl@gmail.com> wrote:\n\n> Currently, <checkout> is a complex command able to handle both\n> branches and files without any distintion other than their names,\n> taking into account that depending on the type (branch or file),\n> the functionality is completely different, the easier example:\n> \n> $ git checkout <branch>  # Switch from current branch to <branch>.\n> $ git checkout <file>    # Restore <file> from HEAD, discarding\n>                         # changes if it's necessary.\n> $ git checkout -- <file> # The same as the last one, only with an\n>                         # useless '--'.\n\nIt's not really \"useless\".\n\nIn the first two commands you give, git guesses whether the first\nargument is a branch or a file. In the 3rd, the -- indicates that it\nmust be a file.\n\n> For GIT new users,\n\nNit: we write Git (for the system) or git (for the command-line tool),\nbut usually avoid the all-caps GIT.\n\n> The solution consists in detect '--' into command args, allowing\n> the discard of changes and considering the following names as\n> file paths, otherwise, they are branch names.\n\nThis answers the \"what?\" question, but does not explain why this is a\ngood change. A good commit message should focus more on the \"why?\"\nquestion.\n\nWhile I agree that \"git checkout\" is a complex command, and would love\nto see a simpler syntax at least for the most common operations, I do\nnot think that this is a good change for several reasons:\n\n* If one considers that this \"--\" syntax is an issue, then this patch\n  is a very partial solution only. Many other commands use the same\n  convention (for example \"git log <commit>\" Vs \"git log -- <file>\"),\n  so changing only one makes git less consistent. Also, note that this\n  \"--\" convention is not git-specific. Try \"touch --help\" and \"touch\n  -- --help\" for example.\n\n* This breaks backward compatibility. People used to \"git checkout\n  <file>\" won't be able to use it anymore. Scripts using it will\n  break. Git avoids breaking backward compatibility, and when there's\n  a good reason to do so we need a good transition plan. In this case,\n  one possible plan would be to 1) issue a warning whenever \"git\n  checkout <file>\" is used for a while, and then 2) actually forbid\n  it. But following this path, I don't think step 2) would actually be\n  useful.\n\n> @@ -928,6 +931,7 @@ static int parse_branchname_arg(int argc, const char **argv,\n> \tdash_dash_pos = -1;\n> \tfor (i = 0; i < argc; i++) {\n> \t\tif (!strcmp(argv[i], \"--\")) {\n> +\t\t\topts->discard_changes = 1;\n> \t\t\tdash_dash_pos = i;\n\nWouldn't \"dash_dash_pos != -1\" be enough to know whether there's a --?\n\n-- \nMatthieu Moy\nhttps://matthieu-moy.fr/\n"}]}