summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJens Lehmann <Jens.Lehmann@web.de>2010-11-12 12:54:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-11-12 23:06:03 (GMT)
commit7dce19d374a37932e9d4c3a6202af407cf5114eb (patch)
tree4e26a11bba6c571c41fef1e625f61edfa62cbb12 /builtin
parent515cc0101943b766fde7aa894827119e332ec033 (diff)
downloadgit-7dce19d374a37932e9d4c3a6202af407cf5114eb.zip
git-7dce19d374a37932e9d4c3a6202af407cf5114eb.tar.gz
git-7dce19d374a37932e9d4c3a6202af407cf5114eb.tar.bz2
fetch/pull: Add the --recurse-submodules option
Until now you had to call "git submodule update" (without -N|--no-fetch option) or something like "git submodule foreach git fetch" to fetch new commits in populated submodules from their remote. This could lead to "(commits not present)" messages in the output of "git diff --submodule" (which is used by "git gui" and "gitk") after fetching or pulling new commits in the superproject and is an obstacle for implementing recursive checkout of submodules. Also "git submodule update" cannot fetch changes when disconnected, so it was very easy to forget to fetch the submodule changes before disconnecting only to discover later that they are needed. This patch adds the "--recurse-submodules" option to recursively fetch each populated submodule from the url configured in the .git/config of the submodule at the end of each "git fetch" or during "git pull" in the superproject. The submodule paths are taken from the index. The hidden option "--submodule-prefix" is added to "git fetch" to be able to print out the full paths of nested submodules. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/fetch.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c
index ea14d5d..cbbde2d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -12,6 +12,7 @@
#include "parse-options.h"
#include "sigchain.h"
#include "transport.h"
+#include "submodule.h"
static const char * const builtin_fetch_usage[] = {
"git fetch [<options>] [<repository> [<refspec>...]]",
@@ -28,12 +29,13 @@ enum {
};
static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;
-static int progress;
+static int progress, recurse_submodules;
static int tags = TAGS_DEFAULT;
static const char *depth;
static const char *upload_pack;
static struct strbuf default_rla = STRBUF_INIT;
static struct transport *transport;
+static const char *submodule_prefix = "";
static struct option builtin_fetch_options[] = {
OPT__VERBOSITY(&verbosity),
@@ -53,6 +55,8 @@ static struct option builtin_fetch_options[] = {
"do not fetch all tags (--no-tags)", TAGS_UNSET),
OPT_BOOLEAN('p', "prune", &prune,
"prune tracking branches no longer on remote"),
+ OPT_BOOLEAN(0, "recurse-submodules", &recurse_submodules,
+ "control recursive fetching of submodules"),
OPT_BOOLEAN(0, "dry-run", &dry_run,
"dry run"),
OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
@@ -61,6 +65,8 @@ static struct option builtin_fetch_options[] = {
OPT_BOOLEAN(0, "progress", &progress, "force progress reporting"),
OPT_STRING(0, "depth", &depth, "DEPTH",
"deepen history of shallow clone"),
+ { OPTION_STRING, 0, "submodule-prefix", &submodule_prefix, "DIR",
+ "prepend this to submodule path output", PARSE_OPT_HIDDEN },
OPT_END()
};
@@ -777,28 +783,36 @@ static int add_remote_or_group(const char *name, struct string_list *list)
return 1;
}
-static int fetch_multiple(struct string_list *list)
+static void add_options_to_argv(int *argc, const char **argv)
{
- int i, result = 0;
- const char *argv[11] = { "fetch", "--append" };
- int argc = 2;
-
if (dry_run)
- argv[argc++] = "--dry-run";
+ argv[(*argc)++] = "--dry-run";
if (prune)
- argv[argc++] = "--prune";
+ argv[(*argc)++] = "--prune";
if (update_head_ok)
- argv[argc++] = "--update-head-ok";
+ argv[(*argc)++] = "--update-head-ok";
if (force)
- argv[argc++] = "--force";
+ argv[(*argc)++] = "--force";
if (keep)
- argv[argc++] = "--keep";
+ argv[(*argc)++] = "--keep";
+ if (recurse_submodules)
+ argv[(*argc)++] = "--recurse-submodules";
if (verbosity >= 2)
- argv[argc++] = "-v";
+ argv[(*argc)++] = "-v";
if (verbosity >= 1)
- argv[argc++] = "-v";
+ argv[(*argc)++] = "-v";
else if (verbosity < 0)
- argv[argc++] = "-q";
+ argv[(*argc)++] = "-q";
+
+}
+
+static int fetch_multiple(struct string_list *list)
+{
+ int i, result = 0;
+ const char *argv[12] = { "fetch", "--append" };
+ int argc = 2;
+
+ add_options_to_argv(&argc, argv);
if (!append && !dry_run) {
int errcode = truncate_fetch_head();
@@ -919,6 +933,17 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
}
}
+ if (!result && recurse_submodules) {
+ const char *options[10];
+ int num_options = 0;
+ gitmodules_config();
+ git_config(submodule_config, NULL);
+ add_options_to_argv(&num_options, options);
+ result = fetch_populated_submodules(num_options, options,
+ submodule_prefix,
+ verbosity < 0);
+ }
+
/* All names were strdup()ed or strndup()ed */
list.strdup_strings = 1;
string_list_clear(&list, 0);