Re: git submodule add fails when using both --branch and --depth
From: Jonathan Nieder <hidden>
Date: 2017-10-02 22:08:53
Hi, Thadeus Fleming wrote:
I'm running git 2.14.2 on Ubuntu 16.04. Compare the behavior ofquoted
git clone --branch pu --depth 1 https://github.com/git/git git-puwhich clones only the latest commit of the pu branch and
Yes.
quoted
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