submodule update: use die_message()
Use die_message() to print the "fatal: " prefix instead of doing it in git-submodule.sh and remove a now-unnecessary exit code from "git submodule--helper run-update-procedure". Also, since die_message() adds the newline for us, replace an invocation of die_with_status() with printf + exit invocations that do not add a newline, but are otherwise identical to die_with_status(). Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committed
Mar 15, 2022 at 14:09 UTC
55b3f12cb54077463709b2ac20cc64eba7dbf673
2 files changed
+19
-23
builtin/submodule--helper.c
+14
-19
@@ -2366,40 +2366,35 @@ static int run_update_command(struct update_data *ud, int subforce)
2366
if (run_command(&cp)) {
2367
switch (ud->update_strategy.type) {
2368
case SM_UPDATE_CHECKOUT:
2369
- printf(_("Unable to checkout '%s' in submodule path '%s'"),
2370
- oid, ud->displaypath);
2369
+ die_message(_("Unable to checkout '%s' in submodule path '%s'"),
2370
+ oid, ud->displaypath);
2371
break;
2372
case SM_UPDATE_REBASE:
2373
- printf(_("Unable to rebase '%s' in submodule path '%s'"),
2374
- oid, ud->displaypath);
2373
+ die_message(_("Unable to rebase '%s' in submodule path '%s'"),
2374
+ oid, ud->displaypath);
2375
break;
2376
case SM_UPDATE_MERGE:
2377
- printf(_("Unable to merge '%s' in submodule path '%s'"),
2378
- oid, ud->displaypath);
2377
+ die_message(_("Unable to merge '%s' in submodule path '%s'"),
2378
+ oid, ud->displaypath);
2379
break;
2380
case SM_UPDATE_COMMAND:
2381
- printf(_("Execution of '%s %s' failed in submodule path '%s'"),
2382
- ud->update_strategy.command, oid, ud->displaypath);
2381
+ die_message(_("Execution of '%s %s' failed in submodule path '%s'"),
2382
+ ud->update_strategy.command, oid, ud->displaypath);
2383
break;
2384
default:
2385
BUG("unexpected update strategy type: %s",
2386
submodule_strategy_to_string(&ud->update_strategy));
2387
}
2388
- /*
2389
- * NEEDSWORK: We are currently printing to stdout with error
2390
- * return so that the shell caller handles the error output
2391
- * properly. Once we start handling the error messages within
2392
- * C, we should use die() instead.
2393
- */
2388
if (must_die_on_failure)
2395
- return 2;
2396
- /*
2397
- * This signifies to the caller in shell that the command
2398
- * failed without dying
2399
- */
2389
+ exit(128);
2390
+
2391
+ /* the command failed, but update must continue */
2392
return 1;
2393
}
2394
2395
+ if (ud->quiet)
2396
+ return 0;
2397
+
2398
switch (ud->update_strategy.type) {
2399
case SM_UPDATE_CHECKOUT:
2400
printf(_("Submodule path '%s': checked out '%s'\n"),
git-submodule.sh
+5
-4
@@ -404,7 +404,7 @@ cmd_update()
404
# exit codes for run-update-procedure:
405
# 0: update was successful, say command output
406
# 1: update procedure failed, but should not die
407
- # 2 or 128: subcommand died during execution
407
+ # 128: subcommand died during execution
408
# 3: no update procedure was run
409
res="$?"
410
case $res in
@@ -412,11 +412,12 @@ cmd_update()
412
say "$out"
413
;;
414
1)
415
- err="${err};fatal: $out"
415
+ err="${err};$out"
416
continue
417
;;
418
- 2|128)
419
- die_with_status $res "fatal: $out"
418
+ 128)
419
+ printf >&2 "$out"
420
+ exit $res
421
;;
422
esac
423