{"thread":{"id":"46864","subject":"git submodule add fails when using both --branch and --depth","startedAt":"2017-09-30T17:20:57Z","lastAt":"2017-10-02T22:08:53Z","messageCount":3,"participants":["Thadeus Fleming","Stefan Beller","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"329248","messageId":"CAA4Wa2sVddG_SS70Dy_womGLKW0ipAjsxR4g+yjMKscjErRjvQ@mail.gmail.com","threadId":"46864","inReplyTo":null,"subject":"git submodule add fails when using both --branch and --depth","fromName":"Thadeus Fleming","fromEmail":"thadeus.j.fleming@gmail.com","sentAt":"2017-09-30T17:20:50Z","receivedAt":"2017-09-30T17:20:57Z","isPatch":false,"sender":{"key":"thadeus.j.fleming@gmail.com","avatar":null},"body":"I'm running git 2.14.2 on Ubuntu 16.04.\n\nCompare the behavior of\n\n> git clone --branch pu --depth 1 https://github.com/git/git git-pu\n\nwhich clones only the latest commit of the pu branch and\n\n> mkdir tmp && cd tmp && git init\n> git submodule add --branch pu --depth 1 https://github.com/git/git \\\n  git-pu\n\nwhich gives the error\n\nfatal: 'origin/pu' is not a commit and a branch 'pu' cannot be created\nfrom it\nUnable to checkout submodule 'git-pu'\n\nInvestigating further, there is indeed only one commit in the local repo:\n\n> cd git-pu\n> git log --oneline | wc -l\n1\n\nBut that commit is the head of master.\n\n> git branch -a\n* master                                 remotes/origin/master\n  remotes/origin/HEAD -> origin/master\n\nThis appears to be because git-submodule--helper does not accept a\n--branch option. Using the --depth N option causes it to only clone N\ncommits from the default branch, which generally do not include the\ndesired branch. Thus, the next step,\n\ngit checkout -f -q -B \"$branch\" \"origin/$branch\"\n\nfails, and provides the rather confusing error message above.\n\nI'd suggest that git-submodule--helper learn a --branch option\nconsistent with git clone, and if that is impossible, that\ngit submodule add rejects the simultaneous use of both the --branch and\n--depth options.\n\n\n\n--tjf\n"},{"id":"329481","messageId":"CAGZ79kYt1rC5D=Gk8Ei1FmwF_zqK2AQgP_TQFHsV-NGHfVgOKA@mail.gmail.com","threadId":"46864","inReplyTo":"CAA4Wa2sVddG_SS70Dy_womGLKW0ipAjsxR4g+yjMKscjErRjvQ@mail.gmail.com","subject":"Re: git submodule add fails when using both --branch and --depth","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-10-02T19:55:16Z","receivedAt":"2017-10-02T19:55:23Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Sep 30, 2017 at 10:20 AM, Thadeus Fleming\n<thadeus.j.fleming@gmail.com> wrote:\n> I'm running git 2.14.2 on Ubuntu 16.04.\n>\n> Compare the behavior of\n>\n>> git clone --branch pu --depth 1 https://github.com/git/git git-pu\n>\n> which clones only the latest commit of the pu branch and\n>\n>> mkdir tmp && cd tmp && git init\n>> git submodule add --branch pu --depth 1 https://github.com/git/git \\\n>   git-pu\n>\n> which gives the error\n>\n> fatal: 'origin/pu' is not a commit and a branch 'pu' cannot be created\n> from it\n> Unable to checkout submodule 'git-pu'\n>\n> Investigating further, there is indeed only one commit in the local repo:\n>\n>> cd git-pu\n>> git log --oneline | wc -l\n> 1\n>\n> But that commit is the head of master.\n>\n>> git branch -a\n> * master                                 remotes/origin/master\n>   remotes/origin/HEAD -> origin/master\n>\n> This appears to be because git-submodule--helper does not accept a\n> --branch option. Using the --depth N option causes it to only clone N\n> commits from the default branch, which generally do not include the\n> desired branch. Thus, the next step,\n>\n> git checkout -f -q -B \"$branch\" \"origin/$branch\"\n>\n> fails, and provides the rather confusing error message above.\n>\n> I'd suggest that git-submodule--helper learn a --branch option\n> consistent with git clone, and if that is impossible, that\n> git submodule add rejects the simultaneous use of both the --branch and\n> --depth options.\n\nAdding the branch field to the submodule helper is a great idea.\n\n>\n>\n>\n> --tjf\n"},{"id":"329483","messageId":"20171002220844.GQ19555@aiede.mtv.corp.google.com","threadId":"46864","inReplyTo":"CAA4Wa2sVddG_SS70Dy_womGLKW0ipAjsxR4g+yjMKscjErRjvQ@mail.gmail.com","subject":"Re: git submodule add fails when using both --branch and --depth","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2017-10-02T22:08:45Z","receivedAt":"2017-10-02T22:08:53Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nThadeus Fleming wrote:\n\n> I'm running git 2.14.2 on Ubuntu 16.04.\n>\n> Compare the behavior of\n>\n>> git clone --branch pu --depth 1 https://github.com/git/git git-pu\n>\n> which clones only the latest commit of the pu branch and\n\nYes.\n\n>> mkdir tmp && cd tmp && git init\n>> git submodule add --branch pu --depth 1 https://github.com/git/git \\\n>  git-pu\n>\n> which gives the error\n>\n> fatal: 'origin/pu' is not a commit and a branch 'pu' cannot be created from it\n> Unable to checkout submodule 'git-pu'\n\nAs a side note (you are using \"git submodule add --depth\", not \"git\nsubmodule update --depth\"), I suspect that \"submodule update --depth\"\nmay not always do what people expect.\n\nWith add --depth, I agree with your expectation and after your fix\neverything should work fine.  But with update --depth, consider the\nfollowing sequence of steps:\n\n 1. I create a repository \"super\" with submodule \"sub\" and publish\n    both.\n\n 2. I make a couple commits to \"sub\" and a commit to \"super\" making\n    use of those changes and want to publish them.\n\n 3. I use \"git push --recurse-submodules\" to publish my commits to\n    \"sub\" and \"super\":\n\n    a. First it pushes to \"sub\".\n\n    b. Then it pushes to \"super\".\n\nBetween steps 3(a) and 3(b), a person can still \"git clone\n--recurse-submodules\" the \"super\" repository.  The repository \"super\"\ndoes not have my change yet and \"sub\" does, but that is not a problem,\nsince commands like \"git checkout --recurse-submodules\" and \"git\nsubmodule update\" know to check out the commit *before* my change in\nthe submodule.\n\nBut between steps 3(a) and 3(b), \"git submodule update --depth=1\"\nwould not work.  It would fetch the submodule with depth 1 and then\ntry to check out a commit that is deeper in history.\n\nSo I think there's more thinking needed there.\n\nThat's all a tangent to your report about add --depth, though.\n\nThanks,\nJonathan\n"}]}