选择性地 init/update git 个子模块

Selectively init/update git submodules

我正在开发一个 RESTful 框架,可以选择构建 HTTP and/or HTTPS 支持。当前仅 HTTP 构建说明如下:

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

我很想提交最新的 HTTPS 功能,但我希望能够在克隆期间 select 某些依赖项(git 子模块)以帮助减少网络流量。

HTTP 和 HTTPS 示例拉下所有依赖项。

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 仅示例拉下特定依赖项。

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 似乎缺少此功能。

--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)

如文档所述,使用 --recursive 选项和 git clone 将初始化所有子模块。您可以 运行 以下内容代替,它直接使用 git submodule 来仅初始化您在 HTTP 情况下需要的子模块:

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