Skip to content

Commit b22db26

Browse files
committed
Merge branch 'es/recursive-single-branch-clone'
"git clone --recurse-submodules --single-branch" now uses the same single-branch option when cloning the submodules. * es/recursive-single-branch-clone: clone: pass --single-branch during --recurse-submodules submodule--helper: use C99 named initializer
2 parents e8e7184 + 132f600 commit b22db26

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

Documentation/git-submodule.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ If you really want to remove a submodule from the repository and commit
133133
that use linkgit:git-rm[1] instead. See linkgit:gitsubmodules[7] for removal
134134
options.
135135

136-
update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]::
136+
update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--] [<path>...]::
137137
+
138138
--
139139
Update the registered submodules to match what the superproject
@@ -430,6 +430,10 @@ options carefully.
430430
Clone new submodules in parallel with as many jobs.
431431
Defaults to the `submodule.fetchJobs` option.
432432

433+
--[no-]single-branch::
434+
This option is only valid for the update command.
435+
Clone only one branch during update: HEAD or one specified by --branch.
436+
433437
<path>...::
434438
Paths to submodule(s). When specified this will restrict the command
435439
to only operate on the submodules found at the specified paths.

builtin/clone.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ static int checkout(int submodule_progress)
833833
argv_array_push(&args, "--no-fetch");
834834
}
835835

836+
if (option_single_branch >= 0)
837+
argv_array_push(&args, option_single_branch ?
838+
"--single-branch" :
839+
"--no-single-branch");
840+
836841
err = run_command_v_opt(args.argv, RUN_GIT_CMD);
837842
argv_array_clear(&args);
838843
}

builtin/submodule--helper.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
12351235

12361236
static int clone_submodule(const char *path, const char *gitdir, const char *url,
12371237
const char *depth, struct string_list *reference, int dissociate,
1238-
int quiet, int progress)
1238+
int quiet, int progress, int single_branch)
12391239
{
12401240
struct child_process cp = CHILD_PROCESS_INIT;
12411241

@@ -1257,6 +1257,10 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
12571257
argv_array_push(&cp.args, "--dissociate");
12581258
if (gitdir && *gitdir)
12591259
argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
1260+
if (single_branch >= 0)
1261+
argv_array_push(&cp.args, single_branch ?
1262+
"--single-branch" :
1263+
"--no-single-branch");
12601264

12611265
argv_array_push(&cp.args, "--");
12621266
argv_array_push(&cp.args, url);
@@ -1383,6 +1387,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
13831387
struct string_list reference = STRING_LIST_INIT_NODUP;
13841388
int dissociate = 0, require_init = 0;
13851389
char *sm_alternate = NULL, *error_strategy = NULL;
1390+
int single_branch = -1;
13861391

13871392
struct option module_clone_options[] = {
13881393
OPT_STRING(0, "prefix", &prefix,
@@ -1410,12 +1415,15 @@ static int module_clone(int argc, const char **argv, const char *prefix)
14101415
N_("force cloning progress")),
14111416
OPT_BOOL(0, "require-init", &require_init,
14121417
N_("disallow cloning into non-empty directory")),
1418+
OPT_BOOL(0, "single-branch", &single_branch,
1419+
N_("clone only one branch, HEAD or --branch")),
14131420
OPT_END()
14141421
};
14151422

14161423
const char *const git_submodule_helper_usage[] = {
14171424
N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
14181425
"[--reference <repository>] [--name <name>] [--depth <depth>] "
1426+
"[--single-branch] "
14191427
"--url <url> --path <path>"),
14201428
NULL
14211429
};
@@ -1448,7 +1456,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
14481456
prepare_possible_alternates(name, &reference);
14491457

14501458
if (clone_submodule(path, sm_gitdir, url, depth, &reference, dissociate,
1451-
quiet, progress))
1459+
quiet, progress, single_branch))
14521460
die(_("clone of '%s' into submodule path '%s' failed"),
14531461
url, path);
14541462
} else {
@@ -1572,6 +1580,7 @@ struct submodule_update_clone {
15721580
const char *depth;
15731581
const char *recursive_prefix;
15741582
const char *prefix;
1583+
int single_branch;
15751584

15761585
/* to be consumed by git-submodule.sh */
15771586
struct update_clone_data *update_clone;
@@ -1586,10 +1595,14 @@ struct submodule_update_clone {
15861595

15871596
int max_jobs;
15881597
};
1589-
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1590-
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, 0, \
1591-
NULL, NULL, NULL, \
1592-
NULL, 0, 0, 0, NULL, 0, 0, 1}
1598+
#define SUBMODULE_UPDATE_CLONE_INIT { \
1599+
.list = MODULE_LIST_INIT, \
1600+
.update = SUBMODULE_UPDATE_STRATEGY_INIT, \
1601+
.recommend_shallow = -1, \
1602+
.references = STRING_LIST_INIT_DUP, \
1603+
.single_branch = -1, \
1604+
.max_jobs = 1, \
1605+
}
15931606

15941607

15951608
static void next_submodule_warn_missing(struct submodule_update_clone *suc,
@@ -1728,6 +1741,10 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
17281741
argv_array_push(&child->args, "--dissociate");
17291742
if (suc->depth)
17301743
argv_array_push(&child->args, suc->depth);
1744+
if (suc->single_branch >= 0)
1745+
argv_array_push(&child->args, suc->single_branch ?
1746+
"--single-branch" :
1747+
"--no-single-branch");
17311748

17321749
cleanup:
17331750
strbuf_reset(&displaypath_sb);
@@ -1907,6 +1924,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
19071924
N_("force cloning progress")),
19081925
OPT_BOOL(0, "require-init", &suc.require_init,
19091926
N_("disallow cloning into non-empty directory")),
1927+
OPT_BOOL(0, "single-branch", &suc.single_branch,
1928+
N_("clone only one branch, HEAD or --branch")),
19101929
OPT_END()
19111930
};
19121931

git-submodule.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ USAGE="[--quiet] [--cached]
1010
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
1111
or: $dashless [--quiet] init [--] [<path>...]
1212
or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
13-
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
13+
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...]
1414
or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
1515
or: $dashless [--quiet] set-url [--] <path> <newurl>
1616
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
@@ -47,6 +47,7 @@ custom_name=
4747
depth=
4848
progress=
4949
dissociate=
50+
single_branch=
5051

5152
die_if_unmatched ()
5253
{
@@ -528,6 +529,12 @@ cmd_update()
528529
--jobs=*)
529530
jobs=$1
530531
;;
532+
--single-branch)
533+
single_branch="--single-branch"
534+
;;
535+
--no-single-branch)
536+
single_branch="--no-single-branch"
537+
;;
531538
--)
532539
shift
533540
break
@@ -557,6 +564,7 @@ cmd_update()
557564
${dissociate:+"--dissociate"} \
558565
${depth:+--depth "$depth"} \
559566
${require_init:+--require-init} \
567+
$single_branch \
560568
$recommend_shallow \
561569
$jobs \
562570
-- \

t/t5617-clone-submodules-remote.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ test_expect_success 'setup' '
1414
cd sub &&
1515
git init &&
1616
test_commit subcommit1 &&
17-
git tag sub_when_added_to_super
17+
git tag sub_when_added_to_super &&
18+
git branch other
1819
) &&
1920
git submodule add "file://$pwd/sub" sub &&
2021
git commit -m "add submodule" &&
@@ -51,4 +52,14 @@ test_expect_success 'check the default is --no-remote-submodules' '
5152
)
5253
'
5354

55+
test_expect_success 'clone with --single-branch' '
56+
test_when_finished "rm -rf super_clone" &&
57+
git clone --recurse-submodules --single-branch "file://$pwd/." super_clone &&
58+
(
59+
cd super_clone/sub &&
60+
git rev-parse --verify origin/master &&
61+
test_must_fail git rev-parse --verify origin/other
62+
)
63+
'
64+
5465
test_done

0 commit comments

Comments
 (0)