Browse Source

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
maint
Junio C Hamano 5 years ago
parent
commit
b22db265d6
  1. 6
      Documentation/git-submodule.txt
  2. 5
      builtin/clone.c
  3. 31
      builtin/submodule--helper.c
  4. 10
      git-submodule.sh
  5. 13
      t/t5617-clone-submodules-remote.sh

6
Documentation/git-submodule.txt

@ -133,7 +133,7 @@ If you really want to remove a submodule from the repository and commit
that use linkgit:git-rm[1] instead. See linkgit:gitsubmodules[7] for removal that use linkgit:git-rm[1] instead. See linkgit:gitsubmodules[7] for removal
options. options.


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


--[no-]single-branch::
This option is only valid for the update command.
Clone only one branch during update: HEAD or one specified by --branch.

<path>...:: <path>...::
Paths to submodule(s). When specified this will restrict the command Paths to submodule(s). When specified this will restrict the command
to only operate on the submodules found at the specified paths. to only operate on the submodules found at the specified paths.

5
builtin/clone.c

@ -833,6 +833,11 @@ static int checkout(int submodule_progress)
argv_array_push(&args, "--no-fetch"); argv_array_push(&args, "--no-fetch");
} }


if (option_single_branch >= 0)
argv_array_push(&args, option_single_branch ?
"--single-branch" :
"--no-single-branch");

err = run_command_v_opt(args.argv, RUN_GIT_CMD); err = run_command_v_opt(args.argv, RUN_GIT_CMD);
argv_array_clear(&args); argv_array_clear(&args);
} }

31
builtin/submodule--helper.c

@ -1235,7 +1235,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)


static int clone_submodule(const char *path, const char *gitdir, const char *url, static int clone_submodule(const char *path, const char *gitdir, const char *url,
const char *depth, struct string_list *reference, int dissociate, const char *depth, struct string_list *reference, int dissociate,
int quiet, int progress) int quiet, int progress, int single_branch)
{ {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;


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


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


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


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


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


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


int max_jobs; int max_jobs;
}; };
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \ #define SUBMODULE_UPDATE_CLONE_INIT { \
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, 0, \ .list = MODULE_LIST_INIT, \
NULL, NULL, NULL, \ .update = SUBMODULE_UPDATE_STRATEGY_INIT, \
NULL, 0, 0, 0, NULL, 0, 0, 1} .recommend_shallow = -1, \
.references = STRING_LIST_INIT_DUP, \
.single_branch = -1, \
.max_jobs = 1, \
}




static void next_submodule_warn_missing(struct submodule_update_clone *suc, 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,
argv_array_push(&child->args, "--dissociate"); argv_array_push(&child->args, "--dissociate");
if (suc->depth) if (suc->depth)
argv_array_push(&child->args, suc->depth); argv_array_push(&child->args, suc->depth);
if (suc->single_branch >= 0)
argv_array_push(&child->args, suc->single_branch ?
"--single-branch" :
"--no-single-branch");


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



10
git-submodule.sh

@ -10,7 +10,7 @@ USAGE="[--quiet] [--cached]
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...] or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: $dashless [--quiet] init [--] [<path>...] or: $dashless [--quiet] init [--] [<path>...]
or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...) or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...] or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...]
or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path> or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
or: $dashless [--quiet] set-url [--] <path> <newurl> or: $dashless [--quiet] set-url [--] <path> <newurl>
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
@ -47,6 +47,7 @@ custom_name=
depth= depth=
progress= progress=
dissociate= dissociate=
single_branch=


die_if_unmatched () die_if_unmatched ()
{ {
@ -528,6 +529,12 @@ cmd_update()
--jobs=*) --jobs=*)
jobs=$1 jobs=$1
;; ;;
--single-branch)
single_branch="--single-branch"
;;
--no-single-branch)
single_branch="--no-single-branch"
;;
--) --)
shift shift
break break
@ -557,6 +564,7 @@ cmd_update()
${dissociate:+"--dissociate"} \ ${dissociate:+"--dissociate"} \
${depth:+--depth "$depth"} \ ${depth:+--depth "$depth"} \
${require_init:+--require-init} \ ${require_init:+--require-init} \
$single_branch \
$recommend_shallow \ $recommend_shallow \
$jobs \ $jobs \
-- \ -- \

13
t/t5617-clone-submodules-remote.sh

@ -14,7 +14,8 @@ test_expect_success 'setup' '
cd sub && cd sub &&
git init && git init &&
test_commit subcommit1 && test_commit subcommit1 &&
git tag sub_when_added_to_super git tag sub_when_added_to_super &&
git branch other
) && ) &&
git submodule add "file://$pwd/sub" sub && git submodule add "file://$pwd/sub" sub &&
git commit -m "add submodule" && git commit -m "add submodule" &&
@ -51,4 +52,14 @@ test_expect_success 'check the default is --no-remote-submodules' '
) )
' '


test_expect_success 'clone with --single-branch' '
test_when_finished "rm -rf super_clone" &&
git clone --recurse-submodules --single-branch "file://$pwd/." super_clone &&
(
cd super_clone/sub &&
git rev-parse --verify origin/master &&
test_must_fail git rev-parse --verify origin/other
)
'

test_done test_done

Loading…
Cancel
Save