push: propagate push-options with --recurse-submodules
authorBrandon Williams <bmwill@google.com>
Wed, 5 Apr 2017 17:47:16 +0000 (10:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Apr 2017 07:45:03 +0000 (00:45 -0700)
Teach push --recurse-submodules to propagate push-options recursively to
the pushes performed in the submodules.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
submodule.h
t/t5545-push-options.sh
transport.c
index c52d6634c528d79ddedf069b7e09e955d283ed64..de444be61ac3a28be6c1e021de7b6a80fea37fd4 100644 (file)
@@ -782,7 +782,9 @@ int find_unpushed_submodules(struct sha1_array *commits,
        return needs_pushing->nr;
 }
 
-static int push_submodule(const char *path, int dry_run)
+static int push_submodule(const char *path,
+                         const struct string_list *push_options,
+                         int dry_run)
 {
        if (add_submodule_odb(path))
                return 1;
@@ -793,6 +795,12 @@ static int push_submodule(const char *path, int dry_run)
                if (dry_run)
                        argv_array_push(&cp.args, "--dry-run");
 
+               if (push_options && push_options->nr) {
+                       const struct string_list_item *item;
+                       for_each_string_list_item(item, push_options)
+                               argv_array_pushf(&cp.args, "--push-option=%s",
+                                                item->string);
+               }
                prepare_submodule_repo_env(&cp.env_array);
                cp.git_cmd = 1;
                cp.no_stdin = 1;
@@ -807,6 +815,7 @@ static int push_submodule(const char *path, int dry_run)
 
 int push_unpushed_submodules(struct sha1_array *commits,
                             const char *remotes_name,
+                            const struct string_list *push_options,
                             int dry_run)
 {
        int i, ret = 1;
@@ -818,7 +827,7 @@ int push_unpushed_submodules(struct sha1_array *commits,
        for (i = 0; i < needs_pushing.nr; i++) {
                const char *path = needs_pushing.items[i].string;
                fprintf(stderr, "Pushing submodule '%s'\n", path);
-               if (!push_submodule(path, dry_run)) {
+               if (!push_submodule(path, push_options, dry_run)) {
                        fprintf(stderr, "Unable to push submodule '%s'\n", path);
                        ret = 0;
                }
index 8a8bc49dc9626b9ba4112f3b0bf25b212d864d1d..0e26430fd372ce35a13b1dda70d3333a23bd2675 100644 (file)
@@ -92,6 +92,7 @@ extern int find_unpushed_submodules(struct sha1_array *commits,
                                    struct string_list *needs_pushing);
 extern int push_unpushed_submodules(struct sha1_array *commits,
                                    const char *remotes_name,
+                                   const struct string_list *push_options,
                                    int dry_run);
 extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
 extern int parallel_submodules(void);
index 97065e62b870c732e7c197dfda054775546289cd..f9232f5d0ffff996359a27d5727f645f8fcff6d3 100755 (executable)
@@ -142,6 +142,46 @@ test_expect_success 'push options work properly across http' '
        test_cmp expect actual
 '
 
+test_expect_success 'push options and submodules' '
+       test_when_finished "rm -rf parent" &&
+       test_when_finished "rm -rf parent_upstream" &&
+       mk_repo_pair &&
+       git -C upstream config receive.advertisePushOptions true &&
+       cp -r upstream parent_upstream &&
+       test_commit -C upstream one &&
+
+       test_create_repo parent &&
+       git -C parent remote add up ../parent_upstream &&
+       test_commit -C parent one &&
+       git -C parent push --mirror up &&
+
+       git -C parent submodule add ../upstream workbench &&
+       git -C parent/workbench remote add up ../../upstream &&
+       git -C parent commit -m "add submoule" &&
+
+       test_commit -C parent/workbench two &&
+       git -C parent add workbench &&
+       git -C parent commit -m "update workbench" &&
+
+       git -C parent push \
+               --push-option=asdf --push-option="more structured text" \
+               --recurse-submodules=on-demand up master &&
+
+       git -C upstream rev-parse --verify master >expect &&
+       git -C parent/workbench rev-parse --verify master >actual &&
+       test_cmp expect actual &&
+
+       git -C parent_upstream rev-parse --verify master >expect &&
+       git -C parent rev-parse --verify master >actual &&
+       test_cmp expect actual &&
+
+       printf "asdf\nmore structured text\n" >expect &&
+       test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
+       test_cmp expect upstream/.git/hooks/post-receive.push_options &&
+       test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
+       test_cmp expect parent_upstream/.git/hooks/post-receive.push_options
+'
+
 stop_httpd
 
 test_done
index 417ed7f19f5fcec5fdf9828749e1e40b207a44e7..64e60b6353903f60dfe64f7730cce3aac2611f13 100644 (file)
@@ -1031,6 +1031,7 @@ int transport_push(struct transport *transport,
 
                        if (!push_unpushed_submodules(&commits,
                                                      transport->remote->name,
+                                                     transport->push_options,
                                                      pretend)) {
                                sha1_array_clear(&commits);
                                die("Failed to push all needed submodules!");