Merge branch 'bw/push-options-recursively-to-submodules'
authorJunio C Hamano <gitster@pobox.com>
Thu, 20 Apr 2017 04:37:14 +0000 (21:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Apr 2017 04:37:14 +0000 (21:37 -0700)
"git push --recurse-submodules --push-option=<string>" learned to
propagate the push option recursively down to pushes in submodules.

* bw/push-options-recursively-to-submodules:
push: propagate remote and refspec with --recurse-submodules
submodule--helper: add push-check subcommand
remote: expose parse_push_refspec function
push: propagate push-options with --recurse-submodules
push: unmark a local variable as static

1  2 
remote.c
remote.h
submodule.c
submodule.h
transport.c
diff --cc remote.c
Simple merge
diff --cc remote.h
Simple merge
diff --cc submodule.c
index 6368d5fa6afe001d38a63908a5a62cfe498ceaea,49ab132d059448e21b29d445ef342022e0389395..cdbecfbeaf8c16af192845c95477985e659bcd20
@@@ -806,8 -824,42 +825,42 @@@ static int push_submodule(const char *p
        return 1;
  }
  
 -int push_unpushed_submodules(struct sha1_array *commits,
+ /*
+  * Perform a check in the submodule to see if the remote and refspec work.
+  * Die if the submodule can't be pushed.
+  */
+ static void submodule_push_check(const char *path, const struct remote *remote,
+                                const char **refspec, int refspec_nr)
+ {
+       struct child_process cp = CHILD_PROCESS_INIT;
+       int i;
+       argv_array_push(&cp.args, "submodule--helper");
+       argv_array_push(&cp.args, "push-check");
+       argv_array_push(&cp.args, remote->name);
+       for (i = 0; i < refspec_nr; i++)
+               argv_array_push(&cp.args, refspec[i]);
+       prepare_submodule_repo_env(&cp.env_array);
+       cp.git_cmd = 1;
+       cp.no_stdin = 1;
+       cp.no_stdout = 1;
+       cp.dir = path;
+       /*
+        * Simply indicate if 'submodule--helper push-check' failed.
+        * More detailed error information will be provided by the
+        * child process.
+        */
+       if (run_command(&cp))
+               die("process for submodule '%s' failed", path);
+ }
-                            const char *remotes_name,
 +int push_unpushed_submodules(struct oid_array *commits,
+                            const struct remote *remote,
+                            const char **refspec, int refspec_nr,
+                            const struct string_list *push_options,
                             int dry_run)
  {
        int i, ret = 1;
diff --cc submodule.h
index a86f757a06720e1bc85d7e9ecad51ffbc6610dbe,127ff9be84399cb67734560fc901f4226ccc73b3..486371d2c34a9397d9f075f052cbae774ad662e7
@@@ -3,7 -3,8 +3,8 @@@
  
  struct diff_options;
  struct argv_array;
 -struct sha1_array;
 +struct oid_array;
+ struct remote;
  
  enum {
        RECURSE_SUBMODULES_ONLY = -5,
@@@ -87,11 -88,13 +88,13 @@@ extern int merge_submodule(unsigned cha
                           const unsigned char base[20],
                           const unsigned char a[20],
                           const unsigned char b[20], int search);
 -extern int find_unpushed_submodules(struct sha1_array *commits,
 +extern int find_unpushed_submodules(struct oid_array *commits,
                                    const char *remotes_name,
                                    struct string_list *needs_pushing);
 -extern int push_unpushed_submodules(struct sha1_array *commits,
 +extern int push_unpushed_submodules(struct oid_array *commits,
-                                   const char *remotes_name,
+                                   const struct remote *remote,
+                                   const char **refspec, int refspec_nr,
+                                   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);
diff --cc transport.c
index c83f3b71bebffee19daa88cfba76aa8d16938b2f,a62e5118c0575e50b93e9b659287e215369b22f9..4d33138a7525310af3f9f73b699360f159516ad1
@@@ -1027,16 -1027,17 +1027,18 @@@ int transport_push(struct transport *tr
  
                        for (; ref; ref = ref->next)
                                if (!is_null_oid(&ref->new_oid))
 -                                      sha1_array_append(&commits, ref->new_oid.hash);
 +                                      oid_array_append(&commits,
 +                                                        &ref->new_oid);
  
                        if (!push_unpushed_submodules(&commits,
-                                                     transport->remote->name,
+                                                     transport->remote,
+                                                     refspec, refspec_nr,
+                                                     transport->push_options,
                                                      pretend)) {
 -                              sha1_array_clear(&commits);
 +                              oid_array_clear(&commits);
                                die("Failed to push all needed submodules!");
                        }
 -                      sha1_array_clear(&commits);
 +                      oid_array_clear(&commits);
                }
  
                if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||