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

Re: [PATCH 1/3] checkout.c: add strict usage of -- before file_path

From
Kevin Daudt <me@ikke.info>
Date
May 13, 2018, 21:02 UTC
Message-ID
<20180513210233.GA18892@alpha>
In-Reply-To
<1526178214-30956-1-git-send-email-danniercl@gmail.com>
On Sat, May 12, 2018 at 08:23:32PM -0600, Dannier Castro L wrote:
Show 29 quoted lines
> Currently, <checkout> is a complex command able to handle both
> branches and files without any distintion other than their names,
> taking into account that depending on the type (branch or file),
> the functionality is completely different, the easier example:
> 
> $ git checkout <branch>  # Switch from current branch to <branch>.
> $ git checkout <file>    # Restore <file> from HEAD, discarding
>                          # changes if it's necessary.
> $ git checkout -- <file> # The same as the last one, only with an
>                          # useless '--'.
> 
> For GIT new users, this complicated versatility of <checkout> could
> be very confused, also considering that actually the flag '--' is
> completely useless (added or not, there is not any difference for
> this command), when the same program messages promote the use of
> this flag.
> 
> Regarding the <checkout>'s power to overwrite any file, discarding
> changes if they exist without some way of recovering them, the
> solution propuses that the usage of '--' is strict before to
> specify the file(s) path(s) for any <checkout> command (including
> all types of flags), as a "defense barrier" to make sure about
> user's knowledge and intension running <checkout>.
> 
> The solution consists in detect '--' into command args, allowing
> the discard of changes and considering the following names as
> file paths, otherwise, they are branch names.
> 
> Signed-off-by: Dannier Castro L <danniercl@gmail.com>

One data point indicating this is giving issues is that today on IRC a user was confused why `git checkout pt` did not show any message and did not checkout a remote branch called 'pt' as they expected. It turned out they also had a local file/dir called 'pt', which caused git to checkout that file/dir rather than creating a local branch based on the remote branch.

Kevin
Previous: Junio C HamanoNext: Duy Nguyen
Message 9 of 11 in “checkout.c: add strict usage of -- before file_path”
  1. 1/3 checkout.c: add strict usage of -- before file_pathDannier Castro L, May 13, 2018
  2. 2/3 test: update tests for strict usage of -- checkoutDannier Castro L, May 13, 2018
  3. 3/3 doc: update doc for strict usage of -- checkoutDannier Castro L, May 13, 2018
  4. Duy NguyenMay 13, 2018
  5. Dannier Castro LMay 13, 2018
  6. SZEDER GáborMay 13, 2018
  7. Philip OakleyMay 13, 2018
  8. Junio C HamanoMay 14, 2018
  9. Kevin DaudtMay 13, 2018
  10. Duy NguyenMay 14, 2018
  11. Duy NguyenMay 14, 2018

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.