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

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

From
TFThadeus Fleming <thadeus.j.fleming@gmail.com>
Date
Sep 30, 2017, 17:20 UTC
Message-ID
<CAA4Wa2sVddG_SS70Dy_womGLKW0ipAjsxR4g+yjMKscjErRjvQ@mail.gmail.com>
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
> 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:
> cd git-pu
> git log --oneline | wc -l
1
But that commit is the head of master.
> 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.

--tjf
Next: Stefan Beller
Message 1 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.