{"thread":{"id":"51906","subject":"[BUG] Adding a submodule containing submodules in a branch and checkout --recurse-submodules","startedAt":"2019-09-24T02:59:15Z","lastAt":"2019-09-24T02:59:15Z","messageCount":1,"participants":["Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"382828","messageId":"7437BB59-4605-48EC-B05E-E2BDB2D9DABC@gmail.com","threadId":"51906","inReplyTo":null,"subject":"[BUG] Adding a submodule containing submodules in a branch and checkout --recurse-submodules","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2019-09-24T02:59:08Z","receivedAt":"2019-09-24T02:59:15Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hello,\n\nI think I have found a bug in the implementation of `git checkout —recurse-submodules $branch` in the case of nested submodules. When I add a submodule that has submodules in a feature branch of the main project, checkout the master branch and then checkout my feature branch again, the submodule is not in the expected state.\n\nAs an illustration, the following sequence of commands will not leave the submodule brooklyn in the right state:\n\nmkdir test\ncd test\ngit init\ngit touch file\ngit add file\ngit commit -m \"initial commit\" # add a commit on master\ngit checkout -b add-sub # create feature branch\ngit submodule add http://github.com/apache/brooklyn # this repo has submodules itself\ngit submodule update --init --recursive # initialize all nested submodules\ngit commit -m \"add brooklyn\"\ngit checkout --recurse-submodules master # this removes the brooklyn directory, as expected\nGIT_TRACE=1 git checkout --recurse-submodules add-sub # this fails to checkout the nested submodules correctly\n22:38:13.885971 git.c:439               trace: built-in: git checkout --recurse-submodules add-sub\n22:38:13.895776 run-command.c:663       trace: run_command: cd brooklyn; unset GIT_PREFIX; GIT_DIR=.git git --super-prefix=brooklyn/ read-tree -u --reset 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n22:38:13.909366 git.c:439               trace: built-in: git read-tree -u --reset 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n22:38:13.918464 run-command.c:663       trace: run_command: cd brooklyn; unset GIT_PREFIX; GIT_DIR=.git git --super-prefix=brooklyn/ read-tree --recurse-submodules -u --reset 30f3d2754a98670d57d142193ba51af3038555af\n22:38:13.935402 git.c:439               trace: built-in: git read-tree --recurse-submodules -u --reset 30f3d2754a98670d57d142193ba51af3038555af\n22:38:13.940017 run-command.c:663       trace: run_command: cd brooklyn-client; unset GIT_INTERNAL_SUPER_PREFIX GIT_PREFIX; GIT_DIR=.git git --super-prefix=brooklyn/brooklyn-client/ read-tree --recurse-submodules -n --reset 05031a79d4724b867db76b7c4afe55190666c7af\nfatal: exec '--super-prefix=brooklyn/brooklyn-client/': cd to 'brooklyn-client' failed: No such file or directory\nerror: Submodule 'brooklyn-client' could not be updated.\nerror: Submodule 'brooklyn/brooklyn-client' cannot checkout new HEAD.\nerror: Submodule 'brooklyn' could not be updated.\n22:38:13.947005 run-command.c:663       trace: run_command: cd brooklyn; unset GIT_PREFIX; GIT_DIR=.git git status --porcelain=2\n22:38:13.962706 git.c:439               trace: built-in: git status --porcelain=2\nM\tbrooklyn\nSwitched to branch 'add-sub’\n\nAfter that, git status says \"modified content\" for brooklyn; cd-ing into brooklyn and doing git status show everything as deleted, and also some errors related to the git dir of the nested submodules : \nOn branch master\nYour branch is up to date with 'origin/master'.\n\nChanges to be committed:\n  (use \"git reset HEAD <file>...\" to unstage)\n\n\tdeleted:    .gitattributes\n\tdeleted:    .gitignore\n\tdeleted:    .gitmodules\n\tdeleted:    .mvn/jvm.config\n\tdeleted:    Dockerfile\n\tdeleted:    Jenkinsfile\n\tdeleted:    LICENSE\n\tdeleted:    NOTICE\n\tdeleted:    README.md\n\tdeleted:    brooklyn-client\n\tdeleted:    brooklyn-dist\n\tdeleted:    brooklyn-docs\n\tdeleted:    brooklyn-library\n\tdeleted:    brooklyn-server\n\tdeleted:    brooklyn-ui\n\tdeleted:    doap_Brooklyn.rdf\n\tdeleted:    pom.xml\n\nfatal: not a git repository: 'brooklyn-client/.git'\nfatal: not a git repository: 'brooklyn-dist/.git'\nfatal: not a git repository: 'brooklyn-docs/.git'\nfatal: not a git repository: 'brooklyn-library/.git'\nfatal: not a git repository: 'brooklyn-server/.git'\nfatal: not a git repository: 'brooklyn-ui/.git'\nSubmodule changes to be committed:\n\n* brooklyn-client 05031a7...0000000:\n\n* brooklyn-dist 3a30944...0000000:\n\n* brooklyn-docs 2b06e96...0000000:\n\n* brooklyn-library a94f7d8...0000000:\n\n* brooklyn-server e601350...0000000:\n\n* brooklyn-ui 503d74e...0000000:\n\nTo get back to the state I was on branch add-sub before checking out master, I need to do \"git submodule update --recursive --force\". I don’t think this is expected behaviour, it is rather confusing.\n\nCheers,\nPhilippe Blain."}]}