From: Philippe Blain <levraiphilippeblain@gmail.com>
To: git@vger.kernel.org
Subject: [BUG] Adding a submodule containing submodules in a branch and checkout --recurse-submodules
Date: Mon, 23 Sep 2019 22:59:08 -0400 [thread overview]
Message-ID: <7437BB59-4605-48EC-B05E-E2BDB2D9DABC@gmail.com> (raw)
Hello,
I 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.
As an illustration, the following sequence of commands will not leave the submodule brooklyn in the right state:
mkdir test
cd test
git init
git touch file
git add file
git commit -m "initial commit" # add a commit on master
git checkout -b add-sub # create feature branch
git submodule add http://github.com/apache/brooklyn # this repo has submodules itself
git submodule update --init --recursive # initialize all nested submodules
git commit -m "add brooklyn"
git checkout --recurse-submodules master # this removes the brooklyn directory, as expected
GIT_TRACE=1 git checkout --recurse-submodules add-sub # this fails to checkout the nested submodules correctly
22:38:13.885971 git.c:439 trace: built-in: git checkout --recurse-submodules add-sub
22: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
22:38:13.909366 git.c:439 trace: built-in: git read-tree -u --reset 4b825dc642cb6eb9a060e54bf8d69288fbee4904
22: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
22:38:13.935402 git.c:439 trace: built-in: git read-tree --recurse-submodules -u --reset 30f3d2754a98670d57d142193ba51af3038555af
22: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
fatal: exec '--super-prefix=brooklyn/brooklyn-client/': cd to 'brooklyn-client' failed: No such file or directory
error: Submodule 'brooklyn-client' could not be updated.
error: Submodule 'brooklyn/brooklyn-client' cannot checkout new HEAD.
error: Submodule 'brooklyn' could not be updated.
22:38:13.947005 run-command.c:663 trace: run_command: cd brooklyn; unset GIT_PREFIX; GIT_DIR=.git git status --porcelain=2
22:38:13.962706 git.c:439 trace: built-in: git status --porcelain=2
M brooklyn
Switched to branch 'add-sub’
After 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 :
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: .gitattributes
deleted: .gitignore
deleted: .gitmodules
deleted: .mvn/jvm.config
deleted: Dockerfile
deleted: Jenkinsfile
deleted: LICENSE
deleted: NOTICE
deleted: README.md
deleted: brooklyn-client
deleted: brooklyn-dist
deleted: brooklyn-docs
deleted: brooklyn-library
deleted: brooklyn-server
deleted: brooklyn-ui
deleted: doap_Brooklyn.rdf
deleted: pom.xml
fatal: not a git repository: 'brooklyn-client/.git'
fatal: not a git repository: 'brooklyn-dist/.git'
fatal: not a git repository: 'brooklyn-docs/.git'
fatal: not a git repository: 'brooklyn-library/.git'
fatal: not a git repository: 'brooklyn-server/.git'
fatal: not a git repository: 'brooklyn-ui/.git'
Submodule changes to be committed:
* brooklyn-client 05031a7...0000000:
* brooklyn-dist 3a30944...0000000:
* brooklyn-docs 2b06e96...0000000:
* brooklyn-library a94f7d8...0000000:
* brooklyn-server e601350...0000000:
* brooklyn-ui 503d74e...0000000:
To 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.
Cheers,
Philippe Blain.
reply other threads:[~2019-09-24 2:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7437BB59-4605-48EC-B05E-E2BDB2D9DABC@gmail.com \
--to=levraiphilippeblain@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).