Skip to content

Commit a03c01d

Browse files
avargitster
authored andcommitted
submodule--helper update: don't override 'checkout' exit code
When "git submodule update" runs it might call "checkout", "merge", "rebase", or a custom command. Ever since run_update_command() was added in c51f8f9 (submodule--helper: run update procedures from C, 2021-08-24) we'd either exit immediately if the "submodule.<name>.update" method failed, or in the case of "checkout" continue trying to update other submodules. This code used to use the magical "2" return code, but in 55b3f12 (submodule update: use die_message(), 2022-03-15) it was made to exit(128), which in preceding commits has been changed to return that 128 code to the top-level. Let's "libify" this code even more by not having it arbitrarily override the return code. In practice this doesn't change anything as the code "git checkout" would return on any normal failure is "1", but we'll now in principle properly abort the operation if "git checkout" were to exit with 128. It would make sense to follow-up this change with a change to allow the "submodule.<name>.update = !..." (SM_UPDATE_COMMAND) method the same liberties as "checkout", and perhaps to do the same with a failed "merge" or "rebase". But let's leave that for now. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Reviewed-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d905d44 commit a03c01d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

builtin/submodule--helper.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,7 @@ static int run_update_command(const struct update_data *ud, int subforce)
21332133
{
21342134
struct child_process cp = CHILD_PROCESS_INIT;
21352135
char *oid = oid_to_hex(&ud->oid);
2136+
int ret;
21362137

21372138
switch (ud->update_strategy.type) {
21382139
case SM_UPDATE_CHECKOUT:
@@ -2165,15 +2166,12 @@ static int run_update_command(const struct update_data *ud, int subforce)
21652166

21662167
cp.dir = xstrdup(ud->sm_path);
21672168
prepare_submodule_repo_env(&cp.env);
2168-
if (run_command(&cp)) {
2169-
int ret;
2170-
2169+
if ((ret = run_command(&cp))) {
21712170
switch (ud->update_strategy.type) {
21722171
case SM_UPDATE_CHECKOUT:
21732172
die_message(_("Unable to checkout '%s' in submodule path '%s'"),
21742173
oid, ud->displaypath);
2175-
/* the command failed, but update must continue */
2176-
ret = 1;
2174+
/* No "ret" assignment, use "git checkout"'s */
21772175
break;
21782176
case SM_UPDATE_REBASE:
21792177
ret = die_message(_("Unable to rebase '%s' in submodule path '%s'"),
@@ -2496,7 +2494,6 @@ static int update_submodules(struct update_data *update_data)
24962494
ret = code;
24972495
if (ret == 128)
24982496
goto cleanup;
2499-
ret = 1;
25002497
}
25012498

25022499
cleanup:

0 commit comments

Comments
 (0)