From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Jens.Lehmann@web.de, jrnieder@gmail.com,
Stefan Beller <sbeller@google.com>
Subject: [PATCH 3/4] submodule update: Initialize all group-selected submodules by default
Date: Tue, 19 Jan 2016 19:34:39 -0800 [thread overview]
Message-ID: <1453260880-628-4-git-send-email-sbeller@google.com> (raw)
In-Reply-To: <1453260880-628-1-git-send-email-sbeller@google.com>
All submodules which are selected via submodule groups
("submodule.groups") are initialized if they were not initialized
before updating the submodules.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
builtin/submodule--helper.c | 30 +++++++++++++++++++++++++++++-
t/t7400-submodule-basic.sh | 26 ++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 4684f16..def382e 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -577,6 +577,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
struct submodule_update_clone {
/* states */
+ struct string_list *submodule_groups;
int count;
int print_unmatched;
/* configuration */
@@ -590,7 +591,7 @@ struct submodule_update_clone {
struct string_list projectlines;
struct pathspec pathspec;
};
-#define SUBMODULE_UPDATE_CLONE_INIT {0, 0, 0, NULL, NULL, NULL, NULL, NULL, MODULE_LIST_INIT, STRING_LIST_INIT_DUP}
+#define SUBMODULE_UPDATE_CLONE_INIT {NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, MODULE_LIST_INIT, STRING_LIST_INIT_DUP}
static void fill_clone_command(struct child_process *cp, int quiet,
const char *prefix, const char *path,
@@ -633,6 +634,7 @@ static int update_clone_get_next_task(struct child_process *cp,
const char *update_module = NULL;
char *url = NULL;
int needs_cloning = 0;
+ int in_submodule_groups = 0;
if (ce_stage(ce)) {
if (pp->recursive_prefix)
@@ -676,6 +678,22 @@ static int update_clone_get_next_task(struct child_process *cp,
strbuf_reset(&sb);
strbuf_addf(&sb, "submodule.%s.url", sub->name);
git_config_get_string(sb.buf, &url);
+ if (pp->submodule_groups && sub->groups){
+ struct string_list_item *item;
+ for_each_string_list_item(item, sub->groups) {
+ if (string_list_has_string(
+ pp->submodule_groups, item->string)) {
+ in_submodule_groups = 1;
+ break;
+ }
+ }
+ if (in_submodule_groups) {
+ if (!url) {
+ init_submodule(sub->name, pp->prefix, pp->quiet);
+ url = xstrdup(sub->url);
+ }
+ }
+ }
if (!url) {
/*
* Only mention uninitialized submodules when its
@@ -687,6 +705,7 @@ static int update_clone_get_next_task(struct child_process *cp,
continue;
}
+
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/.git", ce->name);
needs_cloning = !file_exists(sb.buf);
@@ -742,6 +761,7 @@ static int update_clone_task_finished(int result,
static int update_clone(int argc, const char **argv, const char *prefix)
{
int max_jobs = -1;
+ const struct string_list *list;
struct string_list_item *item;
struct submodule_update_clone pp = SUBMODULE_UPDATE_CLONE_INIT;
@@ -786,6 +806,14 @@ static int update_clone(int argc, const char **argv, const char *prefix)
/* Overlay the parsed .gitmodules file with .git/config */
git_config(git_submodule_config, NULL);
+ list = git_config_get_value_multi("submodule.groups");
+ if (list) {
+ pp.submodule_groups = xmalloc(sizeof(*pp.submodule_groups));
+ string_list_init(pp.submodule_groups, 1);
+ for_each_string_list_item(item, list)
+ string_list_insert(pp.submodule_groups, item->string);
+ }
+
if (max_jobs < 0)
max_jobs = config_parallel_submodules();
if (max_jobs < 0)
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index b468278..e6a008c 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1032,4 +1032,30 @@ test_expect_success 'submodule add records groups' '
test_cmp expected actual
'
+cat <<EOF > expected
+submodule
+-submodule1
+EOF
+
+test_expect_success 'submodule update works with groups implied' '
+ test_when_finished "rm -rf super super_clone" &&
+ mkdir super &&
+ pwd=$(pwd) &&
+ (
+ cd super &&
+ git init &&
+ git submodule add --group groupA file://"$pwd"/example2 submodule &&
+ git submodule add file://"$pwd"/example2 submodule1 &&
+ git commit -a -m "create repository with 2 submodules, one is in a group"
+ ) &&
+ git clone super super_clone &&
+ (
+ cd super_clone &&
+ git config submodule.groups groupA &&
+ git submodule update &&
+ git submodule status |cut -c1,42-52 | tr -d " " >../actual
+ ) &&
+ test_cmp actual expected
+'
+
test_done
--
2.7.0.rc0.41.g89994f2.dirty
next prev parent reply other threads:[~2016-01-20 3:35 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-20 3:34 [PATCH 0/4] Submodule Groups Stefan Beller
2016-01-20 3:34 ` [PATCH 1/4] git submodule: Teach add to accept --group Stefan Beller
2016-01-20 21:18 ` Junio C Hamano
2016-01-20 23:57 ` Stefan Beller
2016-01-21 0:08 ` Junio C Hamano
2016-01-21 0:16 ` Stefan Beller
2016-01-21 4:45 ` Junio C Hamano
2016-01-20 3:34 ` [PATCH 2/4] submodule-config: keep groups around Stefan Beller
2016-01-20 21:23 ` Junio C Hamano
2016-01-21 0:20 ` Stefan Beller
2016-01-21 2:37 ` Junio C Hamano
2016-01-20 3:34 ` Stefan Beller [this message]
2016-01-20 21:30 ` [PATCH 3/4] submodule update: Initialize all group-selected submodules by default Junio C Hamano
2016-01-21 1:44 ` Stefan Beller
2016-01-21 4:40 ` Junio C Hamano
2016-01-21 19:39 ` Stefan Beller
2016-01-21 20:47 ` Junio C Hamano
2016-01-21 20:57 ` Junio C Hamano
2016-01-20 3:34 ` [PATCH 4/4] builtin/clone: support submodule groups Stefan Beller
2016-01-20 21:43 ` Junio C Hamano
2016-01-21 21:17 ` [PATCH 0/4] Submodule Groups Sebastian Schuberth
2016-01-21 21:56 ` Stefan Beller
2016-01-21 22:18 ` Junio C Hamano
2016-01-21 22:25 ` Junio C Hamano
2016-01-21 22:30 ` Stefan Beller
2016-01-21 22:37 ` Junio C Hamano
2016-01-22 8:55 ` Sebastian Schuberth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1453260880-628-4-git-send-email-sbeller@google.com \
--to=sbeller@google.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).