Selectively init/update git submodules

756 views Asked by At

I'm developing a RESTful framework that has the option to build HTTP and/or HTTPS support. The current HTTP only build instructions follow:

git clone --recursive https://github.com/corvusoft/restbed.git
mkdir restbed/build
cd restbed/build
cmake [-DBUILD_TESTS=YES] [-DBUILD_EXAMPLES=YES] [-DCMAKE_INSTALL_PREFIX=/output-directory] ..
make install
make test

I'm keen to commit in the latest HTTPS feature but I'd like the ability to select certain dependencies (git submodules) during clone to help reduce network traffic.

HTTP and HTTPS example pulling down all dependencies.

git clone --recursive  https://github.com/corvusoft/restbed.git
mkdir restbed/build
cd restbed/build
cmake [-DBUILD_TESTS=YES] [-DBUILD_EXAMPLES=YES] [-DCMAKE_INSTALL_PREFIX=/output-directory] ..
make install
make test

HTTP only example pulling down specific dependencies.

git clone --recursive="asio, framework" https://github.com/corvusoft/restbed.git
mkdir restbed/build
cd restbed/build
cmake -DBUILD_SSL=NO [-DBUILD_TESTS=YES] [-DBUILD_EXAMPLES=YES] [-DCMAKE_INSTALL_PREFIX=/output-directory] ..
make install
make test

git --recursive would appear to lack this functionality.

--recursive --recurse-submodules After the clone is created, initialize all submodules within, using their default settings. This is equivalent to running git submodule update --init --recursive immediately after the clone is finished. This option is ignored if the cloned repository does not have a worktree/checkout (i.e. if any of --no-checkout/-n, --bare, or --mirror is given)

1

There are 1 answers

0
decates On BEST ANSWER

As the documentation says, using the --recursive option with git clone will initialize all of the submodules. You can run the following instead, which uses git submodule directly to only initialize the submodules you're after for the HTTP case:

git clone https://github.com/corvusoft/restbed.git
git submodule update --init --recursive dependency/asio
git submodule update --init --recursive dependency/framework    
mkdir restbed/build
cd restbed/build
cmake -DBUILD_SSL=NO [-DBUILD_TESTS=YES] [-DBUILD_EXAMPLES=YES] [-DCMAKE_INSTALL_PREFIX=/output-directory] ..
make install
make test