@ -14,6 +14,7 @@
@@ -14,6 +14,7 @@
#include "blob.h"
#include "thread-utils.h"
#include "quote.h"
#include "remote.h"
#include "worktree.h"
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
@ -783,7 +784,11 @@ int find_unpushed_submodules(struct oid_array *commits,
@@ -783,7 +784,11 @@ int find_unpushed_submodules(struct oid_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 remote *remote,
const char **refspec, int refspec_nr,
const struct string_list *push_options,
int dry_run)
{
if (add_submodule_odb(path))
return 1;
@ -794,6 +799,20 @@ static int push_submodule(const char *path, int dry_run)
@@ -794,6 +799,20 @@ 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);
}
if (remote->origin != REMOTE_UNCONFIGURED) {
int i;
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;
@ -806,20 +825,67 @@ static int push_submodule(const char *path, int dry_run)
@@ -806,20 +825,67 @@ static int push_submodule(const char *path, int dry_run)
return 1;
}
/*
* 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);
}
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)
{
int i, ret = 1;
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
if (!find_unpushed_submodules(commits, remotes_name, &needs_pushing))
if (!find_unpushed_submodules(commits, remote->name, &needs_pushing))
return 1;
/*
* Verify that the remote and refspec can be propagated to all
* submodules. This check can be skipped if the remote and refspec
* won't be propagated due to the remote being unconfigured (e.g. a URL
* instead of a remote name).
*/
if (remote->origin != REMOTE_UNCONFIGURED)
for (i = 0; i < needs_pushing.nr; i++)
submodule_push_check(needs_pushing.items[i].string,
remote, refspec, refspec_nr);
/* Actually push the submodules */
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, remote, refspec, refspec_nr,
push_options, dry_run)) {
fprintf(stderr, "Unable to push submodule '%s'\n", path);
ret = 0;
}