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

Re: git submodule add fails when using both --branch and --depth

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 2, 2017, 22:08 UTC
Message-ID
<20171002220844.GQ19555@aiede.mtv.corp.google.com>
In-Reply-To
<CAA4Wa2sVddG_SS70Dy_womGLKW0ipAjsxR4g+yjMKscjErRjvQ@mail.gmail.com>
Hi,
Thadeus Fleming wrote:
Show 7 quoted lines
> I'm running git 2.14.2 on Ubuntu 16.04.
>
> Compare the behavior of
>
>> git clone --branch pu --depth 1 https://github.com/git/git git-pu
>
> which clones only the latest commit of the pu branch and
Yes.
Show 8 quoted lines
>> mkdir tmp && cd tmp && git init
>> git submodule add --branch pu --depth 1 https://github.com/git/git \
>  git-pu
>
> which gives the error
>
> fatal: 'origin/pu' is not a commit and a branch 'pu' cannot be created from it
> Unable to checkout submodule 'git-pu'

As a side note (you are using "git submodule add --depth", not "git submodule update --depth"), I suspect that "submodule update --depth" may not always do what people expect.

With add --depth, I agree with your expectation and after your fix everything should work fine. But with update --depth, consider the following sequence of steps:

 1. I create a repository "super" with submodule "sub" and publish
    both.
 2. I make a couple commits to "sub" and a commit to "super" making
    use of those changes and want to publish them.
 3. I use "git push --recurse-submodules" to publish my commits to
    "sub" and "super":
    a. First it pushes to "sub".
    b. Then it pushes to "super".

Between steps 3(a) and 3(b), a person can still "git clone --recurse-submodules" the "super" repository. The repository "super" does not have my change yet and "sub" does, but that is not a problem, since commands like "git checkout --recurse-submodules" and "git submodule update" know to check out the commit *before* my change in the submodule.

But between steps 3(a) and 3(b), "git submodule update --depth=1" would not work. It would fetch the submodule with depth 1 and then try to check out a commit that is deeper in history.

So I think there's more thinking needed there.
That's all a tangent to your report about add --depth, though.

Thanks, Jonathan

Previous: Stefan Beller
Message 3 of 3 in “git submodule add fails when using both --branch and --depth”
  1. Thadeus FlemingSep 30, 2017
  2. Stefan BellerOct 2, 2017
  3. Jonathan NiederOct 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.