Re: git submodule add fails when using both --branch and --depth
From: Stefan Beller <hidden>
Date: 2017-10-02 19:55:23
On Sat, Sep 30, 2017 at 10:20 AM, Thadeus Fleming [off-list ref] 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 andquoted
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' Investigating further, there is indeed only one commit in the local repo:quoted
cd git-pu git log --oneline | wc -l1 But that commit is the head of master.quoted
git branch -a* master remotes/origin/master remotes/origin/HEAD -> origin/master This appears to be because git-submodule--helper does not accept a --branch option. Using the --depth N option causes it to only clone N commits from the default branch, which generally do not include the desired branch. Thus, the next step, git checkout -f -q -B "$branch" "origin/$branch" fails, and provides the rather confusing error message above. I'd suggest that git-submodule--helper learn a --branch option consistent with git clone, and if that is impossible, that git submodule add rejects the simultaneous use of both the --branch and --depth options.
Adding the branch field to the submodule helper is a great idea.
--tjf