submodule tests: test for init and update failure output

Amend some submodule tests to test for the failure output of "git submodule [update|init]". The lack of such tests hid a regression in an earlier version of a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 4, 2022 at 16:13 UTC aca8568e2c342b1764837df29468ed498b5e6dcd
2 files changed +25 -3
t/t7406-submodule-update.sh
+12 -2
@@ -205,8 +205,18 @@ test_expect_success 'submodule update should fail due to local changes' '
205 (cd submodule &&
206 compare_head
207 ) &&
208 - test_must_fail git submodule update submodule
209 - )
208 + test_must_fail git submodule update submodule 2>../actual.raw
209 + ) &&
210 + sed "s/^> //" >expect <<-\EOF &&
211 + > error: Your local changes to the following files would be overwritten by checkout:
212 + > file
213 + > Please commit your changes or stash them before you switch branches.
214 + > Aborting
215 + > fatal: Unable to checkout OID in submodule path '\''submodule'\''
216 + EOF
217 + sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual &&
218 + test_cmp expect actual
219 +
220 '
221 test_expect_success 'submodule update should throw away changes with --force ' '
222 (cd super &&
t/t7408-submodule-reference.sh
+13 -1
@@ -193,7 +193,19 @@ test_expect_success 'missing nested submodule alternate fails clone and submodul
193 cd supersuper-clone &&
194 check_that_two_of_three_alternates_are_used &&
195 # update of the submodule fails
196 - test_must_fail git submodule update --init --recursive
196 + cat >expect <<-\EOF &&
197 + fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist
198 + Failed to clone '\''sub'\''. Retry scheduled
199 + fatal: submodule '\''sub-dissociate'\'' cannot add alternate: path ... does not exist
200 + Failed to clone '\''sub-dissociate'\''. Retry scheduled
201 + fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist
202 + Failed to clone '\''sub'\'' a second time, aborting
203 + fatal: Failed to recurse into submodule path ...
204 + EOF
205 + test_must_fail git submodule update --init --recursive 2>err &&
206 + grep -e fatal: -e ^Failed err >actual.raw &&
207 + sed -e "s/path $SQ[^$SQ]*$SQ/path .../" <actual.raw >actual &&
208 + test_cmp expect actual
209 )
210 '
211