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

Re: Git Submodules ref setting

From
Junio C Hamano <gitster@pobox.com>
Date
May 13, 2022, 15:22 UTC
Message-ID
<xmqqwnepbgof.fsf@gitster.g>
In-Reply-To
<88fa7138-cb3f-ab88-525c-198396b0a262@gmail.com>
Philippe Blain <levraiphilippeblain@gmail.com> writes:
> Yes, it was a deliberate design choice to have a deterministic state
> of a repository using submodules upon 'git clone'. Recording a submodule
> at a specific branch instead of at a specific commit would make this design
> choice impossible to achieve.

The above sentences are all correct, but it answers a slightly different question, I think.

I suspect that Vadim wanted to see if it is desirable to point at a non-branch ref with "submodule.<name>.branch" entry (or invent a new "submodule.<name>.ref" entry) in the ".gitmodules" file.

While the answer to that question is "probably not", to understand why, your answer helps ;-).

The "submodule.<name>.branch" entry hints the name of the branch to be used in the named submodule while working on submodule changes meant to go with the change that will be made to the superproject.

It is expected that the workflow goes like this:
 * A contributor checks out branch X of the superproject, which
   binds another project whose name is N as its submodule at path P.
   In the tree of the commit at the tip of branch X in the
   superproject, a concrete commit C in the submodule is recorded
   at that path.
 * The .gitmodules file found in that superproject checkout may
   record submodule.N.branch with value Y.  The commit C should be
   checked out in the submodule.
 * The contributor works on something that involves both the
   superproject and the submodule.  Perhaps the new feature in the
   superproject requires an enhanced version of the submodule, so
   there is an dependency.  New commits are added on top of C in the
   submodule, and branch Y is advanced.  The commit at the tip of
   that branch is recorded in the superproject's tree, and together
   with the changes in the superproject that use the modified
   submodule advance the branch X of the superproject.
 * The contributor shares the work with other participants by
   pushing branch X of the superproject and branch Y of the
   submodule.  There may be other branches that may be pushed out
   "while at it", but at least these two need to be pushed out.

For this workflow to work, it is necessary, as you said, that an exact commit is recorded in the tree of the superproject. We can guarantee a correct build of the superproject at commit at the updated tip of branch X, because we know which submodule commit needs to go with it.

But it is not sufficient. The history in the submodule needs to be manageable---the contributors who cloned the superproject and the submodule need to check out a commit to work on and extend their histories, and while it is possible to work always on detached HEAD, at the place where contributors meet with their work, i.e. the repository their changes were pushed in the last step in the above sequence, there needs _some_ ref. It is possible to use a non-branch ref for that, but because the contributors have to check that ref out after cloning and fetching the submodule, it makes little sense not to require that ref to be a proper branch that can be checked out (instead of merely giving a starting point of an unnamed branch, aka detached HEAD).

And that is why "remote.<name>.branch" is there and it is not "remote.<name>.ref".

Previous: Philip Oakley
Message 5 of 5 in “Git Submodules ref setting”
  1. Вадим ЦветковMay 12, 2022
  2. Philip OakleyMay 12, 2022
  3. Philippe BlainMay 12, 2022
  4. Philip OakleyMay 13, 2022
  5. Junio C HamanoMay 13, 2022

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.