submodule: prefix die messages with 'fatal'

The standard `die()` function that is used in C code prefixes all the messages passed to it with 'fatal: '. This does not happen with the `die` used in 'git-submodule.sh'. Let's prefix each of the shell die messages with 'fatal: ' so that when they are converted to C code, the error messages stay the same as before the conversion. Note that the shell version of `die` exits with error code 1, while the C version exits with error code 128. In practice, this does not change any behaviour, as no functionality in 'submodule add' and 'submodule update' relies on the value of the exit code. Signed-off-by: Atharva Raykar <raykar.ath@gmail.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Shourya Shukla <periperidip@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Atharva Raykar committed Jul 10, 2021 at 13:17 UTC 0008d12284ef916b53341c2aadccdc017ff07c7a
3 files changed +26 -26
git-submodule.sh
+19 -19
@@ -147,7 +147,7 @@ cmd_add()
147
148 if ! git submodule--helper config --check-writeable >/dev/null 2>&1
149 then
150 - die "$(eval_gettext "please make sure that the .gitmodules file is in the working tree")"
150 + die "fatal: $(eval_gettext "please make sure that the .gitmodules file is in the working tree")"
151 fi
152
153 if test -n "$reference_path"
@@ -176,7 +176,7 @@ cmd_add()
176 case "$repo" in
177 ./*|../*)
178 test -z "$wt_prefix" ||
179 - die "$(gettext "Relative path can only be used from the toplevel of the working tree")"
179 + die "fatal: $(gettext "Relative path can only be used from the toplevel of the working tree")"
180
181 # dereference source url relative to parent's url
182 realrepo=$(git submodule--helper resolve-relative-url "$repo") || exit
@@ -186,7 +186,7 @@ cmd_add()
186 realrepo=$repo
187 ;;
188 *)
189 - die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
189 + die "fatal: $(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
190 ;;
191 esac
192
@@ -205,17 +205,17 @@ cmd_add()
205 if test -z "$force"
206 then
207 git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
208 - die "$(eval_gettext "'\$sm_path' already exists in the index")"
208 + die "fatal: $(eval_gettext "'\$sm_path' already exists in the index")"
209 else
210 git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 &&
211 - die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
211 + die "fatal: $(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
212 fi
213
214 if test -d "$sm_path" &&
215 test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null)
216 then
217 git -C "$sm_path" rev-parse --verify -q HEAD >/dev/null ||
218 - die "$(eval_gettext "'\$sm_path' does not have a commit checked out")"
218 + die "fatal: $(eval_gettext "'\$sm_path' does not have a commit checked out")"
219 fi
220
221 if test -z "$force"
@@ -238,7 +238,7 @@ cmd_add()
238
239 if ! git submodule--helper check-name "$sm_name"
240 then
241 - die "$(eval_gettext "'$sm_name' is not a valid submodule name")"
241 + die "fatal: $(eval_gettext "'$sm_name' is not a valid submodule name")"
242 fi
243
244 # perhaps the path exists and is already a git repo, else clone it
@@ -281,7 +281,7 @@ or you are unsure what this means choose another name with the '--name' option."
281 git config submodule."$sm_name".url "$realrepo"
282
283 git add --no-warn-embedded-repo $force "$sm_path" ||
284 - die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
284 + die "fatal: $(eval_gettext "Failed to add submodule '\$sm_path'")"
285
286 git submodule--helper config submodule."$sm_name".path "$sm_path" &&
287 git submodule--helper config submodule."$sm_name".url "$repo" &&
@@ -290,7 +290,7 @@ or you are unsure what this means choose another name with the '--name' option."
290 git submodule--helper config submodule."$sm_name".branch "$branch"
291 fi &&
292 git add --force .gitmodules ||
293 - die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
293 + die "fatal: $(eval_gettext "Failed to register submodule '\$sm_path'")"
294
295 # NEEDSWORK: In a multi-working-tree world, this needs to be
296 # set in the per-worktree config.
@@ -565,7 +565,7 @@ cmd_update()
565 else
566 subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
567 git rev-parse --verify HEAD) ||
568 - die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
568 + die "fatal: $(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
569 fi
570
571 if test -n "$remote"
@@ -575,12 +575,12 @@ cmd_update()
575 then
576 # Fetch remote before determining tracking $sha1
577 fetch_in_submodule "$sm_path" $depth ||
578 - die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
578 + die "fatal: $(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
579 fi
580 remote_name=$(sanitize_submodule_env; cd "$sm_path" && git submodule--helper print-default-remote)
581 sha1=$(sanitize_submodule_env; cd "$sm_path" &&
582 git rev-parse --verify "${remote_name}/${branch}") ||
583 - die "$(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
583 + die "fatal: $(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
584 fi
585
586 if test "$subsha1" != "$sha1" || test -n "$force"
@@ -604,36 +604,36 @@ cmd_update()
604 # not be reachable from any of the refs
605 is_tip_reachable "$sm_path" "$sha1" ||
606 fetch_in_submodule "$sm_path" "$depth" "$sha1" ||
607 - die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")"
607 + die "fatal: $(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")"
608 fi
609
610 must_die_on_failure=
611 case "$update_module" in
612 checkout)
613 command="git checkout $subforce -q"
614 - die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")"
614 + die_msg="fatal: $(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")"
615 say_msg="$(eval_gettext "Submodule path '\$displaypath': checked out '\$sha1'")"
616 ;;
617 rebase)
618 command="git rebase ${GIT_QUIET:+--quiet}"
619 - die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$displaypath'")"
619 + die_msg="fatal: $(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$displaypath'")"
620 say_msg="$(eval_gettext "Submodule path '\$displaypath': rebased into '\$sha1'")"
621 must_die_on_failure=yes
622 ;;
623 merge)
624 command="git merge ${GIT_QUIET:+--quiet}"
625 - die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$displaypath'")"
625 + die_msg="fatal: $(eval_gettext "Unable to merge '\$sha1' in submodule path '\$displaypath'")"
626 say_msg="$(eval_gettext "Submodule path '\$displaypath': merged in '\$sha1'")"
627 must_die_on_failure=yes
628 ;;
629 !*)
630 command="${update_module#!}"
631 - die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$displaypath'")"
631 + die_msg="fatal: $(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$displaypath'")"
632 say_msg="$(eval_gettext "Submodule path '\$displaypath': '\$command \$sha1'")"
633 must_die_on_failure=yes
634 ;;
635 *)
636 - die "$(eval_gettext "Invalid update mode '$update_module' for submodule path '$path'")"
636 + die "fatal: $(eval_gettext "Invalid update mode '$update_module' for submodule path '$path'")"
637 esac
638
639 if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1")
@@ -660,7 +660,7 @@ cmd_update()
660 res=$?
661 if test $res -gt 0
662 then
663 - die_msg="$(eval_gettext "Failed to recurse into submodule path '\$displaypath'")"
663 + die_msg="fatal: $(eval_gettext "Failed to recurse into submodule path '\$displaypath'")"
664 if test $res -ne 2
665 then
666 err="${err};$die_msg"
t/t7400-submodule-basic.sh
+2 -2
@@ -51,7 +51,7 @@ test_expect_success 'submodule update aborts on missing gitmodules url' '
51
52 test_expect_success 'add aborts on repository with no commits' '
53 cat >expect <<-\EOF &&
54 - '"'repo-no-commits'"' does not have a commit checked out
54 + fatal: '"'repo-no-commits'"' does not have a commit checked out
55 EOF
56 git init repo-no-commits &&
57 test_must_fail git submodule add ../a ./repo-no-commits 2>actual &&
@@ -199,7 +199,7 @@ test_expect_success 'submodule add to .gitignored path with --force' '
199 test_expect_success 'submodule add to path with tracked content fails' '
200 (
201 cd addtest &&
202 - echo "'\''dir-tracked'\'' already exists in the index" >expect &&
202 + echo "fatal: '\''dir-tracked'\'' already exists in the index" >expect &&
203 mkdir dir-tracked &&
204 test_commit foo dir-tracked/bar &&
205 test_must_fail git submodule add "$submodurl" dir-tracked >actual 2>&1 &&
t/t7406-submodule-update.sh
+5 -5
@@ -448,7 +448,7 @@ test_expect_success 'fsck detects command in .gitmodules' '
448 '
449
450 cat << EOF >expect
451 -Execution of 'false $submodulesha1' failed in submodule path 'submodule'
451 +fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule'
452 EOF
453
454 test_expect_success 'submodule update - command in .git/config catches failure' '
@@ -465,7 +465,7 @@ test_expect_success 'submodule update - command in .git/config catches failure'
465 '
466
467 cat << EOF >expect
468 -Execution of 'false $submodulesha1' failed in submodule path '../submodule'
468 +fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule'
469 EOF
470
471 test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
@@ -484,7 +484,7 @@ test_expect_success 'submodule update - command in .git/config catches failure -
484
485 test_expect_success 'submodule update - command run for initial population of submodule' '
486 cat >expect <<-EOF &&
487 - Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
487 + fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
488 EOF
489 rm -rf super/submodule &&
490 test_must_fail git -C super submodule update 2>actual &&
@@ -493,8 +493,8 @@ test_expect_success 'submodule update - command run for initial population of su
493 '
494
495 cat << EOF >expect
496 -Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
497 -Failed to recurse into submodule path '../super'
496 +fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
497 +fatal: Failed to recurse into submodule path '../super'
498 EOF
499
500 test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '