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

Re: [PATCH] checkout & worktree: introduce a core.DWIMRemote setting

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 4, 2018, 07:14 UTC
Message-ID
<CAPig+cSRBBzXDWMJd5k=ZGOt_ayATWB6fZQrcMqJkP8ja4Tq+g@mail.gmail.com>
In-Reply-To
<87y3h1ykwn.fsf@evledraar.gmail.com>

On Wed, May 2, 2018 at 2:25 PM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 17 quoted lines
> On Wed, May 02 2018, Eric Sunshine wrote:
>> A few observations:
>>
>> 1. DWIM has broad meaning; while this certainly falls within DWIM,
>> it's also just a _default_, so should this instead be named
>> "defaultRemote"?
>>
>> 2. Building on #1: How well is the term "DWIM" understood by non-power
>> users? A term, such as "default" is more well known.
>
> I've got no love for the DWIM term. And I think I should change it in
> v2, I just want some way to enable this functionality since this
> behavior has annoyed me for a long time.
>
> I wonder though if something like "core.defaultRemote" might not bring
> up connotations about whether this would e.g. affect "push" in the minds
> of users (not that my initial suggestion is better).
A reasonable concern.
> So maybe something like checkout.implicitRemote would be better? And we
> could just break the rule that only git-checkout would use it, since
> git-worktree could be said to be doing something checkout-like, or just
> also add a worktree.implicitRemote.

Considering that git-worktree runs the post-checkout hook, it seems pretty safe to say that it does something checkout-like.

Personally, I find "defaultRemote" easier to understand than "implicitRemote", but I suppose I can see your reasoning for choosing "implicit". Whereas "default" is something to "fall back upon" when something is missing, "implicit" suggests what to choose when a something has not been specified explicitly.

Show 21 quoted lines
>> 3. git-worktree learned --guess-remote and worktree.guessRemote in [1]
>> and [2], which, on the surface, sound confusingly similar to
>> "DWIMRemote". Even though I was well involved in the discussion and
>> repeatedly reviewed the patch series which introduced those, it still
>> took me an embarrassingly long time, and repeated re-reads of all
>> commit messages involved, to grasp (or re-grasp) how "guess remote"
>> and "DWIM remote" differ. If it was that difficult for me, as a person
>> involved in the patch series, to figure out "guess remote" vs. "DWIM
>> remote", then I worry that it may be too confusing in general. If the
>> new config option had been named "defaultRemote", I don't think I'd
>> have been confused at all.
>
> I hadn't looked at this at all before today when I wrote the patch, and
> I've never used git-worktree (but maybe I should...), but my
> understanding of this --[no-]guess-remote functionality is that it
> effectively splits up the functionality that the "git checkout" does,
> and we'll unconditionally check out the branch, but the option controls
> whether or not we'd set up the equivalent of remote tracking for
> git-worktree.
>
> But maybe I've completely misunderstood it.
Yes, you misunderstood it.

The setting up of a remote-tracking branch is DWIM'd as of 4e85333197 ("worktree: make add <path> <branch> dwim", 2017-11-26); it doesn't require an explicit option to enable it (though tracking can be disabled via --no-track). The "guess-remote" feature does something entirely different; it was added to avoid backward compatibility problems.

In long-form:
    git worktree add <path> <branch>

adds a new worktree at <path> and checks out <branch>. As originally implemented, shortened:

    git worktree add <path>

does one type of DWIM, as a convenience, and pretends that the user actually typed:

    branch=$(basename <path>)
    git branch $branch HEAD
    git workree add <path> $branch

which creates a new branch and then checks it out in the new worktree as usual. The "guess remote" feature which Thomas added augments that by adding a DWIM which checks if $(basename <path>) names a remote-tracking branch, in which case, it becomes shorthand for (something like):

    branch=$(basename <path>)
    if remote-tracking branch named $branch exists:
        git branch --track $branch $guessedRemote/$branch
    else:
        git branch $branch HEAD
    fi
    git worktree add <path> $branch

In retrospect, this DWIM-checking for a like-named remote-tracking branch should have been implemented from the start in git-worktree since it mirrors how "git checkout <branch>" will DWIM remote-tracking <remote>/<branch>. However, such DWIM'ing was overlooked and git-worktree existed long enough without it that, due to backward compatibility concerns, the new DWIM'ing got hidden behind a switch, hence --guess-remote ("worktree.guessRemote") to enable it.

Unrelated: Thomas added another DWIM, which we just finalized a few
days ago, which extends the shorthand "git worktree add <path>" to
first check if a local branch named $(basename <path>) already exists
and merely check that out into the new worktree rather than trying to
create a new branch of that name (which is another obvious DWIM missed
during initial implementation). In other words:
    branch=$(basename <path>)
    if local branch named $branch does _not_ exist:
        if remote-tracking branch named $branch exists:
            git branch --track $branch $guessedRemote/$branch
        else:
            git branch $branch HEAD
        fi
    fi
    git worktree add <path> $branch
Previous: Ævar Arnfjörð BjarmasonNext: Eric Sunshine
Message 94 of 95 in “checkout & worktree: introduce a core.DWIMRemote setting”
  1. checkout & worktree: introduce a core.DWIMRemote settingÆvar Arnfjörð Bjarmason, May 2, 2018
  2. Duy NguyenMay 2, 2018
  3. Eric SunshineMay 2, 2018
  4. Duy NguyenMay 2, 2018
  5. Ævar Arnfjörð BjarmasonMay 2, 2018
  6. checkout & worktree: introduce checkout.implicitRemoteÆvar Arnfjörð Bjarmason, May 3, 2018
  7. Duy NguyenMay 3, 2018
  8. Ævar Arnfjörð BjarmasonMay 4, 2018
  9. Duy NguyenMay 4, 2018
  10. Ævar Arnfjörð BjarmasonMay 4, 2018
  11. Eric SunshineMay 4, 2018
  12. checkout & worktree: introduce checkout.implicitRemoteÆvar Arnfjörð Bjarmason, May 24, 2018
  13. Junio C HamanoMay 25, 2018
  14. Duy NguyenMay 25, 2018
  15. Ævar Arnfjörð BjarmasonMay 25, 2018
  16. Duy NguyenMay 26, 2018
  17. Ævar Arnfjörð BjarmasonMay 31, 2018
  18. 0/9 ambiguous checkout UI & checkout.defaultRemoteÆvar Arnfjörð Bjarmason, May 31, 2018
  19. 1/9 checkout tests: index should be clean after dwim checkoutÆvar Arnfjörð Bjarmason, May 31, 2018
  20. Junio C HamanoJun 1, 2018
  21. Ævar Arnfjörð BjarmasonJun 1, 2018
  22. 2/9 checkout.h: wrap the arguments to unique_tracking_name()Ævar Arnfjörð Bjarmason, May 31, 2018
  23. 3/9 checkout.[ch]: move struct declaration into *.hÆvar Arnfjörð Bjarmason, May 31, 2018
  24. Thomas GummererMay 31, 2018
  25. Junio C HamanoJun 1, 2018
  26. Ævar Arnfjörð BjarmasonJun 1, 2018
  27. 4/9 checkout.[ch]: introduce an *_INIT macroÆvar Arnfjörð Bjarmason, May 31, 2018
  28. Junio C HamanoJun 1, 2018
  29. 5/9 checkout.[ch]: change "unique" member to "num_matches"Ævar Arnfjörð Bjarmason, May 31, 2018
  30. 7/9 builtin/checkout.c: use "ret" variable for returnÆvar Arnfjörð Bjarmason, May 31, 2018
  31. 6/9 checkout: pass the "num_matches" up to callersÆvar Arnfjörð Bjarmason, May 31, 2018
  32. 9/9 checkout & worktree: introduce checkout.defaultRemoteÆvar Arnfjörð Bjarmason, May 31, 2018
  33. Stefan BellerMay 31, 2018
  34. Eric SunshineJun 1, 2018
  35. Ævar Arnfjörð BjarmasonJun 1, 2018
  36. Thomas GummererMay 31, 2018
  37. Junio C HamanoJun 1, 2018
  38. 8/9 checkout: add advice for ambiguous "checkout <branch>"Ævar Arnfjörð Bjarmason, May 31, 2018
  39. Junio C HamanoJun 1, 2018
  40. Junio C HamanoJun 1, 2018
  41. Ævar Arnfjörð BjarmasonJun 1, 2018
  42. Junio C HamanoJun 4, 2018
  43. Ævar Arnfjörð BjarmasonJun 1, 2018
  44. Eric SunshineJun 1, 2018
  45. Ævar Arnfjörð BjarmasonJun 1, 2018
  46. 0/8 ambiguous checkout UI & checkout.defaultRemoteÆvar Arnfjörð Bjarmason, Jun 1, 2018
  47. 1/8 checkout tests: index should be clean after dwim checkoutÆvar Arnfjörð Bjarmason, Jun 1, 2018
  48. 2/8 checkout.h: wrap the arguments to unique_tracking_name()Ævar Arnfjörð Bjarmason, Jun 1, 2018
  49. 3/8 checkout.[ch]: introduce an *_INIT macroÆvar Arnfjörð Bjarmason, Jun 1, 2018
  50. Eric SunshineJun 1, 2018
  51. 4/8 checkout.[ch]: change "unique" member to "num_matches"Ævar Arnfjörð Bjarmason, Jun 1, 2018
  52. Eric SunshineJun 1, 2018
  53. 6/8 builtin/checkout.c: use "ret" variable for returnÆvar Arnfjörð Bjarmason, Jun 1, 2018
  54. 5/8 checkout: pass the "num_matches" up to callersÆvar Arnfjörð Bjarmason, Jun 1, 2018
  55. 8/8 checkout & worktree: introduce checkout.defaultRemoteÆvar Arnfjörð Bjarmason, Jun 1, 2018
  56. 7/8 checkout: add advice for ambiguous "checkout <branch>"Ævar Arnfjörð Bjarmason, Jun 1, 2018
  57. Eric SunshineJun 1, 2018
  58. 0/8 ambiguous checkout UI & checkout.defaultRemoteÆvar Arnfjörð Bjarmason, Jun 2, 2018
  59. 1/8 checkout tests: index should be clean after dwim checkoutÆvar Arnfjörð Bjarmason, Jun 2, 2018
  60. 2/8 checkout.h: wrap the arguments to unique_tracking_name()Ævar Arnfjörð Bjarmason, Jun 2, 2018
  61. 3/8 checkout.c: introduce an *_INIT macroÆvar Arnfjörð Bjarmason, Jun 2, 2018
  62. 4/8 checkout.c]: change "unique" member to "num_matches"Ævar Arnfjörð Bjarmason, Jun 2, 2018
  63. 6/8 builtin/checkout.c: use "ret" variable for returnÆvar Arnfjörð Bjarmason, Jun 2, 2018
  64. 5/8 checkout: pass the "num_matches" up to callersÆvar Arnfjörð Bjarmason, Jun 2, 2018
  65. 7/8 checkout: add advice for ambiguous "checkout <branch>"Ævar Arnfjörð Bjarmason, Jun 2, 2018
  66. 8/8 checkout & worktree: introduce checkout.defaultRemoteÆvar Arnfjörð Bjarmason, Jun 2, 2018
  67. Eric SunshineJun 3, 2018
  68. 0/8 ambiguous checkout UI & checkout.defaultRemoteÆvar Arnfjörð Bjarmason, Jun 5, 2018
  69. 1/8 checkout tests: index should be clean after dwim checkoutÆvar Arnfjörð Bjarmason, Jun 5, 2018
  70. SZEDER GáborJun 5, 2018
  71. tests: make use of the test_must_be_empty functionÆvar Arnfjörð Bjarmason, Jul 27, 2018
  72. Junio C HamanoJul 27, 2018
  73. SZEDER GáborJul 31, 2018
  74. t6018-rev-list-glob: fix 'empty stdin' testSZEDER Gábor, Aug 22, 2018
  75. Eric SunshineAug 22, 2018
  76. SZEDER GáborAug 22, 2018
  77. Eric SunshineAug 22, 2018
  78. Junio C HamanoAug 22, 2018
  79. Junio C HamanoAug 22, 2018
  80. Jeff KingAug 22, 2018
  81. rev-list: make empty --stdin not an errorJeff King, Aug 22, 2018
  82. Junio C HamanoAug 22, 2018
  83. Jeff KingAug 22, 2018
  84. Junio C HamanoAug 22, 2018
  85. Jeff KingAug 22, 2018
  86. Junio C HamanoAug 22, 2018
  87. 3/8 checkout.c: introduce an *_INIT macroÆvar Arnfjörð Bjarmason, Jun 5, 2018
  88. 2/8 checkout.h: wrap the arguments to unique_tracking_name()Ævar Arnfjörð Bjarmason, Jun 5, 2018
  89. 4/8 checkout.c: change "unique" member to "num_matches"Ævar Arnfjörð Bjarmason, Jun 5, 2018
  90. 6/8 builtin/checkout.c: use "ret" variable for returnÆvar Arnfjörð Bjarmason, Jun 5, 2018
  91. 7/8 checkout: add advice for ambiguous "checkout <branch>"Ævar Arnfjörð Bjarmason, Jun 5, 2018
  92. 8/8 checkout & worktree: introduce checkout.defaultRemoteÆvar Arnfjörð Bjarmason, Jun 5, 2018
  93. 5/8 checkout: pass the "num_matches" up to callersÆvar Arnfjörð Bjarmason, Jun 5, 2018
  94. Eric SunshineMay 4, 2018
  95. Eric SunshineMay 4, 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.