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

Re: [PATCH 0/5] Some submodule bugfixes and "reattaching detached HEADs"

From
Junio C Hamano <gitster@pobox.com>
Date
May 2, 2017, 01:35 UTC
Message-ID
<xmqqbmrcf3cn.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170501182405.GG39135@google.com>
Brandon Williams <bmwill@google.com> writes:
> I don't know why submodules were originally designed to be in a
> detached HEAD state but I much prefer working on branches (as I'm sure
> many other developers do) so the prospect of this becoming the norm is
> exciting! :D

The reason is because the superproject already records where the HEAD in the submodule should be, when any of its commits is checked out. The tip of a branch (which one???) in a submodule may match that commit, in which case there is nothing gained by having you on that branch, or it may not match that commit, in which case it is unclear what should happen. Leaving your submodule on the branch would mean the state of your tree as a whole does not match what the checkout operation in the superproject wanted to create. Resetting the branch would mean you may lose the history of the branch.

Thinking of the detached HEAD state as an implicit unnamed branch that matches the state the superproject checkout expects was conceptually one of the cleanest choices.

But all of the above concentrates on what should happen immediately after you do a checkout in the superproject, and it would be OK for a sight-seer. Once you want to work in the submodules to build on their histories, not being on a branch does become awkward. For one thing, after you are done with the work in your submodule, you would want to update the superproject and make a commit that records the commit in the submodule, and then you would want to publish both the superproject and the submodule because both of them are now updated. The commit in the superproject may be on the branch that is currently checked out, but we don't know what branch the commit in the submoudule should go.

The submodule.<name>.branch configuration may be a good source to learn that piece of information, but it does not fully solve the issue. It is OK for the tip of that branch to be at or behind the commit the superproject records, but it is unclear what should happen if the local tip of that branch is ahead of the commit in the superproject when checkout happens.

By the way, how does this topic work with the various checkout modes that can be specified with submodule.<name>.update?

Previous: Brandon WilliamsNext: Stefan Beller
Message 15 of 22 in “Some submodule bugfixes and "reattaching detached HEADs"”
  1. 0/5 Some submodule bugfixes and "reattaching detached HEADs"Stefan Beller, May 1, 2017
  2. 1/5 submodule_move_head: fix leak of struct child_processStefan Beller, May 1, 2017
  3. Brandon WilliamsMay 1, 2017
  4. Junio C HamanoMay 2, 2017
  5. Stefan BellerMay 2, 2017
  6. 3/5 submodule: avoid auto-discovery in new working tree manipulator codeStefan Beller, May 1, 2017
  7. 2/5 submodule_move_head: prepare env for child correctlyStefan Beller, May 1, 2017
  8. Junio C HamanoMay 2, 2017
  9. Stefan BellerMay 2, 2017
  10. 4/5 submodule--helper: reattach-HEADStefan Beller, May 1, 2017
  11. Brandon WilliamsMay 1, 2017
  12. Stefan BellerMay 1, 2017
  13. 5/5 submodule_move_head: reattach submodule HEAD to branch if possible.Stefan Beller, May 1, 2017
  14. Brandon WilliamsMay 1, 2017
  15. Junio C HamanoMay 2, 2017
  16. Stefan BellerMay 2, 2017
  17. Stefan BellerMay 31, 2017
  18. 0/3 Some submodule bugfixesStefan Beller, May 2, 2017
  19. 1/3 submodule_move_head: reuse child_process structure for futher commandsStefan Beller, May 2, 2017
  20. 2/3 submodule: avoid auto-discovery in new working tree manipulator codeStefan Beller, May 2, 2017
  21. 3/3 submodule: properly recurse for read-tree and checkoutStefan Beller, May 2, 2017
  22. Brandon WilliamsMay 2, 2017

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.