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

Re: [RFC/PATCH] worktree: replace "checkout --to" with "worktree new"

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 2, 2015, 18:45 UTC
Message-ID
<CAPig+cR2tn6G0N1sSsrkP_Lo_U_hjLYi08qEsMr+gcsjheaX7A@mail.gmail.com>
In-Reply-To
<CAPig+cT=U6LxpJuUMaCd-x=gQPvh89SDNUo12+2_3uYb_q3=Og@mail.gmail.com>
On Wed, Jul 1, 2015 at 10:52 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 20 quoted lines
> However, there are still a few bits of
> code which want to know that the checkout is happening in a new
> worktree. I haven't examined them closely yet to diagnose if this
> specialized knowledge can be eliminated. Perhaps you can weight in. In
> particular:
>
> checkout_paths:
>     if (opts->new_worktree)
>         die(_("'%s' cannot be used with updating paths"), "--to");
>
> merge_working_tree:
>     tree = parse_tree_indirect(old->commit &&
>         !opts->new_worktree_mode ?
>             old->commit->object.sha1 :
>             EMPTY_TREE_SHA1_BIN);
>
> switch_branches:
>     if (!opts->quiet && !old.path && old.commit &&
>         new->commit != old.commit && !opts->new_worktree_mode)
>             orphaned_commit_warning(old.commit, new->commit);

There's another instance: 3473ad0 (checkout: don't require a work tree when checking out into a new one, 2014-11-30) added this:

    if (!new_worktree)
        setup_work_tree();
which the "worktree add" patch changed to:
    setup_work_tree();

which doesn't hurt (since setup_work_tree() protects itself against multiple invocations) but isn't semantically clean. If I understand correctly, I think a better approach would be to move the setup_work_tree() call to worktree.c just before it invokes git-checkout, and revert 3473ad0 entirely (including this bit):

    - { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
    +{ "checkout", cmd_checkout, RUN_SETUP },
so that git-checkout once again requires a worktree.
Previous: Eric SunshineNext: Eric Sunshine
Message 25 of 27 in “worktree: replace "checkout --to" with "worktree new"”
  1. worktree: replace "checkout --to" with "worktree new"Eric Sunshine, Jun 30, 2015
  2. Duy NguyenJun 30, 2015
  3. Junio C HamanoJun 30, 2015
  4. Duy NguyenJul 1, 2015
  5. Eric SunshineJun 30, 2015
  6. Eric SunshineJul 1, 2015
  7. Junio C HamanoJun 30, 2015
  8. Eric SunshineJun 30, 2015
  9. Junio C HamanoJun 30, 2015
  10. Mikael MagnussonJul 1, 2015
  11. Mark LevedahlJun 30, 2015
  12. Junio C HamanoJul 1, 2015
  13. Eric SunshineJul 1, 2015
  14. Eric SunshineJul 1, 2015
  15. Junio C HamanoJul 1, 2015
  16. Eric SunshineJul 1, 2015
  17. Junio C HamanoJul 1, 2015
  18. Duy NguyenJul 2, 2015
  19. Eric SunshineJul 2, 2015
  20. Duy NguyenJul 2, 2015
  21. Duy NguyenJul 2, 2015
  22. Eric SunshineJul 2, 2015
  23. Duy NguyenJul 2, 2015
  24. Eric SunshineJul 2, 2015
  25. Eric SunshineJul 2, 2015
  26. Eric SunshineJul 2, 2015
  27. Eric SunshineJul 2, 2015

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.