Skip to content

Commit 0008d12

Browse files
tfidfwastakengitster
authored andcommitted
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 <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Shourya Shukla <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 84069fc commit 0008d12

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

git-submodule.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ cmd_add()
147147

148148
if ! git submodule--helper config --check-writeable >/dev/null 2>&1
149149
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")"
151151
fi
152152

153153
if test -n "$reference_path"
@@ -176,7 +176,7 @@ cmd_add()
176176
case "$repo" in
177177
./*|../*)
178178
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")"
180180

181181
# dereference source url relative to parent's url
182182
realrepo=$(git submodule--helper resolve-relative-url "$repo") || exit
@@ -186,7 +186,7 @@ cmd_add()
186186
realrepo=$repo
187187
;;
188188
*)
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 ./|../")"
190190
;;
191191
esac
192192

@@ -205,17 +205,17 @@ cmd_add()
205205
if test -z "$force"
206206
then
207207
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")"
209209
else
210210
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")"
212212
fi
213213

214214
if test -d "$sm_path" &&
215215
test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null)
216216
then
217217
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")"
219219
fi
220220

221221
if test -z "$force"
@@ -238,7 +238,7 @@ cmd_add()
238238

239239
if ! git submodule--helper check-name "$sm_name"
240240
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")"
242242
fi
243243

244244
# 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."
281281
git config submodule."$sm_name".url "$realrepo"
282282

283283
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'")"
285285

286286
git submodule--helper config submodule."$sm_name".path "$sm_path" &&
287287
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."
290290
git submodule--helper config submodule."$sm_name".branch "$branch"
291291
fi &&
292292
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'")"
294294

295295
# NEEDSWORK: In a multi-working-tree world, this needs to be
296296
# set in the per-worktree config.
@@ -565,7 +565,7 @@ cmd_update()
565565
else
566566
subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
567567
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'")"
569569
fi
570570

571571
if test -n "$remote"
@@ -575,12 +575,12 @@ cmd_update()
575575
then
576576
# Fetch remote before determining tracking $sha1
577577
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'")"
579579
fi
580580
remote_name=$(sanitize_submodule_env; cd "$sm_path" && git submodule--helper print-default-remote)
581581
sha1=$(sanitize_submodule_env; cd "$sm_path" &&
582582
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'")"
584584
fi
585585

586586
if test "$subsha1" != "$sha1" || test -n "$force"
@@ -604,36 +604,36 @@ cmd_update()
604604
# not be reachable from any of the refs
605605
is_tip_reachable "$sm_path" "$sha1" ||
606606
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.")"
608608
fi
609609

610610
must_die_on_failure=
611611
case "$update_module" in
612612
checkout)
613613
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'")"
615615
say_msg="$(eval_gettext "Submodule path '\$displaypath': checked out '\$sha1'")"
616616
;;
617617
rebase)
618618
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'")"
620620
say_msg="$(eval_gettext "Submodule path '\$displaypath': rebased into '\$sha1'")"
621621
must_die_on_failure=yes
622622
;;
623623
merge)
624624
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'")"
626626
say_msg="$(eval_gettext "Submodule path '\$displaypath': merged in '\$sha1'")"
627627
must_die_on_failure=yes
628628
;;
629629
!*)
630630
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'")"
632632
say_msg="$(eval_gettext "Submodule path '\$displaypath': '\$command \$sha1'")"
633633
must_die_on_failure=yes
634634
;;
635635
*)
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'")"
637637
esac
638638

639639
if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1")
@@ -660,7 +660,7 @@ cmd_update()
660660
res=$?
661661
if test $res -gt 0
662662
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'")"
664664
if test $res -ne 2
665665
then
666666
err="${err};$die_msg"

t/t7400-submodule-basic.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test_expect_success 'submodule update aborts on missing gitmodules url' '
5151

5252
test_expect_success 'add aborts on repository with no commits' '
5353
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
5555
EOF
5656
git init repo-no-commits &&
5757
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' '
199199
test_expect_success 'submodule add to path with tracked content fails' '
200200
(
201201
cd addtest &&
202-
echo "'\''dir-tracked'\'' already exists in the index" >expect &&
202+
echo "fatal: '\''dir-tracked'\'' already exists in the index" >expect &&
203203
mkdir dir-tracked &&
204204
test_commit foo dir-tracked/bar &&
205205
test_must_fail git submodule add "$submodurl" dir-tracked >actual 2>&1 &&

t/t7406-submodule-update.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ test_expect_success 'fsck detects command in .gitmodules' '
448448
'
449449

450450
cat << EOF >expect
451-
Execution of 'false $submodulesha1' failed in submodule path 'submodule'
451+
fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule'
452452
EOF
453453

454454
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'
465465
'
466466

467467
cat << EOF >expect
468-
Execution of 'false $submodulesha1' failed in submodule path '../submodule'
468+
fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule'
469469
EOF
470470

471471
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 -
484484

485485
test_expect_success 'submodule update - command run for initial population of submodule' '
486486
cat >expect <<-EOF &&
487-
Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
487+
fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
488488
EOF
489489
rm -rf super/submodule &&
490490
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
493493
'
494494

495495
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'
498498
EOF
499499

500500
test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '

0 commit comments

Comments
 (0)