3
#include "environment.h"
8
#include "parse-options.h"
12
#include "preload-index.h"
14
#include "read-cache.h"
16
#include "sparse-index.h"
18
#include "submodule-config.h"
19
#include "string-list.h"
20
#include "run-command.h"
27
#include "object-file.h"
28
#include "object-name.h"
29
#include "object-store-ll.h"
32
#include "list-objects-filter-options.h"
34
#define OPT_QUIET (1 << 0)
35
#define OPT_CACHED (1 << 1)
36
#define OPT_RECURSIVE (1 << 2)
37
#define OPT_FORCE (1 << 3)
39
typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
42
static int repo_get_default_remote(struct repository *repo, char **default_remote)
45
struct strbuf sb = STRBUF_INIT;
46
struct ref_store *store = get_main_ref_store(repo);
47
const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL,
51
return die_message(_("No such ref: %s"), "HEAD");
54
if (!strcmp(refname, "HEAD")) {
55
*default_remote = xstrdup("origin");
59
if (!skip_prefix(refname, "refs/heads/", &refname))
60
return die_message(_("Expecting a full ref name, got %s"),
63
strbuf_addf(&sb, "branch.%s.remote", refname);
64
if (repo_config_get_string(repo, sb.buf, &dest))
65
*default_remote = xstrdup("origin");
67
*default_remote = dest;
73
static int get_default_remote_submodule(const char *module_path, char **default_remote)
75
struct repository subrepo;
78
if (repo_submodule_init(&subrepo, the_repository, module_path,
80
return die_message(_("could not get a repository handle for submodule '%s'"),
82
ret = repo_get_default_remote(&subrepo, default_remote);
88
static char *get_default_remote(void)
91
int code = repo_get_default_remote(the_repository, &default_remote);
96
return default_remote;
99
static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
101
char *remoteurl, *resolved_url;
102
char *remote = get_default_remote();
103
struct strbuf remotesb = STRBUF_INIT;
105
strbuf_addf(&remotesb, "remote.%s.url", remote);
106
if (git_config_get_string(remotesb.buf, &remoteurl)) {
108
warning(_("could not look up configuration '%s'. "
109
"Assuming this repository is its own "
110
"authoritative upstream."),
112
remoteurl = xgetcwd();
114
resolved_url = relative_url(remoteurl, rel_url, up_path);
118
strbuf_release(&remotesb);
124
static char *get_submodule_displaypath(const char *path, const char *prefix,
125
const char *super_prefix)
127
if (prefix && super_prefix) {
128
BUG("cannot have prefix '%s' and superprefix '%s'",
129
prefix, super_prefix);
131
struct strbuf sb = STRBUF_INIT;
132
char *displaypath = xstrdup(relative_path(path, prefix, &sb));
135
} else if (super_prefix) {
136
return xstrfmt("%s%s", super_prefix, path);
138
return xstrdup(path);
142
static char *compute_rev_name(const char *sub_path, const char* object_id)
144
struct strbuf sb = STRBUF_INIT;
147
static const char *describe_bare[] = { NULL };
149
static const char *describe_tags[] = { "--tags", NULL };
151
static const char *describe_contains[] = { "--contains", NULL };
153
static const char *describe_all_always[] = { "--all", "--always", NULL };
155
static const char **describe_argv[] = { describe_bare, describe_tags,
157
describe_all_always, NULL };
159
for (d = describe_argv; *d; d++) {
160
struct child_process cp = CHILD_PROCESS_INIT;
161
prepare_submodule_repo_env(&cp.env);
166
strvec_push(&cp.args, "describe");
167
strvec_pushv(&cp.args, *d);
168
strvec_push(&cp.args, object_id);
170
if (!capture_command(&cp, &sb, 0)) {
171
strbuf_strip_suffix(&sb, "\n");
172
return strbuf_detach(&sb, NULL);
181
const struct cache_entry **entries;
184
#define MODULE_LIST_INIT { 0 }
186
static void module_list_release(struct module_list *ml)
191
static int module_list_compute(const char **argv,
193
struct pathspec *pathspec,
194
struct module_list *list)
197
char *ps_matched = NULL;
199
parse_pathspec(pathspec, 0,
200
PATHSPEC_PREFER_FULL,
204
ps_matched = xcalloc(pathspec->nr, 1);
206
if (repo_read_index(the_repository) < 0)
207
die(_("index file corrupt"));
209
for (i = 0; i < the_repository->index->cache_nr; i++) {
210
const struct cache_entry *ce = the_repository->index->cache[i];
212
if (!match_pathspec(the_repository->index, pathspec, ce->name, ce_namelen(ce),
214
!S_ISGITLINK(ce->ce_mode))
217
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
218
list->entries[list->nr++] = ce;
219
while (i + 1 < the_repository->index->cache_nr &&
220
!strcmp(ce->name, the_repository->index->cache[i + 1]->name))
228
if (ps_matched && report_path_error(ps_matched, pathspec))
236
static void module_list_active(struct module_list *list)
239
struct module_list active_modules = MODULE_LIST_INIT;
241
for (i = 0; i < list->nr; i++) {
242
const struct cache_entry *ce = list->entries[i];
244
if (!is_submodule_active(the_repository, ce->name))
247
ALLOC_GROW(active_modules.entries,
248
active_modules.nr + 1,
249
active_modules.alloc);
250
active_modules.entries[active_modules.nr++] = ce;
253
module_list_release(list);
254
*list = active_modules;
257
static char *get_up_path(const char *path)
259
struct strbuf sb = STRBUF_INIT;
261
strbuf_addstrings(&sb, "../", count_slashes(path));
268
if (!is_dir_sep(path[strlen(path) - 1]))
269
strbuf_addstr(&sb, "../");
271
return strbuf_detach(&sb, NULL);
274
static void for_each_listed_submodule(const struct module_list *list,
275
each_submodule_fn fn, void *cb_data)
279
for (i = 0; i < list->nr; i++)
280
fn(list->entries[i], cb_data);
287
const char *super_prefix;
291
#define FOREACH_CB_INIT { 0 }
293
static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
296
struct foreach_cb *info = cb_data;
297
const char *path = list_item->name;
298
const struct object_id *ce_oid = &list_item->oid;
299
const struct submodule *sub;
300
struct child_process cp = CHILD_PROCESS_INIT;
303
if (validate_submodule_path(path) < 0)
306
displaypath = get_submodule_displaypath(path, info->prefix,
309
sub = submodule_from_path(the_repository, null_oid(), path);
312
die(_("No url found for submodule path '%s' in .gitmodules"),
315
if (!is_submodule_populated_gently(path, NULL))
318
prepare_submodule_repo_env(&cp.env);
334
if (info->argc == 1) {
335
char *toplevel = xgetcwd();
336
struct strbuf sb = STRBUF_INIT;
338
strvec_pushf(&cp.env, "name=%s", sub->name);
339
strvec_pushf(&cp.env, "sm_path=%s", path);
340
strvec_pushf(&cp.env, "displaypath=%s", displaypath);
341
strvec_pushf(&cp.env, "sha1=%s",
343
strvec_pushf(&cp.env, "toplevel=%s", toplevel);
354
sq_quote_buf(&sb, path);
355
strvec_pushf(&cp.args, "path=%s; %s",
356
sb.buf, info->argv[0]);
360
strvec_pushv(&cp.args, info->argv);
364
printf(_("Entering '%s'\n"), displaypath);
366
if (info->argv[0] && run_command(&cp))
367
die(_("run_command returned non-zero status for %s\n."),
370
if (info->recursive) {
371
struct child_process cpr = CHILD_PROCESS_INIT;
375
prepare_submodule_repo_env(&cpr.env);
377
strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive",
379
strvec_pushf(&cpr.args, "--super-prefix=%s/", displaypath);
382
strvec_push(&cpr.args, "--quiet");
384
strvec_push(&cpr.args, "--");
385
strvec_pushv(&cpr.args, info->argv);
387
if (run_command(&cpr))
388
die(_("run_command returned non-zero status while "
389
"recursing in the nested submodules of %s\n."),
397
static int module_foreach(int argc, const char **argv, const char *prefix)
399
struct foreach_cb info = FOREACH_CB_INIT;
400
struct pathspec pathspec = { 0 };
401
struct module_list list = MODULE_LIST_INIT;
402
struct option module_foreach_options[] = {
403
OPT__SUPER_PREFIX(&info.super_prefix),
404
OPT__QUIET(&info.quiet, N_("suppress output of entering each submodule command")),
405
OPT_BOOL(0, "recursive", &info.recursive,
406
N_("recurse into nested submodules")),
409
const char *const git_submodule_helper_usage[] = {
410
N_("git submodule foreach [--quiet] [--recursive] [--] <command>"),
415
argc = parse_options(argc, argv, prefix, module_foreach_options,
416
git_submodule_helper_usage, 0);
418
if (module_list_compute(NULL, prefix, &pathspec, &list) < 0)
423
info.prefix = prefix;
425
for_each_listed_submodule(&list, runcommand_in_submodule_cb, &info);
429
module_list_release(&list);
430
clear_pathspec(&pathspec);
434
static int starts_with_dot_slash(const char *const path)
436
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_SLASH |
437
PATH_MATCH_XPLATFORM);
440
static int starts_with_dot_dot_slash(const char *const path)
442
return path_match_flags(path, PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH |
443
PATH_MATCH_XPLATFORM);
448
const char *super_prefix;
451
#define INIT_CB_INIT { 0 }
453
static void init_submodule(const char *path, const char *prefix,
454
const char *super_prefix,
457
const struct submodule *sub;
458
struct strbuf sb = STRBUF_INIT;
460
char *url = NULL, *displaypath;
462
displaypath = get_submodule_displaypath(path, prefix, super_prefix);
464
sub = submodule_from_path(the_repository, null_oid(), path);
467
die(_("No url found for submodule path '%s' in .gitmodules"),
476
if (!is_submodule_active(the_repository, path)) {
477
strbuf_addf(&sb, "submodule.%s.active", sub->name);
478
git_config_set_gently(sb.buf, "true");
487
strbuf_addf(&sb, "submodule.%s.url", sub->name);
488
if (git_config_get_string(sb.buf, &url)) {
490
die(_("No url found for submodule path '%s' in .gitmodules"),
493
url = xstrdup(sub->url);
496
if (starts_with_dot_dot_slash(url) ||
497
starts_with_dot_slash(url)) {
500
url = resolve_relative_url(oldurl, NULL, 0);
504
if (git_config_set_gently(sb.buf, url))
505
die(_("Failed to register url for submodule path '%s'"),
507
if (!(flags & OPT_QUIET))
509
_("Submodule '%s' (%s) registered for path '%s'\n"),
510
sub->name, url, displaypath);
515
strbuf_addf(&sb, "submodule.%s.update", sub->name);
516
if (git_config_get_string_tmp(sb.buf, &upd) &&
517
sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
518
if (sub->update_strategy.type == SM_UPDATE_COMMAND) {
519
fprintf(stderr, _("warning: command update mode suggested for submodule '%s'\n"),
523
upd = submodule_update_type_to_string(sub->update_strategy.type);
526
if (git_config_set_gently(sb.buf, upd))
527
die(_("Failed to register update mode for submodule path '%s'"), displaypath);
534
static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data)
536
struct init_cb *info = cb_data;
538
init_submodule(list_item->name, info->prefix, info->super_prefix,
542
static int module_init(int argc, const char **argv, const char *prefix)
544
struct init_cb info = INIT_CB_INIT;
545
struct pathspec pathspec = { 0 };
546
struct module_list list = MODULE_LIST_INIT;
548
struct option module_init_options[] = {
549
OPT__QUIET(&quiet, N_("suppress output for initializing a submodule")),
552
const char *const git_submodule_helper_usage[] = {
553
N_("git submodule init [<options>] [<path>]"),
558
argc = parse_options(argc, argv, prefix, module_init_options,
559
git_submodule_helper_usage, 0);
561
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
568
if (!argc && !git_config_get("submodule.active"))
569
module_list_active(&list);
571
info.prefix = prefix;
573
info.flags |= OPT_QUIET;
575
for_each_listed_submodule(&list, init_submodule_cb, &info);
579
module_list_release(&list);
580
clear_pathspec(&pathspec);
586
const char *super_prefix;
589
#define STATUS_CB_INIT { 0 }
591
static void print_status(unsigned int flags, char state, const char *path,
592
const struct object_id *oid, const char *displaypath)
594
if (flags & OPT_QUIET)
597
printf("%c%s %s", state, oid_to_hex(oid), displaypath);
599
if (state == ' ' || state == '+') {
600
char *name = compute_rev_name(path, oid_to_hex(oid));
603
printf(" (%s)", name);
610
static int handle_submodule_head_ref(const char *refname UNUSED,
611
const char *referent UNUSED,
612
const struct object_id *oid,
616
struct object_id *output = cb_data;
624
static void status_submodule(const char *path, const struct object_id *ce_oid,
625
unsigned int ce_flags, const char *prefix,
626
const char *super_prefix, unsigned int flags)
629
struct strvec diff_files_args = STRVEC_INIT;
630
struct rev_info rev = REV_INFO_INIT;
631
struct strbuf buf = STRBUF_INIT;
633
struct setup_revision_opt opt = {
634
.free_removed_argv_elements = 1,
637
if (validate_submodule_path(path) < 0)
640
if (!submodule_from_path(the_repository, null_oid(), path))
641
die(_("no submodule mapping found in .gitmodules for path '%s'"),
644
displaypath = get_submodule_displaypath(path, prefix, super_prefix);
646
if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) {
647
print_status(flags, 'U', path, null_oid(), displaypath);
651
strbuf_addf(&buf, "%s/.git", path);
652
git_dir = read_gitfile(buf.buf);
656
if (!is_submodule_active(the_repository, path) ||
657
!is_git_directory(git_dir)) {
658
print_status(flags, '-', path, ce_oid, displaypath);
659
strbuf_release(&buf);
662
strbuf_release(&buf);
664
strvec_pushl(&diff_files_args, "diff-files",
665
"--ignore-submodules=dirty", "--quiet", "--",
668
git_config(git_diff_basic_config, NULL);
670
repo_init_revisions(the_repository, &rev, NULL);
672
setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
673
run_diff_files(&rev, 0);
675
if (!diff_result_code(&rev.diffopt)) {
676
print_status(flags, ' ', path, ce_oid,
678
} else if (!(flags & OPT_CACHED)) {
679
struct object_id oid;
680
struct ref_store *refs = repo_get_submodule_ref_store(the_repository,
684
print_status(flags, '-', path, ce_oid, displaypath);
687
if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
688
die(_("could not resolve HEAD ref inside the "
689
"submodule '%s'"), path);
691
print_status(flags, '+', path, &oid, displaypath);
693
print_status(flags, '+', path, ce_oid, displaypath);
696
if (flags & OPT_RECURSIVE) {
697
struct child_process cpr = CHILD_PROCESS_INIT;
701
prepare_submodule_repo_env(&cpr.env);
703
strvec_pushl(&cpr.args, "submodule--helper", "status",
704
"--recursive", NULL);
705
strvec_pushf(&cpr.args, "--super-prefix=%s/", displaypath);
707
if (flags & OPT_CACHED)
708
strvec_push(&cpr.args, "--cached");
710
if (flags & OPT_QUIET)
711
strvec_push(&cpr.args, "--quiet");
713
if (run_command(&cpr))
714
die(_("failed to recurse into submodule '%s'"), path);
718
strvec_clear(&diff_files_args);
720
release_revisions(&rev);
723
static void status_submodule_cb(const struct cache_entry *list_item,
726
struct status_cb *info = cb_data;
728
status_submodule(list_item->name, &list_item->oid, list_item->ce_flags,
729
info->prefix, info->super_prefix, info->flags);
732
static int module_status(int argc, const char **argv, const char *prefix)
734
struct status_cb info = STATUS_CB_INIT;
735
struct pathspec pathspec = { 0 };
736
struct module_list list = MODULE_LIST_INIT;
738
struct option module_status_options[] = {
739
OPT__SUPER_PREFIX(&info.super_prefix),
740
OPT__QUIET(&quiet, N_("suppress submodule status output")),
741
OPT_BIT(0, "cached", &info.flags, N_("use commit stored in the index instead of the one stored in the submodule HEAD"), OPT_CACHED),
742
OPT_BIT(0, "recursive", &info.flags, N_("recurse into nested submodules"), OPT_RECURSIVE),
745
const char *const git_submodule_helper_usage[] = {
746
N_("git submodule status [--quiet] [--cached] [--recursive] [<path>...]"),
751
argc = parse_options(argc, argv, prefix, module_status_options,
752
git_submodule_helper_usage, 0);
754
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
757
info.prefix = prefix;
759
info.flags |= OPT_QUIET;
761
for_each_listed_submodule(&list, status_submodule_cb, &info);
765
module_list_release(&list);
766
clear_pathspec(&pathspec);
771
unsigned int mod_src;
772
unsigned int mod_dst;
773
struct object_id oid_src;
774
struct object_id oid_dst;
778
#define MODULE_CB_INIT { 0 }
780
static void module_cb_release(struct module_cb *mcb)
785
struct module_cb_list {
786
struct module_cb **entries;
789
#define MODULE_CB_LIST_INIT { 0 }
791
static void module_cb_list_release(struct module_cb_list *mcbl)
795
for (i = 0; i < mcbl->nr; i++) {
796
struct module_cb *mcb = mcbl->entries[i];
798
module_cb_release(mcb);
808
const char *super_prefix;
809
unsigned int cached: 1;
810
unsigned int for_status: 1;
811
unsigned int files: 1;
814
#define SUMMARY_CB_INIT { 0 }
821
static char *verify_submodule_committish(const char *sm_path,
822
const char *committish)
824
struct child_process cp_rev_parse = CHILD_PROCESS_INIT;
825
struct strbuf result = STRBUF_INIT;
827
cp_rev_parse.git_cmd = 1;
828
cp_rev_parse.dir = sm_path;
829
prepare_submodule_repo_env(&cp_rev_parse.env);
830
strvec_pushl(&cp_rev_parse.args, "rev-parse", "-q", "--short", NULL);
831
strvec_pushf(&cp_rev_parse.args, "%s^0", committish);
832
strvec_push(&cp_rev_parse.args, "--");
834
if (capture_command(&cp_rev_parse, &result, 0))
837
strbuf_trim_trailing_newline(&result);
838
return strbuf_detach(&result, NULL);
841
static void print_submodule_summary(struct summary_cb *info, const char *errmsg,
842
int total_commits, const char *displaypath,
843
const char *src_abbrev, const char *dst_abbrev,
846
if (p->status == 'T') {
847
if (S_ISGITLINK(p->mod_dst))
848
printf(_("* %s %s(blob)->%s(submodule)"),
849
displaypath, src_abbrev, dst_abbrev);
851
printf(_("* %s %s(submodule)->%s(blob)"),
852
displaypath, src_abbrev, dst_abbrev);
854
printf("* %s %s...%s",
855
displaypath, src_abbrev, dst_abbrev);
858
if (total_commits < 0)
861
printf(" (%d):\n", total_commits);
864
printf(_("%s"), errmsg);
865
} else if (total_commits > 0) {
866
struct child_process cp_log = CHILD_PROCESS_INIT;
869
cp_log.dir = p->sm_path;
870
prepare_submodule_repo_env(&cp_log.env);
871
strvec_pushl(&cp_log.args, "log", NULL);
873
if (S_ISGITLINK(p->mod_src) && S_ISGITLINK(p->mod_dst)) {
874
if (info->summary_limit > 0)
875
strvec_pushf(&cp_log.args, "-%d",
876
info->summary_limit);
878
strvec_pushl(&cp_log.args, "--pretty= %m %s",
879
"--first-parent", NULL);
880
strvec_pushf(&cp_log.args, "%s...%s",
881
src_abbrev, dst_abbrev);
882
} else if (S_ISGITLINK(p->mod_dst)) {
883
strvec_pushl(&cp_log.args, "--pretty= > %s",
884
"-1", dst_abbrev, NULL);
886
strvec_pushl(&cp_log.args, "--pretty= < %s",
887
"-1", src_abbrev, NULL);
889
run_command(&cp_log);
894
static void generate_submodule_summary(struct summary_cb *info,
897
char *displaypath, *src_abbrev = NULL, *dst_abbrev;
898
int missing_src = 0, missing_dst = 0;
899
struct strbuf errmsg = STRBUF_INIT;
900
int total_commits = -1;
902
if (!info->cached && oideq(&p->oid_dst, null_oid())) {
903
if (S_ISGITLINK(p->mod_dst)) {
904
struct ref_store *refs = repo_get_submodule_ref_store(the_repository,
908
refs_head_ref(refs, handle_submodule_head_ref, &p->oid_dst);
909
} else if (S_ISLNK(p->mod_dst) || S_ISREG(p->mod_dst)) {
911
int fd = open(p->sm_path, O_RDONLY);
913
if (fd < 0 || fstat(fd, &st) < 0 ||
914
index_fd(the_repository->index, &p->oid_dst, fd, &st, OBJ_BLOB,
916
error(_("couldn't hash object from '%s'"), p->sm_path);
920
warning(_("unexpected mode %o\n"), p->mod_dst);
924
if (S_ISGITLINK(p->mod_src)) {
925
if (p->status != 'D')
926
src_abbrev = verify_submodule_committish(p->sm_path,
927
oid_to_hex(&p->oid_src));
936
src_abbrev = xstrndup(oid_to_hex(&p->oid_src), 7);
945
src_abbrev = xstrndup(oid_to_hex(&p->oid_src), 7);
948
if (S_ISGITLINK(p->mod_dst)) {
949
dst_abbrev = verify_submodule_committish(p->sm_path,
950
oid_to_hex(&p->oid_dst));
959
dst_abbrev = xstrndup(oid_to_hex(&p->oid_dst), 7);
968
dst_abbrev = xstrndup(oid_to_hex(&p->oid_dst), 7);
971
displaypath = get_submodule_displaypath(p->sm_path, info->prefix,
974
if (!missing_src && !missing_dst) {
975
struct child_process cp_rev_list = CHILD_PROCESS_INIT;
976
struct strbuf sb_rev_list = STRBUF_INIT;
978
strvec_pushl(&cp_rev_list.args, "rev-list",
979
"--first-parent", "--count", NULL);
980
if (S_ISGITLINK(p->mod_src) && S_ISGITLINK(p->mod_dst))
981
strvec_pushf(&cp_rev_list.args, "%s...%s",
982
src_abbrev, dst_abbrev);
984
strvec_push(&cp_rev_list.args, S_ISGITLINK(p->mod_src) ?
985
src_abbrev : dst_abbrev);
986
strvec_push(&cp_rev_list.args, "--");
988
cp_rev_list.git_cmd = 1;
989
cp_rev_list.dir = p->sm_path;
990
prepare_submodule_repo_env(&cp_rev_list.env);
992
if (!capture_command(&cp_rev_list, &sb_rev_list, 0))
993
total_commits = atoi(sb_rev_list.buf);
995
strbuf_release(&sb_rev_list);
1001
if (S_ISGITLINK(p->mod_dst)) {
1002
if (missing_src && missing_dst) {
1003
strbuf_addf(&errmsg, " Warn: %s doesn't contain commits %s and %s\n",
1004
displaypath, oid_to_hex(&p->oid_src),
1005
oid_to_hex(&p->oid_dst));
1007
strbuf_addf(&errmsg, " Warn: %s doesn't contain commit %s\n",
1008
displaypath, missing_src ?
1009
oid_to_hex(&p->oid_src) :
1010
oid_to_hex(&p->oid_dst));
1015
print_submodule_summary(info, errmsg.len ? errmsg.buf : NULL,
1016
total_commits, displaypath, src_abbrev,
1022
strbuf_release(&errmsg);
1025
static void prepare_submodule_summary(struct summary_cb *info,
1026
struct module_cb_list *list)
1029
for (i = 0; i < list->nr; i++) {
1030
const struct submodule *sub;
1031
struct module_cb *p = list->entries[i];
1032
struct strbuf sm_gitdir = STRBUF_INIT;
1034
if (p->status == 'D' || p->status == 'T') {
1035
generate_submodule_summary(info, p);
1039
if (info->for_status && p->status != 'A' &&
1040
(sub = submodule_from_path(the_repository,
1041
null_oid(), p->sm_path))) {
1042
char *config_key = NULL;
1046
config_key = xstrfmt("submodule.%s.ignore",
1048
if (!git_config_get_string_tmp(config_key, &value))
1049
ignore_all = !strcmp(value, "all");
1050
else if (sub->ignore)
1051
ignore_all = !strcmp(sub->ignore, "all");
1059
strbuf_addstr(&sm_gitdir, p->sm_path);
1060
if (is_nonbare_repository_dir(&sm_gitdir))
1061
generate_submodule_summary(info, p);
1062
strbuf_release(&sm_gitdir);
1066
static void submodule_summary_callback(struct diff_queue_struct *q,
1067
struct diff_options *options UNUSED,
1071
struct module_cb_list *list = data;
1072
for (i = 0; i < q->nr; i++) {
1073
struct diff_filepair *p = q->queue[i];
1074
struct module_cb *temp;
1076
if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
1078
temp = (struct module_cb*)malloc(sizeof(struct module_cb));
1079
temp->mod_src = p->one->mode;
1080
temp->mod_dst = p->two->mode;
1081
temp->oid_src = p->one->oid;
1082
temp->oid_dst = p->two->oid;
1083
temp->status = p->status;
1084
temp->sm_path = xstrdup(p->one->path);
1086
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
1087
list->entries[list->nr++] = temp;
1091
static const char *get_diff_cmd(enum diff_cmd diff_cmd)
1094
case DIFF_INDEX: return "diff-index";
1095
case DIFF_FILES: return "diff-files";
1096
default: BUG("bad diff_cmd value %d", diff_cmd);
1100
static int compute_summary_module_list(struct object_id *head_oid,
1101
struct summary_cb *info,
1102
enum diff_cmd diff_cmd)
1104
struct strvec diff_args = STRVEC_INIT;
1105
struct rev_info rev;
1106
struct setup_revision_opt opt = {
1107
.free_removed_argv_elements = 1,
1109
struct module_cb_list list = MODULE_CB_LIST_INIT;
1112
strvec_push(&diff_args, get_diff_cmd(diff_cmd));
1114
strvec_push(&diff_args, "--cached");
1115
strvec_pushl(&diff_args, "--ignore-submodules=dirty", "--raw", NULL);
1117
strvec_push(&diff_args, oid_to_hex(head_oid));
1118
strvec_push(&diff_args, "--");
1120
strvec_pushv(&diff_args, info->argv);
1122
git_config(git_diff_basic_config, NULL);
1123
repo_init_revisions(the_repository, &rev, info->prefix);
1125
precompose_argv_prefix(diff_args.nr, diff_args.v, NULL);
1126
setup_revisions(diff_args.nr, diff_args.v, &rev, &opt);
1127
rev.diffopt.output_format = DIFF_FORMAT_NO_OUTPUT | DIFF_FORMAT_CALLBACK;
1128
rev.diffopt.format_callback = submodule_summary_callback;
1129
rev.diffopt.format_callback_data = &list;
1131
if (!info->cached) {
1132
if (diff_cmd == DIFF_INDEX)
1134
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
1135
perror("repo_read_index_preload");
1139
} else if (repo_read_index(the_repository) < 0) {
1140
perror("repo_read_cache");
1145
if (diff_cmd == DIFF_INDEX)
1146
run_diff_index(&rev, info->cached ? DIFF_INDEX_CACHED : 0);
1148
run_diff_files(&rev, 0);
1149
prepare_submodule_summary(info, &list);
1151
strvec_clear(&diff_args);
1152
release_revisions(&rev);
1153
module_cb_list_release(&list);
1157
static int module_summary(int argc, const char **argv, const char *prefix)
1159
struct summary_cb info = SUMMARY_CB_INIT;
1163
int summary_limit = -1;
1164
enum diff_cmd diff_cmd = DIFF_INDEX;
1165
struct object_id head_oid;
1167
struct option module_summary_options[] = {
1168
OPT_BOOL(0, "cached", &cached,
1169
N_("use the commit stored in the index instead of the submodule HEAD")),
1170
OPT_BOOL(0, "files", &files,
1171
N_("compare the commit in the index with that in the submodule HEAD")),
1172
OPT_BOOL(0, "for-status", &for_status,
1173
N_("skip submodules with 'ignore_config' value set to 'all'")),
1174
OPT_INTEGER('n', "summary-limit", &summary_limit,
1175
N_("limit the summary size")),
1178
const char *const git_submodule_helper_usage[] = {
1179
N_("git submodule summary [<options>] [<commit>] [--] [<path>]"),
1183
argc = parse_options(argc, argv, prefix, module_summary_options,
1184
git_submodule_helper_usage, 0);
1189
if (!repo_get_oid(the_repository, argc ? argv[0] : "HEAD", &head_oid)) {
1194
} else if (!argc || !strcmp(argv[0], "HEAD")) {
1196
oidcpy(&head_oid, the_hash_algo->empty_tree);
1202
if (repo_get_oid(the_repository, "HEAD", &head_oid))
1203
die(_("could not fetch a revision for HEAD"));
1208
die(_("options '%s' and '%s' cannot be used together"), "--cached", "--files");
1209
diff_cmd = DIFF_FILES;
1214
info.prefix = prefix;
1215
info.cached = !!cached;
1216
info.files = !!files;
1217
info.for_status = !!for_status;
1218
info.summary_limit = summary_limit;
1220
ret = compute_summary_module_list((diff_cmd == DIFF_INDEX) ? &head_oid : NULL,
1227
const char *super_prefix;
1230
#define SYNC_CB_INIT { 0 }
1232
static void sync_submodule(const char *path, const char *prefix,
1233
const char *super_prefix, unsigned int flags)
1235
const struct submodule *sub;
1236
char *remote_key = NULL;
1237
char *sub_origin_url, *super_config_url, *displaypath, *default_remote;
1238
struct strbuf sb = STRBUF_INIT;
1239
char *sub_config_path = NULL;
1242
if (!is_submodule_active(the_repository, path))
1245
if (validate_submodule_path(path) < 0)
1248
sub = submodule_from_path(the_repository, null_oid(), path);
1250
if (sub && sub->url) {
1251
if (starts_with_dot_dot_slash(sub->url) ||
1252
starts_with_dot_slash(sub->url)) {
1253
char *up_path = get_up_path(path);
1255
sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
1256
super_config_url = resolve_relative_url(sub->url, NULL, 1);
1259
sub_origin_url = xstrdup(sub->url);
1260
super_config_url = xstrdup(sub->url);
1263
sub_origin_url = xstrdup("");
1264
super_config_url = xstrdup("");
1267
displaypath = get_submodule_displaypath(path, prefix, super_prefix);
1269
if (!(flags & OPT_QUIET))
1270
printf(_("Synchronizing submodule url for '%s'\n"),
1274
strbuf_addf(&sb, "submodule.%s.url", sub->name);
1275
if (git_config_set_gently(sb.buf, super_config_url))
1276
die(_("failed to register url for submodule path '%s'"),
1279
if (!is_submodule_populated_gently(path, NULL))
1283
code = get_default_remote_submodule(path, &default_remote);
1287
remote_key = xstrfmt("remote.%s.url", default_remote);
1288
free(default_remote);
1290
submodule_to_gitdir(&sb, path);
1291
strbuf_addstr(&sb, "/config");
1293
if (git_config_set_in_file_gently(sb.buf, remote_key, NULL, sub_origin_url))
1294
die(_("failed to update remote for submodule '%s'"),
1297
if (flags & OPT_RECURSIVE) {
1298
struct child_process cpr = CHILD_PROCESS_INIT;
1302
prepare_submodule_repo_env(&cpr.env);
1304
strvec_pushl(&cpr.args, "submodule--helper", "sync",
1305
"--recursive", NULL);
1306
strvec_pushf(&cpr.args, "--super-prefix=%s/", displaypath);
1308
if (flags & OPT_QUIET)
1309
strvec_push(&cpr.args, "--quiet");
1311
if (run_command(&cpr))
1312
die(_("failed to recurse into submodule '%s'"),
1317
free(super_config_url);
1318
free(sub_origin_url);
1319
strbuf_release(&sb);
1322
free(sub_config_path);
1325
static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data)
1327
struct sync_cb *info = cb_data;
1329
sync_submodule(list_item->name, info->prefix, info->super_prefix,
1333
static int module_sync(int argc, const char **argv, const char *prefix)
1335
struct sync_cb info = SYNC_CB_INIT;
1336
struct pathspec pathspec = { 0 };
1337
struct module_list list = MODULE_LIST_INIT;
1340
struct option module_sync_options[] = {
1341
OPT__SUPER_PREFIX(&info.super_prefix),
1342
OPT__QUIET(&quiet, N_("suppress output of synchronizing submodule url")),
1343
OPT_BOOL(0, "recursive", &recursive,
1344
N_("recurse into nested submodules")),
1347
const char *const git_submodule_helper_usage[] = {
1348
N_("git submodule sync [--quiet] [--recursive] [<path>]"),
1353
argc = parse_options(argc, argv, prefix, module_sync_options,
1354
git_submodule_helper_usage, 0);
1356
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
1359
info.prefix = prefix;
1361
info.flags |= OPT_QUIET;
1363
info.flags |= OPT_RECURSIVE;
1365
for_each_listed_submodule(&list, sync_submodule_cb, &info);
1369
module_list_release(&list);
1370
clear_pathspec(&pathspec);
1378
#define DEINIT_CB_INIT { 0 }
1380
static void deinit_submodule(const char *path, const char *prefix,
1383
const struct submodule *sub;
1384
char *displaypath = NULL;
1385
struct child_process cp_config = CHILD_PROCESS_INIT;
1386
struct strbuf sb_config = STRBUF_INIT;
1387
char *sub_git_dir = xstrfmt("%s/.git", path);
1389
if (validate_submodule_path(path) < 0)
1392
sub = submodule_from_path(the_repository, null_oid(), path);
1394
if (!sub || !sub->name)
1397
displaypath = get_submodule_displaypath(path, prefix, NULL);
1400
if (is_directory(path)) {
1401
struct strbuf sb_rm = STRBUF_INIT;
1404
if (is_directory(sub_git_dir)) {
1405
if (!(flags & OPT_QUIET))
1406
warning(_("Submodule work tree '%s' contains a .git "
1407
"directory. This will be replaced with a "
1408
".git file by using absorbgitdirs."),
1411
absorb_git_dir_into_superproject(path, NULL);
1415
if (!(flags & OPT_FORCE)) {
1416
struct child_process cp_rm = CHILD_PROCESS_INIT;
1419
strvec_pushl(&cp_rm.args, "rm", "-qn",
1422
if (run_command(&cp_rm))
1423
die(_("Submodule work tree '%s' contains local "
1424
"modifications; use '-f' to discard them"),
1428
strbuf_addstr(&sb_rm, path);
1430
if (!remove_dir_recursively(&sb_rm, 0))
1431
format = _("Cleared directory '%s'\n");
1433
format = _("Could not remove submodule work tree '%s'\n");
1435
if (!(flags & OPT_QUIET))
1436
printf(format, displaypath);
1438
submodule_unset_core_worktree(sub);
1440
strbuf_release(&sb_rm);
1443
if (mkdir(path, 0777))
1444
printf(_("could not create empty submodule directory %s"),
1447
cp_config.git_cmd = 1;
1448
strvec_pushl(&cp_config.args, "config", "--get-regexp", NULL);
1449
strvec_pushf(&cp_config.args, "submodule.%s\\.", sub->name);
1452
if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) {
1453
char *sub_key = xstrfmt("submodule.%s", sub->name);
1459
repo_config_rename_section_in_file(the_repository, NULL, sub_key, NULL);
1460
if (!(flags & OPT_QUIET))
1461
printf(_("Submodule '%s' (%s) unregistered for path '%s'\n"),
1462
sub->name, sub->url, displaypath);
1469
strbuf_release(&sb_config);
1472
static void deinit_submodule_cb(const struct cache_entry *list_item,
1475
struct deinit_cb *info = cb_data;
1476
deinit_submodule(list_item->name, info->prefix, info->flags);
1479
static int module_deinit(int argc, const char **argv, const char *prefix)
1481
struct deinit_cb info = DEINIT_CB_INIT;
1482
struct pathspec pathspec = { 0 };
1483
struct module_list list = MODULE_LIST_INIT;
1487
struct option module_deinit_options[] = {
1488
OPT__QUIET(&quiet, N_("suppress submodule status output")),
1489
OPT__FORCE(&force, N_("remove submodule working trees even if they contain local changes"), 0),
1490
OPT_BOOL(0, "all", &all, N_("unregister all submodules")),
1493
const char *const git_submodule_helper_usage[] = {
1494
N_("git submodule deinit [--quiet] [-f | --force] [--all | [--] [<path>...]]"),
1499
argc = parse_options(argc, argv, prefix, module_deinit_options,
1500
git_submodule_helper_usage, 0);
1503
error("pathspec and --all are incompatible");
1504
usage_with_options(git_submodule_helper_usage,
1505
module_deinit_options);
1509
die(_("Use '--all' if you really want to deinitialize all submodules"));
1511
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
1514
info.prefix = prefix;
1516
info.flags |= OPT_QUIET;
1518
info.flags |= OPT_FORCE;
1520
for_each_listed_submodule(&list, deinit_submodule_cb, &info);
1524
module_list_release(&list);
1525
clear_pathspec(&pathspec);
1529
struct module_clone_data {
1535
struct list_objects_filter_options *filter_options;
1536
enum ref_storage_format ref_storage_format;
1537
unsigned int quiet: 1;
1538
unsigned int progress: 1;
1539
unsigned int dissociate: 1;
1540
unsigned int require_init: 1;
1543
#define MODULE_CLONE_DATA_INIT { \
1544
.single_branch = -1, \
1545
.ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN, \
1548
struct submodule_alternate_setup {
1549
const char *submodule_name;
1550
enum SUBMODULE_ALTERNATE_ERROR_MODE {
1551
SUBMODULE_ALTERNATE_ERROR_DIE,
1552
SUBMODULE_ALTERNATE_ERROR_INFO,
1553
SUBMODULE_ALTERNATE_ERROR_IGNORE
1555
struct string_list *reference;
1557
#define SUBMODULE_ALTERNATE_SETUP_INIT { \
1558
.error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE, \
1561
static const char alternate_error_advice[] = N_(
1562
"An alternate computed from a superproject's alternate is invalid.\n"
1563
"To allow Git to clone without an alternate in such a case, set\n"
1564
"submodule.alternateErrorStrategy to 'info' or, equivalently, clone with\n"
1565
"'--reference-if-able' instead of '--reference'."
1568
static int add_possible_reference_from_superproject(
1569
struct object_directory *odb, void *sas_cb)
1571
struct submodule_alternate_setup *sas = sas_cb;
1578
if (strip_suffix(odb->path, "/objects", &len)) {
1579
struct repository alternate;
1581
struct strbuf sb = STRBUF_INIT;
1582
struct strbuf err = STRBUF_INIT;
1583
strbuf_add(&sb, odb->path, len);
1585
if (repo_init(&alternate, sb.buf, NULL) < 0)
1586
die(_("could not get a repository handle for gitdir '%s'"),
1596
submodule_name_to_gitdir(&sb, &alternate, sas->submodule_name);
1597
strbuf_addch(&sb, '/');
1598
repo_clear(&alternate);
1600
sm_alternate = compute_alternate_path(sb.buf, &err);
1602
char *p = strbuf_detach(&sb, NULL);
1604
string_list_append(sas->reference, p)->util = p;
1607
switch (sas->error_mode) {
1608
case SUBMODULE_ALTERNATE_ERROR_DIE:
1609
if (advice_enabled(ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE))
1610
advise(_(alternate_error_advice));
1611
die(_("submodule '%s' cannot add alternate: %s"),
1612
sas->submodule_name, err.buf);
1613
case SUBMODULE_ALTERNATE_ERROR_INFO:
1614
fprintf_ln(stderr, _("submodule '%s' cannot add alternate: %s"),
1615
sas->submodule_name, err.buf);
1616
case SUBMODULE_ALTERNATE_ERROR_IGNORE:
1620
strbuf_release(&sb);
1626
static void prepare_possible_alternates(const char *sm_name,
1627
struct string_list *reference)
1629
char *sm_alternate = NULL, *error_strategy = NULL;
1630
struct submodule_alternate_setup sas = SUBMODULE_ALTERNATE_SETUP_INIT;
1632
git_config_get_string("submodule.alternateLocation", &sm_alternate);
1636
git_config_get_string("submodule.alternateErrorStrategy", &error_strategy);
1638
if (!error_strategy)
1639
error_strategy = xstrdup("die");
1641
sas.submodule_name = sm_name;
1642
sas.reference = reference;
1643
if (!strcmp(error_strategy, "die"))
1644
sas.error_mode = SUBMODULE_ALTERNATE_ERROR_DIE;
1645
else if (!strcmp(error_strategy, "info"))
1646
sas.error_mode = SUBMODULE_ALTERNATE_ERROR_INFO;
1647
else if (!strcmp(error_strategy, "ignore"))
1648
sas.error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE;
1650
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
1652
if (!strcmp(sm_alternate, "superproject"))
1653
foreach_alt_odb(add_possible_reference_from_superproject, &sas);
1654
else if (!strcmp(sm_alternate, "no"))
1657
die(_("Value '%s' for submodule.alternateLocation is not recognized"), sm_alternate);
1660
free(error_strategy);
1663
static char *clone_submodule_sm_gitdir(const char *name)
1665
struct strbuf sb = STRBUF_INIT;
1668
submodule_name_to_gitdir(&sb, the_repository, name);
1669
sm_gitdir = absolute_pathdup(sb.buf);
1670
strbuf_release(&sb);
1675
static int dir_contains_only_dotgit(const char *path)
1677
DIR *dir = opendir(path);
1684
e = readdir_skip_dot_and_dotdot(dir);
1687
else if (strcmp(DEFAULT_GIT_DIR_ENVIRONMENT, e->d_name) ||
1688
(e = readdir_skip_dot_and_dotdot(dir))) {
1689
error("unexpected item '%s' in '%s'", e->d_name, path);
1697
static int clone_submodule(const struct module_clone_data *clone_data,
1698
struct string_list *reference)
1701
char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name);
1702
char *sm_alternate = NULL, *error_strategy = NULL;
1704
struct child_process cp = CHILD_PROCESS_INIT;
1705
const char *clone_data_path = clone_data->path;
1706
char *to_free = NULL;
1708
if (validate_submodule_path(clone_data_path) < 0)
1711
if (!is_absolute_path(clone_data->path))
1712
clone_data_path = to_free = xstrfmt("%s/%s", get_git_work_tree(),
1715
if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
1716
die(_("refusing to create/use '%s' in another submodule's "
1717
"git dir"), sm_gitdir);
1719
if (!file_exists(sm_gitdir)) {
1720
if (clone_data->require_init && !stat(clone_data_path, &st) &&
1721
!is_empty_dir(clone_data_path))
1722
die(_("directory not empty: '%s'"), clone_data_path);
1724
if (safe_create_leading_directories_const(sm_gitdir) < 0)
1725
die(_("could not create directory '%s'"), sm_gitdir);
1727
prepare_possible_alternates(clone_data->name, reference);
1729
strvec_push(&cp.args, "clone");
1730
strvec_push(&cp.args, "--no-checkout");
1731
if (clone_data->quiet)
1732
strvec_push(&cp.args, "--quiet");
1733
if (clone_data->progress)
1734
strvec_push(&cp.args, "--progress");
1735
if (clone_data->depth > 0)
1736
strvec_pushf(&cp.args, "--depth=%d", clone_data->depth);
1737
if (reference->nr) {
1738
struct string_list_item *item;
1740
for_each_string_list_item(item, reference)
1741
strvec_pushl(&cp.args, "--reference",
1742
item->string, NULL);
1744
if (clone_data->ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
1745
strvec_pushf(&cp.args, "--ref-format=%s",
1746
ref_storage_format_to_name(clone_data->ref_storage_format));
1747
if (clone_data->dissociate)
1748
strvec_push(&cp.args, "--dissociate");
1749
if (sm_gitdir && *sm_gitdir)
1750
strvec_pushl(&cp.args, "--separate-git-dir", sm_gitdir, NULL);
1751
if (clone_data->filter_options && clone_data->filter_options->choice)
1752
strvec_pushf(&cp.args, "--filter=%s",
1753
expand_list_objects_filter_spec(
1754
clone_data->filter_options));
1755
if (clone_data->single_branch >= 0)
1756
strvec_push(&cp.args, clone_data->single_branch ?
1758
"--no-single-branch");
1760
strvec_push(&cp.args, "--");
1761
strvec_push(&cp.args, clone_data->url);
1762
strvec_push(&cp.args, clone_data_path);
1765
prepare_submodule_repo_env(&cp.env);
1768
if(run_command(&cp))
1769
die(_("clone of '%s' into submodule path '%s' failed"),
1770
clone_data->url, clone_data_path);
1772
if (clone_data->require_init && !stat(clone_data_path, &st) &&
1773
!dir_contains_only_dotgit(clone_data_path)) {
1774
char *dot_git = xstrfmt("%s/.git", clone_data_path);
1777
die(_("directory not empty: '%s'"), clone_data_path);
1782
if (clone_data->require_init && !stat(clone_data_path, &st) &&
1783
!is_empty_dir(clone_data_path))
1784
die(_("directory not empty: '%s'"), clone_data_path);
1785
if (safe_create_leading_directories_const(clone_data_path) < 0)
1786
die(_("could not create directory '%s'"), clone_data_path);
1787
path = xstrfmt("%s/index", sm_gitdir);
1788
unlink_or_warn(path);
1801
if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0) {
1802
char *head = xstrfmt("%s/HEAD", sm_gitdir);
1805
die(_("refusing to create/use '%s' in another submodule's "
1806
"git dir"), sm_gitdir);
1809
connect_work_tree_and_git_dir(clone_data_path, sm_gitdir, 0);
1811
p = git_pathdup_submodule(clone_data_path, "config");
1813
die(_("could not get submodule directory for '%s'"), clone_data_path);
1816
git_config_get_string("submodule.alternateLocation", &sm_alternate);
1818
git_config_set_in_file(p, "submodule.alternateLocation",
1820
git_config_get_string("submodule.alternateErrorStrategy", &error_strategy);
1822
git_config_set_in_file(p, "submodule.alternateErrorStrategy",
1826
free(error_strategy);
1834
static int module_clone(int argc, const char **argv, const char *prefix)
1836
int dissociate = 0, quiet = 0, progress = 0, require_init = 0;
1837
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
1838
struct string_list reference = STRING_LIST_INIT_NODUP;
1839
struct list_objects_filter_options filter_options =
1840
LIST_OBJECTS_FILTER_INIT;
1841
const char *ref_storage_format = NULL;
1843
struct option module_clone_options[] = {
1844
OPT_STRING(0, "prefix", &clone_data.prefix,
1846
N_("alternative anchor for relative paths")),
1847
OPT_STRING(0, "path", &clone_data.path,
1849
N_("where the new submodule will be cloned to")),
1850
OPT_STRING(0, "name", &clone_data.name,
1852
N_("name of the new submodule")),
1853
OPT_STRING(0, "url", &clone_data.url,
1855
N_("url where to clone the submodule from")),
1856
OPT_STRING_LIST(0, "reference", &reference,
1858
N_("reference repository")),
1859
OPT_STRING(0, "ref-format", &ref_storage_format, N_("format"),
1860
N_("specify the reference format to use")),
1861
OPT_BOOL(0, "dissociate", &dissociate,
1862
N_("use --reference only while cloning")),
1863
OPT_INTEGER(0, "depth", &clone_data.depth,
1864
N_("depth for shallow clones")),
1865
OPT__QUIET(&quiet, "suppress output for cloning a submodule"),
1866
OPT_BOOL(0, "progress", &progress,
1867
N_("force cloning progress")),
1868
OPT_BOOL(0, "require-init", &require_init,
1869
N_("disallow cloning into non-empty directory")),
1870
OPT_BOOL(0, "single-branch", &clone_data.single_branch,
1871
N_("clone only one branch, HEAD or --branch")),
1872
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
1875
const char *const git_submodule_helper_usage[] = {
1876
N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
1877
"[--reference <repository>] [--name <name>] [--depth <depth>] "
1878
"[--single-branch] [--filter <filter-spec>] "
1879
"--url <url> --path <path>"),
1883
argc = parse_options(argc, argv, prefix, module_clone_options,
1884
git_submodule_helper_usage, 0);
1886
if (ref_storage_format) {
1887
clone_data.ref_storage_format = ref_storage_format_by_name(ref_storage_format);
1888
if (clone_data.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
1889
die(_("unknown ref storage format '%s'"), ref_storage_format);
1891
clone_data.dissociate = !!dissociate;
1892
clone_data.quiet = !!quiet;
1893
clone_data.progress = !!progress;
1894
clone_data.require_init = !!require_init;
1895
clone_data.filter_options = &filter_options;
1897
if (argc || !clone_data.url || !clone_data.path || !*(clone_data.path))
1898
usage_with_options(git_submodule_helper_usage,
1899
module_clone_options);
1901
clone_submodule(&clone_data, &reference);
1902
list_objects_filter_release(&filter_options);
1903
string_list_clear(&reference, 1);
1907
static int determine_submodule_update_strategy(struct repository *r,
1910
enum submodule_update_type update,
1911
struct submodule_update_strategy *out)
1913
const struct submodule *sub = submodule_from_path(r, null_oid(), path);
1918
key = xstrfmt("submodule.%s.update", sub->name);
1922
} else if (!repo_config_get_string_tmp(r, key, &val)) {
1923
if (parse_submodule_update_strategy(val, out) < 0) {
1924
ret = die_message(_("Invalid update mode '%s' configured for submodule path '%s'"),
1928
} else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
1929
if (sub->update_strategy.type == SM_UPDATE_COMMAND)
1930
BUG("how did we read update = !command from .gitmodules?");
1931
out->type = sub->update_strategy.type;
1932
out->command = sub->update_strategy.command;
1934
out->type = SM_UPDATE_CHECKOUT;
1937
(out->type == SM_UPDATE_MERGE ||
1938
out->type == SM_UPDATE_REBASE ||
1939
out->type == SM_UPDATE_NONE))
1940
out->type = SM_UPDATE_CHECKOUT;
1948
struct update_clone_data {
1949
const struct submodule *sub;
1950
struct object_id oid;
1951
unsigned just_cloned;
1954
struct submodule_update_clone {
1959
const struct update_data *update_data;
1962
struct update_clone_data *update_clone;
1963
int update_clone_nr; int update_clone_alloc;
1966
unsigned quickstop : 1;
1969
const struct cache_entry **failed_clones;
1970
int failed_clones_nr, failed_clones_alloc;
1972
#define SUBMODULE_UPDATE_CLONE_INIT { 0 }
1974
static void submodule_update_clone_release(struct submodule_update_clone *suc)
1976
free(suc->update_clone);
1977
free(suc->failed_clones);
1982
const char *super_prefix;
1984
enum submodule_update_type update_default;
1985
struct object_id suboid;
1986
struct string_list references;
1987
struct submodule_update_strategy update_strategy;
1988
struct list_objects_filter_options *filter_options;
1989
struct module_list list;
1990
enum ref_storage_format ref_storage_format;
1994
int recommend_shallow;
1995
unsigned int require_init;
1998
unsigned int nofetch;
1999
unsigned int remote;
2000
unsigned int progress;
2001
unsigned int dissociate;
2003
unsigned int warn_if_uninitialized;
2004
unsigned int recursive;
2007
struct object_id oid;
2008
unsigned int just_cloned;
2009
const char *sm_path;
2011
#define UPDATE_DATA_INIT { \
2012
.update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT, \
2013
.list = MODULE_LIST_INIT, \
2014
.ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN, \
2015
.recommend_shallow = -1, \
2016
.references = STRING_LIST_INIT_DUP, \
2017
.single_branch = -1, \
2021
static void update_data_release(struct update_data *ud)
2023
free(ud->displaypath);
2024
module_list_release(&ud->list);
2027
static void next_submodule_warn_missing(struct submodule_update_clone *suc,
2028
struct strbuf *out, const char *displaypath)
2034
if (suc->update_data->warn_if_uninitialized) {
2036
_("Submodule path '%s' not initialized"),
2038
strbuf_addch(out, '\n');
2040
_("Maybe you want to use 'update --init'?"));
2041
strbuf_addch(out, '\n');
2049
static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
2050
struct child_process *child,
2051
struct submodule_update_clone *suc,
2054
const struct submodule *sub = NULL;
2055
const char *url = NULL;
2056
const char *update_string;
2057
enum submodule_update_type update_type;
2059
const struct update_data *ud = suc->update_data;
2060
char *displaypath = get_submodule_displaypath(ce->name, ud->prefix,
2062
struct strbuf sb = STRBUF_INIT;
2063
int needs_cloning = 0;
2064
int need_free_url = 0;
2067
strbuf_addf(out, _("Skipping unmerged submodule %s"), displaypath);
2068
strbuf_addch(out, '\n');
2072
sub = submodule_from_path(the_repository, null_oid(), ce->name);
2075
next_submodule_warn_missing(suc, out, displaypath);
2079
key = xstrfmt("submodule.%s.update", sub->name);
2080
if (!repo_config_get_string_tmp(the_repository, key, &update_string)) {
2081
update_type = parse_submodule_update_type(update_string);
2083
update_type = sub->update_strategy.type;
2087
if (suc->update_data->update_strategy.type == SM_UPDATE_NONE
2088
|| (suc->update_data->update_strategy.type == SM_UPDATE_UNSPECIFIED
2089
&& update_type == SM_UPDATE_NONE)) {
2090
strbuf_addf(out, _("Skipping submodule '%s'"), displaypath);
2091
strbuf_addch(out, '\n');
2096
if (!is_submodule_active(the_repository, ce->name)) {
2097
next_submodule_warn_missing(suc, out, displaypath);
2102
strbuf_addf(&sb, "submodule.%s.url", sub->name);
2103
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
2104
if (sub->url && (starts_with_dot_slash(sub->url) ||
2105
starts_with_dot_dot_slash(sub->url))) {
2106
url = resolve_relative_url(sub->url, NULL, 0);
2113
die(_("cannot clone submodule '%s' without a URL"), sub->name);
2116
strbuf_addf(&sb, "%s/.git", ce->name);
2117
needs_cloning = !file_exists(sb.buf);
2119
ALLOC_GROW(suc->update_clone, suc->update_clone_nr + 1,
2120
suc->update_clone_alloc);
2121
oidcpy(&suc->update_clone[suc->update_clone_nr].oid, &ce->oid);
2122
suc->update_clone[suc->update_clone_nr].just_cloned = needs_cloning;
2123
suc->update_clone[suc->update_clone_nr].sub = sub;
2124
suc->update_clone_nr++;
2130
child->no_stdin = 1;
2131
child->stdout_to_stderr = 1;
2133
strvec_push(&child->args, "submodule--helper");
2134
strvec_push(&child->args, "clone");
2135
if (suc->update_data->progress)
2136
strvec_push(&child->args, "--progress");
2137
if (suc->update_data->quiet)
2138
strvec_push(&child->args, "--quiet");
2139
if (suc->update_data->prefix)
2140
strvec_pushl(&child->args, "--prefix", suc->update_data->prefix, NULL);
2141
if (suc->update_data->recommend_shallow && sub->recommend_shallow == 1)
2142
strvec_push(&child->args, "--depth=1");
2143
else if (suc->update_data->depth)
2144
strvec_pushf(&child->args, "--depth=%d", suc->update_data->depth);
2145
if (suc->update_data->filter_options && suc->update_data->filter_options->choice)
2146
strvec_pushf(&child->args, "--filter=%s",
2147
expand_list_objects_filter_spec(suc->update_data->filter_options));
2148
if (suc->update_data->require_init)
2149
strvec_push(&child->args, "--require-init");
2150
if (suc->update_data->ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
2151
strvec_pushf(&child->args, "--ref-format=%s",
2152
ref_storage_format_to_name(suc->update_data->ref_storage_format));
2153
strvec_pushl(&child->args, "--path", sub->path, NULL);
2154
strvec_pushl(&child->args, "--name", sub->name, NULL);
2155
strvec_pushl(&child->args, "--url", url, NULL);
2156
if (suc->update_data->references.nr) {
2157
struct string_list_item *item;
2159
for_each_string_list_item(item, &suc->update_data->references)
2160
strvec_pushl(&child->args, "--reference", item->string, NULL);
2162
if (suc->update_data->dissociate)
2163
strvec_push(&child->args, "--dissociate");
2164
if (suc->update_data->single_branch >= 0)
2165
strvec_push(&child->args, suc->update_data->single_branch ?
2167
"--no-single-branch");
2171
strbuf_release(&sb);
2175
return needs_cloning;
2178
static int update_clone_get_next_task(struct child_process *child,
2183
struct submodule_update_clone *suc = suc_cb;
2184
const struct cache_entry *ce;
2187
for (; suc->current < suc->update_data->list.nr; suc->current++) {
2188
ce = suc->update_data->list.entries[suc->current];
2189
if (prepare_to_clone_next_submodule(ce, child, suc, err)) {
2190
int *p = xmalloc(sizeof(*p));
2204
index = suc->current - suc->update_data->list.nr;
2205
if (index < suc->failed_clones_nr) {
2208
ce = suc->failed_clones[index];
2209
if (!prepare_to_clone_next_submodule(ce, child, suc, err)) {
2211
strbuf_addstr(err, "BUG: submodule considered for "
2212
"cloning, doesn't need cloning "
2216
p = xmalloc(sizeof(*p));
2226
static int update_clone_start_failure(struct strbuf *err UNUSED,
2228
void *idx_task_cb UNUSED)
2230
struct submodule_update_clone *suc = suc_cb;
2236
static int update_clone_task_finished(int result,
2241
const struct cache_entry *ce;
2242
struct submodule_update_clone *suc = suc_cb;
2243
int *idxP = idx_task_cb;
2251
if (idx < suc->update_data->list.nr) {
2252
ce = suc->update_data->list.entries[idx];
2253
strbuf_addf(err, _("Failed to clone '%s'. Retry scheduled"),
2255
strbuf_addch(err, '\n');
2256
ALLOC_GROW(suc->failed_clones,
2257
suc->failed_clones_nr + 1,
2258
suc->failed_clones_alloc);
2259
suc->failed_clones[suc->failed_clones_nr++] = ce;
2262
idx -= suc->update_data->list.nr;
2263
ce = suc->failed_clones[idx];
2264
strbuf_addf(err, _("Failed to clone '%s' a second time, aborting"),
2266
strbuf_addch(err, '\n');
2274
static int git_update_clone_config(const char *var, const char *value,
2275
const struct config_context *ctx,
2280
if (!strcmp(var, "submodule.fetchjobs"))
2281
*max_jobs = parse_submodule_fetchjobs(var, value, ctx->kvi);
2285
static int is_tip_reachable(const char *path, const struct object_id *oid)
2287
struct child_process cp = CHILD_PROCESS_INIT;
2288
struct strbuf rev = STRBUF_INIT;
2289
char *hex = oid_to_hex(oid);
2295
strvec_pushl(&cp.args, "rev-list", "-n", "1", hex, "--not", "--all", NULL);
2297
prepare_submodule_repo_env(&cp.env);
2299
if (capture_command(&cp, &rev, GIT_MAX_HEXSZ + 1) || rev.len)
2304
strbuf_release(&rev);
2308
static int fetch_in_submodule(const char *module_path, int depth, int quiet,
2309
const struct object_id *oid)
2311
struct child_process cp = CHILD_PROCESS_INIT;
2313
prepare_submodule_repo_env(&cp.env);
2315
cp.dir = module_path;
2317
strvec_push(&cp.args, "fetch");
2319
strvec_push(&cp.args, "--quiet");
2321
strvec_pushf(&cp.args, "--depth=%d", depth);
2323
char *hex = oid_to_hex(oid);
2324
char *remote = get_default_remote();
2326
strvec_pushl(&cp.args, remote, hex, NULL);
2330
return run_command(&cp);
2333
static int run_update_command(const struct update_data *ud, int subforce)
2335
struct child_process cp = CHILD_PROCESS_INIT;
2336
char *oid = oid_to_hex(&ud->oid);
2339
switch (ud->update_strategy.type) {
2340
case SM_UPDATE_CHECKOUT:
2342
strvec_pushl(&cp.args, "checkout", "-q", NULL);
2344
strvec_push(&cp.args, "-f");
2346
case SM_UPDATE_REBASE:
2348
strvec_push(&cp.args, "rebase");
2350
strvec_push(&cp.args, "--quiet");
2352
case SM_UPDATE_MERGE:
2354
strvec_push(&cp.args, "merge");
2356
strvec_push(&cp.args, "--quiet");
2358
case SM_UPDATE_COMMAND:
2360
strvec_push(&cp.args, ud->update_strategy.command);
2363
BUG("unexpected update strategy type: %d",
2364
ud->update_strategy.type);
2366
strvec_push(&cp.args, oid);
2368
cp.dir = ud->sm_path;
2369
prepare_submodule_repo_env(&cp.env);
2370
if ((ret = run_command(&cp))) {
2371
switch (ud->update_strategy.type) {
2372
case SM_UPDATE_CHECKOUT:
2373
die_message(_("Unable to checkout '%s' in submodule path '%s'"),
2374
oid, ud->displaypath);
2377
case SM_UPDATE_REBASE:
2378
ret = die_message(_("Unable to rebase '%s' in submodule path '%s'"),
2379
oid, ud->displaypath);
2381
case SM_UPDATE_MERGE:
2382
ret = die_message(_("Unable to merge '%s' in submodule path '%s'"),
2383
oid, ud->displaypath);
2385
case SM_UPDATE_COMMAND:
2386
ret = die_message(_("Execution of '%s %s' failed in submodule path '%s'"),
2387
ud->update_strategy.command, oid, ud->displaypath);
2390
BUG("unexpected update strategy type: %d",
2391
ud->update_strategy.type);
2400
switch (ud->update_strategy.type) {
2401
case SM_UPDATE_CHECKOUT:
2402
printf(_("Submodule path '%s': checked out '%s'\n"),
2403
ud->displaypath, oid);
2405
case SM_UPDATE_REBASE:
2406
printf(_("Submodule path '%s': rebased into '%s'\n"),
2407
ud->displaypath, oid);
2409
case SM_UPDATE_MERGE:
2410
printf(_("Submodule path '%s': merged in '%s'\n"),
2411
ud->displaypath, oid);
2413
case SM_UPDATE_COMMAND:
2414
printf(_("Submodule path '%s': '%s %s'\n"),
2415
ud->displaypath, ud->update_strategy.command, oid);
2418
BUG("unexpected update strategy type: %d",
2419
ud->update_strategy.type);
2425
static int run_update_procedure(const struct update_data *ud)
2427
int subforce = is_null_oid(&ud->suboid) || ud->force;
2434
if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
2435
fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, NULL) &&
2438
_("Unable to fetch in submodule path '%s'; "
2439
"trying to directly fetch %s:"),
2440
ud->displaypath, oid_to_hex(&ud->oid));
2445
if (!is_tip_reachable(ud->sm_path, &ud->oid) &&
2446
fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, &ud->oid))
2447
return die_message(_("Fetched in submodule path '%s', but it did not "
2448
"contain %s. Direct fetching of that commit failed."),
2449
ud->displaypath, oid_to_hex(&ud->oid));
2452
return run_update_command(ud, subforce);
2455
static int remote_submodule_branch(const char *path, const char **branch)
2457
const struct submodule *sub;
2461
sub = submodule_from_path(the_repository, null_oid(), path);
2463
return die_message(_("could not initialize submodule at path '%s'"),
2466
key = xstrfmt("submodule.%s.branch", sub->name);
2467
if (repo_config_get_string_tmp(the_repository, key, branch))
2468
*branch = sub->branch;
2476
if (!strcmp(*branch, ".")) {
2477
const char *refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
2482
return die_message(_("No such ref: %s"), "HEAD");
2485
if (!strcmp(refname, "HEAD"))
2486
return die_message(_("Submodule (%s) branch configured to inherit "
2487
"branch from superproject, but the superproject "
2488
"is not on any branch"), sub->name);
2490
if (!skip_prefix(refname, "refs/heads/", &refname))
2491
return die_message(_("Expecting a full ref name, got %s"),
2502
static int ensure_core_worktree(const char *path)
2505
struct repository subrepo;
2507
if (repo_submodule_init(&subrepo, the_repository, path, null_oid()))
2508
return die_message(_("could not get a repository handle for submodule '%s'"),
2511
if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {
2512
char *cfg_file, *abs_path;
2513
const char *rel_path;
2514
struct strbuf sb = STRBUF_INIT;
2516
cfg_file = repo_git_path(&subrepo, "config");
2518
abs_path = absolute_pathdup(path);
2519
rel_path = relative_path(abs_path, subrepo.gitdir, &sb);
2521
git_config_set_in_file(cfg_file, "core.worktree", rel_path);
2525
strbuf_release(&sb);
2528
repo_clear(&subrepo);
2532
static const char *submodule_update_type_to_label(enum submodule_update_type type)
2535
case SM_UPDATE_CHECKOUT:
2537
case SM_UPDATE_MERGE:
2539
case SM_UPDATE_REBASE:
2541
case SM_UPDATE_UNSPECIFIED:
2542
case SM_UPDATE_NONE:
2543
case SM_UPDATE_COMMAND:
2546
BUG("unreachable with type %d", type);
2549
static void update_data_to_args(const struct update_data *update_data,
2550
struct strvec *args)
2552
enum submodule_update_type update_type = update_data->update_default;
2554
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
2555
if (update_data->displaypath)
2556
strvec_pushf(args, "--super-prefix=%s/",
2557
update_data->displaypath);
2558
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
2559
if (update_data->quiet)
2560
strvec_push(args, "--quiet");
2561
if (update_data->force)
2562
strvec_push(args, "--force");
2563
if (update_data->init)
2564
strvec_push(args, "--init");
2565
if (update_data->remote)
2566
strvec_push(args, "--remote");
2567
if (update_data->nofetch)
2568
strvec_push(args, "--no-fetch");
2569
if (update_data->dissociate)
2570
strvec_push(args, "--dissociate");
2571
if (update_data->progress)
2572
strvec_push(args, "--progress");
2573
if (update_data->require_init)
2574
strvec_push(args, "--require-init");
2575
if (update_data->depth)
2576
strvec_pushf(args, "--depth=%d", update_data->depth);
2577
if (update_type != SM_UPDATE_UNSPECIFIED)
2578
strvec_pushf(args, "--%s",
2579
submodule_update_type_to_label(update_type));
2581
if (update_data->references.nr) {
2582
struct string_list_item *item;
2584
for_each_string_list_item(item, &update_data->references)
2585
strvec_pushl(args, "--reference", item->string, NULL);
2587
if (update_data->ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
2588
strvec_pushf(args, "--ref-format=%s",
2589
ref_storage_format_to_name(update_data->ref_storage_format));
2590
if (update_data->filter_options && update_data->filter_options->choice)
2591
strvec_pushf(args, "--filter=%s",
2592
expand_list_objects_filter_spec(
2593
update_data->filter_options));
2594
if (update_data->recommend_shallow == 0)
2595
strvec_push(args, "--no-recommend-shallow");
2596
else if (update_data->recommend_shallow == 1)
2597
strvec_push(args, "--recommend-shallow");
2598
if (update_data->single_branch >= 0)
2599
strvec_push(args, update_data->single_branch ?
2601
"--no-single-branch");
2604
static int update_submodule(struct update_data *update_data)
2608
if (validate_submodule_path(update_data->sm_path) < 0)
2611
ret = determine_submodule_update_strategy(the_repository,
2612
update_data->just_cloned,
2613
update_data->sm_path,
2614
update_data->update_default,
2615
&update_data->update_strategy);
2619
if (update_data->just_cloned)
2620
oidcpy(&update_data->suboid, null_oid());
2621
else if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
2622
"HEAD", &update_data->suboid))
2623
return die_message(_("Unable to find current revision in submodule path '%s'"),
2624
update_data->displaypath);
2626
if (update_data->remote) {
2632
code = get_default_remote_submodule(update_data->sm_path, &remote_name);
2635
code = remote_submodule_branch(update_data->sm_path, &branch);
2638
remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch);
2642
if (!update_data->nofetch) {
2643
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
2645
return die_message(_("Unable to fetch in submodule path '%s'"),
2646
update_data->sm_path);
2649
if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
2650
remote_ref, &update_data->oid))
2651
return die_message(_("Unable to find %s revision in submodule path '%s'"),
2652
remote_ref, update_data->sm_path);
2657
if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) {
2658
ret = run_update_procedure(update_data);
2663
if (update_data->recursive) {
2664
struct child_process cp = CHILD_PROCESS_INIT;
2665
struct update_data next = *update_data;
2668
oidcpy(&next.oid, null_oid());
2669
oidcpy(&next.suboid, null_oid());
2671
cp.dir = update_data->sm_path;
2673
prepare_submodule_repo_env(&cp.env);
2674
update_data_to_args(&next, &cp.args);
2676
ret = run_command(&cp);
2678
die_message(_("Failed to recurse into submodule path '%s'"),
2679
update_data->displaypath);
2686
static int update_submodules(struct update_data *update_data)
2689
struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
2690
const struct run_process_parallel_opts opts = {
2691
.tr2_category = "submodule",
2692
.tr2_label = "parallel/update",
2694
.processes = update_data->max_jobs,
2696
.get_next_task = update_clone_get_next_task,
2697
.start_failure = update_clone_start_failure,
2698
.task_finished = update_clone_task_finished,
2702
suc.update_data = update_data;
2703
run_processes_parallel(&opts);
2713
if (suc.quickstop) {
2718
for (i = 0; i < suc.update_clone_nr; i++) {
2719
struct update_clone_data ucd = suc.update_clone[i];
2722
oidcpy(&update_data->oid, &ucd.oid);
2723
update_data->just_cloned = ucd.just_cloned;
2724
update_data->sm_path = ucd.sub->path;
2732
if (validate_submodule_path(update_data->sm_path) < 0)
2735
code = ensure_core_worktree(update_data->sm_path);
2739
update_data->displaypath = get_submodule_displaypath(
2740
update_data->sm_path, update_data->prefix,
2741
update_data->super_prefix);
2742
code = update_submodule(update_data);
2743
FREE_AND_NULL(update_data->displaypath);
2753
submodule_update_clone_release(&suc);
2754
string_list_clear(&update_data->references, 0);
2758
static int module_update(int argc, const char **argv, const char *prefix)
2760
struct pathspec pathspec = { 0 };
2761
struct pathspec pathspec2 = { 0 };
2762
struct update_data opt = UPDATE_DATA_INIT;
2763
struct list_objects_filter_options filter_options =
2764
LIST_OBJECTS_FILTER_INIT;
2765
const char *ref_storage_format = NULL;
2767
struct option module_update_options[] = {
2768
OPT__SUPER_PREFIX(&opt.super_prefix),
2769
OPT__FORCE(&opt.force, N_("force checkout updates"), 0),
2770
OPT_BOOL(0, "init", &opt.init,
2771
N_("initialize uninitialized submodules before update")),
2772
OPT_BOOL(0, "remote", &opt.remote,
2773
N_("use SHA-1 of submodule's remote tracking branch")),
2774
OPT_BOOL(0, "recursive", &opt.recursive,
2775
N_("traverse submodules recursively")),
2776
OPT_BOOL('N', "no-fetch", &opt.nofetch,
2777
N_("don't fetch new objects from the remote site")),
2778
OPT_SET_INT(0, "checkout", &opt.update_default,
2779
N_("use the 'checkout' update strategy (default)"),
2780
SM_UPDATE_CHECKOUT),
2781
OPT_SET_INT('m', "merge", &opt.update_default,
2782
N_("use the 'merge' update strategy"),
2784
OPT_SET_INT('r', "rebase", &opt.update_default,
2785
N_("use the 'rebase' update strategy"),
2787
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
2788
N_("reference repository")),
2789
OPT_STRING(0, "ref-format", &ref_storage_format, N_("format"),
2790
N_("specify the reference format to use")),
2791
OPT_BOOL(0, "dissociate", &opt.dissociate,
2792
N_("use --reference only while cloning")),
2793
OPT_INTEGER(0, "depth", &opt.depth,
2794
N_("create a shallow clone truncated to the "
2795
"specified number of revisions")),
2796
OPT_INTEGER('j', "jobs", &opt.max_jobs,
2797
N_("parallel jobs")),
2798
OPT_BOOL(0, "recommend-shallow", &opt.recommend_shallow,
2799
N_("whether the initial clone should follow the shallow recommendation")),
2800
OPT__QUIET(&opt.quiet, N_("don't print cloning progress")),
2801
OPT_BOOL(0, "progress", &opt.progress,
2802
N_("force cloning progress")),
2803
OPT_BOOL(0, "require-init", &opt.require_init,
2804
N_("disallow cloning into non-empty directory, implies --init")),
2805
OPT_BOOL(0, "single-branch", &opt.single_branch,
2806
N_("clone only one branch, HEAD or --branch")),
2807
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
2810
const char *const git_submodule_helper_usage[] = {
2811
N_("git submodule [--quiet] update"
2812
" [--init [--filter=<filter-spec>]] [--remote]"
2813
" [-N|--no-fetch] [-f|--force]"
2814
" [--checkout|--merge|--rebase]"
2815
" [--[no-]recommend-shallow] [--reference <repository>]"
2816
" [--recursive] [--[no-]single-branch] [--] [<path>...]"),
2820
update_clone_config_from_gitmodules(&opt.max_jobs);
2821
git_config(git_update_clone_config, &opt.max_jobs);
2823
argc = parse_options(argc, argv, prefix, module_update_options,
2824
git_submodule_helper_usage, 0);
2826
if (opt.require_init)
2829
if (filter_options.choice && !opt.init) {
2830
usage_with_options(git_submodule_helper_usage,
2831
module_update_options);
2834
if (ref_storage_format) {
2835
opt.ref_storage_format = ref_storage_format_by_name(ref_storage_format);
2836
if (opt.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
2837
die(_("unknown ref storage format '%s'"), ref_storage_format);
2840
opt.filter_options = &filter_options;
2841
opt.prefix = prefix;
2843
if (opt.update_default)
2844
opt.update_strategy.type = opt.update_default;
2846
if (module_list_compute(argv, prefix, &pathspec, &opt.list) < 0) {
2852
opt.warn_if_uninitialized = 1;
2855
struct module_list list = MODULE_LIST_INIT;
2856
struct init_cb info = INIT_CB_INIT;
2858
if (module_list_compute(argv, opt.prefix,
2859
&pathspec2, &list) < 0) {
2860
module_list_release(&list);
2869
if (!argc && !git_config_get("submodule.active"))
2870
module_list_active(&list);
2872
info.prefix = opt.prefix;
2873
info.super_prefix = opt.super_prefix;
2875
info.flags |= OPT_QUIET;
2877
for_each_listed_submodule(&list, init_submodule_cb, &info);
2878
module_list_release(&list);
2881
ret = update_submodules(&opt);
2883
update_data_release(&opt);
2884
list_objects_filter_release(&filter_options);
2885
clear_pathspec(&pathspec);
2886
clear_pathspec(&pathspec2);
2890
static int push_check(int argc, const char **argv, const char *prefix UNUSED)
2892
struct remote *remote;
2893
const char *superproject_head;
2895
int detached_head = 0;
2896
struct object_id head_oid;
2899
die("submodule--helper push-check requires at least 2 arguments");
2906
superproject_head = argv[1];
2910
head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
2911
0, &head_oid, NULL);
2913
die(_("Failed to resolve HEAD as a valid ref."));
2914
if (!strcmp(head, "HEAD"))
2921
remote = pushremote_get(argv[1]);
2922
if (!remote || remote->origin == REMOTE_UNCONFIGURED)
2923
die("remote '%s' not configured", argv[1]);
2928
struct ref *local_refs = get_local_heads();
2929
struct refspec refspec = REFSPEC_INIT_PUSH;
2931
refspec_appendn(&refspec, argv + 2, argc - 2);
2933
for (i = 0; i < refspec.nr; i++) {
2934
const struct refspec_item *rs = &refspec.items[i];
2936
if (rs->pattern || rs->matching)
2940
switch (count_refspec_match(rs->src, local_refs, NULL)) {
2949
if (!strcmp(rs->src, "HEAD")) {
2950
if (!detached_head &&
2951
!strcmp(head, superproject_head))
2953
die("HEAD does not match the named branch in the superproject");
2957
die("src refspec '%s' must name a ref",
2961
refspec_clear(&refspec);
2968
static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2971
struct pathspec pathspec = { 0 };
2972
struct module_list list = MODULE_LIST_INIT;
2973
const char *super_prefix = NULL;
2974
struct option embed_gitdir_options[] = {
2975
OPT__SUPER_PREFIX(&super_prefix),
2978
const char *const git_submodule_helper_usage[] = {
2979
N_("git submodule absorbgitdirs [<options>] [<path>...]"),
2984
argc = parse_options(argc, argv, prefix, embed_gitdir_options,
2985
git_submodule_helper_usage, 0);
2987
if (module_list_compute(argv, prefix, &pathspec, &list) < 0)
2990
for (i = 0; i < list.nr; i++)
2991
absorb_git_dir_into_superproject(list.entries[i]->name,
2996
clear_pathspec(&pathspec);
2997
module_list_release(&list);
3001
static int module_set_url(int argc, const char **argv, const char *prefix)
3007
struct option options[] = {
3008
OPT__QUIET(&quiet, N_("suppress output for setting url of a submodule")),
3011
const char *const usage[] = {
3012
N_("git submodule set-url [--quiet] <path> <newurl>"),
3015
const struct submodule *sub;
3017
argc = parse_options(argc, argv, prefix, options, usage, 0);
3019
if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1]))
3020
usage_with_options(usage, options);
3022
sub = submodule_from_path(the_repository, null_oid(), path);
3025
die(_("no submodule mapping found in .gitmodules for path '%s'"),
3028
config_name = xstrfmt("submodule.%s.url", sub->name);
3029
ret = config_set_in_gitmodules_file_gently(config_name, newurl);
3032
repo_read_gitmodules(the_repository, 0);
3033
sync_submodule(sub->path, prefix, NULL, quiet ? OPT_QUIET : 0);
3040
static int module_set_branch(int argc, const char **argv, const char *prefix)
3042
int opt_default = 0, ret;
3043
const char *opt_branch = NULL;
3046
struct option options[] = {
3051
OPT_NOOP_NOARG('q', "quiet"),
3053
OPT_BOOL('d', "default", &opt_default,
3054
N_("set the default tracking branch to master")),
3055
OPT_STRING('b', "branch", &opt_branch, N_("branch"),
3056
N_("set the default tracking branch")),
3059
const char *const usage[] = {
3060
N_("git submodule set-branch [-q|--quiet] (-d|--default) <path>"),
3061
N_("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>"),
3064
const struct submodule *sub;
3066
argc = parse_options(argc, argv, prefix, options, usage, 0);
3068
if (!opt_branch && !opt_default)
3069
die(_("--branch or --default required"));
3071
if (opt_branch && opt_default)
3072
die(_("options '%s' and '%s' cannot be used together"), "--branch", "--default");
3074
if (argc != 1 || !(path = argv[0]))
3075
usage_with_options(usage, options);
3077
sub = submodule_from_path(the_repository, null_oid(), path);
3080
die(_("no submodule mapping found in .gitmodules for path '%s'"),
3083
config_name = xstrfmt("submodule.%s.branch", sub->name);
3084
ret = config_set_in_gitmodules_file_gently(config_name, opt_branch);
3090
static int module_create_branch(int argc, const char **argv, const char *prefix)
3092
enum branch_track track;
3093
int quiet = 0, force = 0, reflog = 0, dry_run = 0;
3094
struct option options[] = {
3095
OPT__QUIET(&quiet, N_("print only error messages")),
3096
OPT__FORCE(&force, N_("force creation"), 0),
3097
OPT_BOOL(0, "create-reflog", &reflog,
3098
N_("create the branch's reflog")),
3099
OPT_CALLBACK_F('t', "track", &track, "(direct|inherit)",
3100
N_("set branch tracking configuration"),
3102
parse_opt_tracking_mode),
3103
OPT__DRY_RUN(&dry_run,
3104
N_("show whether the branch would be created")),
3107
const char *const usage[] = {
3108
N_("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>"),
3112
git_config(git_default_config, NULL);
3113
track = git_branch_track;
3114
argc = parse_options(argc, argv, prefix, options, usage, 0);
3117
usage_with_options(usage, options);
3119
if (!quiet && !dry_run)
3120
printf_ln(_("creating branch '%s'"), argv[0]);
3122
create_branches_recursively(the_repository, argv[0], argv[1], argv[2],
3123
force, reflog, quiet, track, dry_run);
3130
const char *reference_path;
3132
const char *sm_name;
3134
const char *realrepo;
3135
enum ref_storage_format ref_storage_format;
3137
unsigned int force: 1;
3138
unsigned int quiet: 1;
3139
unsigned int progress: 1;
3140
unsigned int dissociate: 1;
3142
#define ADD_DATA_INIT { \
3144
.ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN, \
3147
static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
3149
struct child_process cp_remote = CHILD_PROCESS_INIT;
3150
struct strbuf sb_remote_out = STRBUF_INIT;
3152
cp_remote.git_cmd = 1;
3153
strvec_pushf(&cp_remote.env,
3154
"GIT_DIR=%s", git_dir_path);
3155
strvec_push(&cp_remote.env, "GIT_WORK_TREE=.");
3156
strvec_pushl(&cp_remote.args, "remote", "-v", NULL);
3157
if (!capture_command(&cp_remote, &sb_remote_out, 0)) {
3159
char *line = sb_remote_out.buf;
3161
while ((next_line = strchr(line, '\n')) != NULL) {
3162
size_t len = next_line - line;
3164
if (strip_suffix_mem(line, &len, " (fetch)"))
3165
strbuf_addf(msg, " %.*s\n", (int)len, line);
3166
line = next_line + 1;
3170
strbuf_release(&sb_remote_out);
3173
static int add_submodule(const struct add_data *add_data)
3175
char *submod_gitdir_path;
3176
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
3177
struct string_list reference = STRING_LIST_INIT_NODUP;
3181
if (is_directory(add_data->sm_path)) {
3182
struct strbuf sm_path = STRBUF_INIT;
3183
strbuf_addstr(&sm_path, add_data->sm_path);
3184
submod_gitdir_path = xstrfmt("%s/.git", add_data->sm_path);
3185
if (is_nonbare_repository_dir(&sm_path))
3186
printf(_("Adding existing repo at '%s' to the index\n"),
3189
die(_("'%s' already exists and is not a valid git repo"),
3191
strbuf_release(&sm_path);
3192
free(submod_gitdir_path);
3194
struct child_process cp = CHILD_PROCESS_INIT;
3196
submod_gitdir_path = xstrfmt(".git/modules/%s", add_data->sm_name);
3198
if (is_directory(submod_gitdir_path)) {
3199
if (!add_data->force) {
3200
struct strbuf msg = STRBUF_INIT;
3203
strbuf_addf(&msg, _("A git directory for '%s' is found "
3204
"locally with remote(s):\n"),
3207
append_fetch_remotes(&msg, submod_gitdir_path);
3208
free(submod_gitdir_path);
3210
strbuf_addf(&msg, _("If you want to reuse this local git "
3211
"directory instead of cloning again from\n"
3213
"use the '--force' option. If the local git "
3214
"directory is not the correct repo\n"
3215
"or you are unsure what this means choose "
3216
"another name with the '--name' option."),
3217
add_data->realrepo);
3219
die_msg = strbuf_detach(&msg, NULL);
3222
printf(_("Reactivating local git directory for "
3223
"submodule '%s'\n"), add_data->sm_name);
3226
free(submod_gitdir_path);
3228
clone_data.prefix = add_data->prefix;
3229
clone_data.path = add_data->sm_path;
3230
clone_data.name = add_data->sm_name;
3231
clone_data.url = add_data->realrepo;
3232
clone_data.quiet = add_data->quiet;
3233
clone_data.progress = add_data->progress;
3234
if (add_data->reference_path) {
3235
char *p = xstrdup(add_data->reference_path);
3237
string_list_append(&reference, p)->util = p;
3239
clone_data.ref_storage_format = add_data->ref_storage_format;
3240
clone_data.dissociate = add_data->dissociate;
3241
if (add_data->depth >= 0)
3242
clone_data.depth = add_data->depth;
3244
if (clone_submodule(&clone_data, &reference))
3247
prepare_submodule_repo_env(&cp.env);
3249
cp.dir = add_data->sm_path;
3254
strvec_pushl(&cp.args, "checkout", "-f", "-q", NULL);
3256
if (add_data->branch) {
3257
strvec_pushl(&cp.args, "-B", add_data->branch, NULL);
3258
strvec_pushf(&cp.args, "origin/%s", add_data->branch);
3261
if (run_command(&cp))
3262
die(_("unable to checkout submodule '%s'"), add_data->sm_path);
3267
string_list_clear(&reference, 1);
3271
static int config_submodule_in_gitmodules(const char *name, const char *var, const char *value)
3276
if (!is_writing_gitmodules_ok())
3277
die(_("please make sure that the .gitmodules file is in the working tree"));
3279
key = xstrfmt("submodule.%s.%s", name, var);
3280
ret = config_set_in_gitmodules_file_gently(key, value);
3286
static void configure_added_submodule(struct add_data *add_data)
3289
struct child_process add_submod = CHILD_PROCESS_INIT;
3290
struct child_process add_gitmodules = CHILD_PROCESS_INIT;
3292
key = xstrfmt("submodule.%s.url", add_data->sm_name);
3293
git_config_set_gently(key, add_data->realrepo);
3296
add_submod.git_cmd = 1;
3297
strvec_pushl(&add_submod.args, "add",
3298
"--no-warn-embedded-repo", NULL);
3299
if (add_data->force)
3300
strvec_push(&add_submod.args, "--force");
3301
strvec_pushl(&add_submod.args, "--", add_data->sm_path, NULL);
3303
if (run_command(&add_submod))
3304
die(_("Failed to add submodule '%s'"), add_data->sm_path);
3306
if (config_submodule_in_gitmodules(add_data->sm_name, "path", add_data->sm_path) ||
3307
config_submodule_in_gitmodules(add_data->sm_name, "url", add_data->repo))
3308
die(_("Failed to register submodule '%s'"), add_data->sm_path);
3310
if (add_data->branch) {
3311
if (config_submodule_in_gitmodules(add_data->sm_name,
3312
"branch", add_data->branch))
3313
die(_("Failed to register submodule '%s'"), add_data->sm_path);
3316
add_gitmodules.git_cmd = 1;
3317
strvec_pushl(&add_gitmodules.args,
3318
"add", "--force", "--", ".gitmodules", NULL);
3320
if (run_command(&add_gitmodules))
3321
die(_("Failed to register submodule '%s'"), add_data->sm_path);
3333
if (!git_config_get("submodule.active")) {
3338
if (!is_submodule_active(the_repository, add_data->sm_path)) {
3339
key = xstrfmt("submodule.%s.active", add_data->sm_name);
3340
git_config_set_gently(key, "true");
3344
key = xstrfmt("submodule.%s.active", add_data->sm_name);
3345
git_config_set_gently(key, "true");
3350
static void die_on_index_match(const char *path, int force)
3353
const char *args[] = { path, NULL };
3354
parse_pathspec(&ps, 0, PATHSPEC_PREFER_CWD, NULL, args);
3356
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
3357
die(_("index file corrupt"));
3361
char *ps_matched = xcalloc(ps.nr, 1);
3364
ensure_full_index(the_repository->index);
3370
for (i = 0; i < the_repository->index->cache_nr; i++) {
3371
ce_path_match(the_repository->index, the_repository->index->cache[i], &ps,
3374
if (ps_matched[0]) {
3376
die(_("'%s' already exists in the index"),
3378
if (!S_ISGITLINK(the_repository->index->cache[i]->ce_mode))
3379
die(_("'%s' already exists in the index "
3380
"and is not a submodule"), path);
3386
clear_pathspec(&ps);
3389
static void die_on_repo_without_commits(const char *path)
3391
struct strbuf sb = STRBUF_INIT;
3392
strbuf_addstr(&sb, path);
3393
if (is_nonbare_repository_dir(&sb)) {
3394
struct object_id oid;
3395
if (repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid) < 0)
3396
die(_("'%s' does not have a commit checked out"), path);
3398
strbuf_release(&sb);
3401
static int module_add(int argc, const char **argv, const char *prefix)
3403
int force = 0, quiet = 0, progress = 0, dissociate = 0;
3404
struct add_data add_data = ADD_DATA_INIT;
3405
const char *ref_storage_format = NULL;
3406
char *to_free = NULL;
3407
struct option options[] = {
3408
OPT_STRING('b', "branch", &add_data.branch, N_("branch"),
3409
N_("branch of repository to add as submodule")),
3410
OPT__FORCE(&force, N_("allow adding an otherwise ignored submodule path"),
3411
PARSE_OPT_NOCOMPLETE),
3412
OPT__QUIET(&quiet, N_("print only error messages")),
3413
OPT_BOOL(0, "progress", &progress, N_("force cloning progress")),
3414
OPT_STRING(0, "reference", &add_data.reference_path, N_("repository"),
3415
N_("reference repository")),
3416
OPT_STRING(0, "ref-format", &ref_storage_format, N_("format"),
3417
N_("specify the reference format to use")),
3418
OPT_BOOL(0, "dissociate", &dissociate, N_("borrow the objects from reference repositories")),
3419
OPT_STRING(0, "name", &add_data.sm_name, N_("name"),
3420
N_("sets the submodule's name to the given string "
3421
"instead of defaulting to its path")),
3422
OPT_INTEGER(0, "depth", &add_data.depth, N_("depth for shallow clones")),
3425
const char *const usage[] = {
3426
N_("git submodule add [<options>] [--] <repository> [<path>]"),
3429
struct strbuf sb = STRBUF_INIT;
3432
argc = parse_options(argc, argv, prefix, options, usage, 0);
3434
if (!is_writing_gitmodules_ok())
3435
die(_("please make sure that the .gitmodules file is in the working tree"));
3437
if (prefix && *prefix &&
3438
add_data.reference_path && !is_absolute_path(add_data.reference_path))
3439
add_data.reference_path = xstrfmt("%s%s", prefix, add_data.reference_path);
3441
if (argc == 0 || argc > 2)
3442
usage_with_options(usage, options);
3444
if (ref_storage_format) {
3445
add_data.ref_storage_format = ref_storage_format_by_name(ref_storage_format);
3446
if (add_data.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
3447
die(_("unknown ref storage format '%s'"), ref_storage_format);
3450
add_data.repo = argv[0];
3452
add_data.sm_path = git_url_basename(add_data.repo, 0, 0);
3454
add_data.sm_path = xstrdup(argv[1]);
3456
if (prefix && *prefix && !is_absolute_path(add_data.sm_path)) {
3457
char *sm_path = add_data.sm_path;
3459
add_data.sm_path = xstrfmt("%s%s", prefix, sm_path);
3463
if (starts_with_dot_dot_slash(add_data.repo) ||
3464
starts_with_dot_slash(add_data.repo)) {
3466
die(_("Relative path can only be used from the toplevel "
3467
"of the working tree"));
3470
to_free = resolve_relative_url(add_data.repo, NULL, 1);
3471
add_data.realrepo = to_free;
3472
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
3473
add_data.realrepo = add_data.repo;
3475
die(_("repo URL: '%s' must be absolute or begin with ./|../"),
3483
normalize_path_copy(add_data.sm_path, add_data.sm_path);
3484
strip_dir_trailing_slashes(add_data.sm_path);
3486
if (validate_submodule_path(add_data.sm_path) < 0)
3489
die_on_index_match(add_data.sm_path, force);
3490
die_on_repo_without_commits(add_data.sm_path);
3493
struct child_process cp = CHILD_PROCESS_INIT;
3497
strvec_pushl(&cp.args, "add", "--dry-run", "--ignore-missing",
3498
"--no-warn-embedded-repo", add_data.sm_path, NULL);
3499
if ((ret = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) {
3500
strbuf_complete_line(&sb);
3501
fputs(sb.buf, stderr);
3506
if(!add_data.sm_name)
3507
add_data.sm_name = add_data.sm_path;
3509
if (check_submodule_name(add_data.sm_name))
3510
die(_("'%s' is not a valid submodule name"), add_data.sm_name);
3512
add_data.prefix = prefix;
3513
add_data.force = !!force;
3514
add_data.quiet = !!quiet;
3515
add_data.progress = !!progress;
3516
add_data.dissociate = !!dissociate;
3518
if (add_submodule(&add_data))
3520
configure_added_submodule(&add_data);
3524
free(add_data.sm_path);
3526
strbuf_release(&sb);
3531
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
3533
parse_opt_subcommand_fn *fn = NULL;
3534
const char *const usage[] = {
3535
N_("git submodule--helper <command>"),
3538
struct option options[] = {
3539
OPT_SUBCOMMAND("clone", &fn, module_clone),
3540
OPT_SUBCOMMAND("add", &fn, module_add),
3541
OPT_SUBCOMMAND("update", &fn, module_update),
3542
OPT_SUBCOMMAND("foreach", &fn, module_foreach),
3543
OPT_SUBCOMMAND("init", &fn, module_init),
3544
OPT_SUBCOMMAND("status", &fn, module_status),
3545
OPT_SUBCOMMAND("sync", &fn, module_sync),
3546
OPT_SUBCOMMAND("deinit", &fn, module_deinit),
3547
OPT_SUBCOMMAND("summary", &fn, module_summary),
3548
OPT_SUBCOMMAND("push-check", &fn, push_check),
3549
OPT_SUBCOMMAND("absorbgitdirs", &fn, absorb_git_dirs),
3550
OPT_SUBCOMMAND("set-url", &fn, module_set_url),
3551
OPT_SUBCOMMAND("set-branch", &fn, module_set_branch),
3552
OPT_SUBCOMMAND("create-branch", &fn, module_create_branch),
3555
argc = parse_options(argc, argv, prefix, options, usage, 0);
3557
return fn(argc, argv, prefix);