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

Re: [PATCH] checkout: teach --worktree

From
Denton Liu <liu.denton@gmail.com>
Date
Jun 14, 2020, 08:02 UTC
Message-ID
<20200614080254.GA1202945@generichostname>
In-Reply-To
<20200614074439.GA617439@generichostname>
On Sun, Jun 14, 2020 at 03:44:39AM -0400, Denton Liu wrote:
Show 24 quoted lines
> Hi Eric,
> 
> On Sat, Jun 13, 2020 at 10:51:47PM -0400, Eric Sunshine wrote:
> > On Sat, Jun 13, 2020 at 10:25 AM Denton Liu <liu.denton@gmail.com> wrote:
> > > [...]
> > > Teach `git checkout --worktree`, allowing users to checkout files
> > > directly into the worktree without affecting the index.
> > >
> > > Signed-off-by: Denton Liu <liu.denton@gmail.com>
> > > ---
> > > diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
> > > @@ -264,6 +266,12 @@ When switching branches with `--merge`, staged changes may be lost.
> > > +-W::
> > > +--worktree::
> > > +       When writing contents, only modify files in the worktree. Do not
> > > +       modify the index. This option is essentially a no-op when used
> > > +       without a `<tree-ish>`.
> > 
> > Why a no-op rather than actually diagnosing that --worktree makes no
> > sense in that case and erroring out?
> 
> I decided on this behaviour because I assumed that an empty
> `git checkout` has `git restore` behaviour but I guess I was mistaken.
> I'll change it to error out.
...Disregard the above. I misread your comments.

I thought about it some more and I think that the real bug is in how I phrased it in the documentation. I meant that --worktree itself was essentially no-op, not the whole checkout operation.

I think that it makes sense to allow this behaviour. The documentation states that we only modify files in the worktree. So if we do `git checkout --worktree <path>`, we should overwrite the worktree with the index. This should be exactly the same as running `git checkout <path>`.

However, one additonal behaviour I should implement is running `git checkout --worktree` should behave like running `git checkout .`. So this would make --worktree not a no-op without a tree-ish.

Previous: Denton LiuNext: Junio C Hamano
Message 4 of 9 in “checkout: teach --worktree”
  1. checkout: teach --worktreeDenton Liu, Jun 13, 2020
  2. Eric SunshineJun 14, 2020
  3. Denton LiuJun 14, 2020
  4. Denton LiuJun 14, 2020
  5. Junio C HamanoJun 14, 2020
  6. checkout: teach --worktreeDenton Liu, Jun 14, 2020
  7. Phillip WoodJun 16, 2020
  8. Denton LiuJun 23, 2020
  9. Phillip WoodJun 24, 2020

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.