diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 35abb993d8..1646caf82a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2123,7 +2123,8 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, return run_command(&cp); } -static int run_update_command(const struct update_data *ud, int subforce) +static int run_update_command(const struct update_data *ud, int subforce, + int *must_die_on_failure) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2187,7 +2188,7 @@ static int run_update_command(const struct update_data *ud, int subforce) } if (ret == 128) - exit(ret); + *must_die_on_failure = 1; return ret; } @@ -2219,7 +2220,8 @@ static int run_update_command(const struct update_data *ud, int subforce) return 0; } -static int run_update_procedure(const struct update_data *ud) +static int run_update_procedure(const struct update_data *ud, + int *must_die_on_failure) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2246,7 +2248,7 @@ static int run_update_procedure(const struct update_data *ud) ud->displaypath, oid_to_hex(&ud->oid)); } - return run_update_command(ud, subforce); + return run_update_command(ud, subforce, must_die_on_failure); } static const char *remote_submodule_branch(const char *path) @@ -2383,7 +2385,8 @@ static void update_data_to_args(const struct update_data *update_data, "--no-single-branch"); } -static int update_submodule(struct update_data *update_data) +static int update_submodule(struct update_data *update_data, + int *must_die_on_failure) { ensure_core_worktree(update_data->sm_path); @@ -2419,9 +2422,15 @@ static int update_submodule(struct update_data *update_data) free(remote_ref); } - if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) - if (run_update_procedure(update_data)) + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { + int ret; + + ret = run_update_procedure(update_data, must_die_on_failure); + if (*must_die_on_failure) + return ret; + if (ret) return 1; + } if (update_data->recursive) { struct child_process cp = CHILD_PROCESS_INIT; @@ -2437,14 +2446,13 @@ static int update_submodule(struct update_data *update_data) prepare_submodule_repo_env(&cp.env); update_data_to_args(&next, &cp.args); - /* die() if child process die()'d */ ret = run_command(&cp); if (!ret) return 0; die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); if (ret == 128) - exit(ret); + *must_die_on_failure = 1; return ret; } @@ -2477,12 +2485,19 @@ static int update_submodules(struct update_data *update_data) for (i = 0; i < suc.update_clone_nr; i++) { struct update_clone_data ucd = suc.update_clone[i]; + int must_die_on_failure = 0; + int code; oidcpy(&update_data->oid, &ucd.oid); update_data->just_cloned = ucd.just_cloned; update_data->sm_path = ucd.sub->path; - if (update_submodule(update_data)) + code = update_submodule(update_data, &must_die_on_failure); + if (code) + ret = code; + if (must_die_on_failure) + goto cleanup; + else if (code) ret = 1; }