Skip to content

Commit

Permalink
clone: use submodules.recurse option for automatically clone submodules
Browse files Browse the repository at this point in the history
Simplify cloning repositories with submodules when the option
submodules.recurse is set by the user. This makes it transparent to the
user if submodules are used. The user doesn’t have to know if he has to add
an extra parameter to get the full project including the used submodules.
This makes clone behave identical to other commands like fetch, pull,
checkout, ... which include the submodules automatically if this option is
set.

It is implemented analog to the pull command by using an own config
function instead of using just the default config. In contrast to the pull
command, the submodule.recurse state is saved as an array of strings as it
can take an optionally pathspec argument which describes which submodules
should be recursively initialized and cloned. To recursively initialize and
clone all submodules a pathspec of "." has to be used.
The regression test is simplified compared to the test for "git clone
--recursive" as the general functionality is already checked there.

Signed-off-by: Markus Klein <masmiseim@gmx.de>
  • Loading branch information
Masmiseim36 committed Jan 30, 2020
1 parent d0654dc commit 7fa8d19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion builtin/clone.c
Expand Up @@ -26,6 +26,8 @@
#include "dir-iterator.h"
#include "iterator.h"
#include "sigchain.h"
#include "submodule-config.h"
#include "submodule.h"
#include "branch.h"
#include "remote.h"
#include "run-command.h"
Expand Down Expand Up @@ -929,6 +931,18 @@ static int path_exists(const char *path)
return !stat(path, &sb);
}

/**
* Read config variables.
*/
static int git_clone_config(const char *var, const char *value, void *cb)
{
if (!strcmp(var, "submodule.recurse") && git_config_bool(var, value)) {
string_list_append(&option_recurse_submodules, "true");
return 0;
}
return git_default_config(var, value, cb);
}

int cmd_clone(int argc, const char **argv, const char *prefix)
{
int is_bundle = 0, is_local;
Expand Down Expand Up @@ -1103,7 +1117,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)

write_config(&option_config);

git_config(git_default_config, NULL);
git_config(git_clone_config, NULL);

if (option_bare) {
if (option_mirror)
Expand Down
11 changes: 11 additions & 0 deletions t/t7407-submodule-foreach.sh
Expand Up @@ -383,6 +383,17 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules
git rev-parse --resolve-git-dir nested1/nested2/nested3/submodule/.git
)
'
test_expect_success 'use "git clone" with submodule.recurse=true to checkout all submodules' '
git clone -c submodule.recurse=true super clone7 &&
(
git -C clone7 rev-parse --resolve-git-dir .git --resolve-git-dir nested1/nested2/nested3/submodule/.git >actual &&
cat >expect <<-EOF &&
.git
$(pwd)/clone7/.git/modules/nested1/modules/nested2/modules/nested3/modules/submodule
EOF
test_cmp expect actual
)
'

test_expect_success 'command passed to foreach retains notion of stdin' '
(
Expand Down

0 comments on commit 7fa8d19

Please sign in to comment.