add: use advise_if_enabled for ADVICE_ADD_EMBEDDED_REPO
By following a similar reasoning as in previous commits, there are no reason why we should not use the advise_if_enabled() API to display the ADVICE_ADD_EMBEDDED_REPO advice. This advice was introduced in 532139940c (add: warn when adding an embedded repository, 2017-06-14). Some tests were included in the commit, but none is testing this advice. Which, note, we only want to display once per run. So, use the advise_if_enabled() machinery to show the ADVICE_ADD_EMBEDDED_REPO advice and include a test to notice any possible breakage. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Rubén Justo <rjusto@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Rubén Justo committed
Mar 30, 2024 at 15:09 UTC
6412d0152774155393ed97003a5c6121cf0a4684
2 files changed
+37
-3
builtin/add.c
+3
-3
@@ -310,9 +310,9 @@ static void check_embedded_repo(const char *path)
310
strbuf_strip_suffix(&name, "/");
311
312
warning(_("adding embedded git repository: %s"), name.buf);
313
- if (!adviced_on_embedded_repo &&
314
- advice_enabled(ADVICE_ADD_EMBEDDED_REPO)) {
315
- advise(embedded_advice, name.buf, name.buf);
313
+ if (!adviced_on_embedded_repo) {
314
+ advise_if_enabled(ADVICE_ADD_EMBEDDED_REPO,
315
+ embedded_advice, name.buf, name.buf);
316
adviced_on_embedded_repo = 1;
317
}
318
t/t3700-add.sh
+34
@@ -349,6 +349,40 @@ test_expect_success '"git add ." in empty repo' '
349
)
350
'
351
352
+test_expect_success '"git add" a embedded repository' '
353
+ rm -fr outer && git init outer &&
354
+ (
355
+ cd outer &&
356
+ for i in 1 2
357
+ do
358
+ name=inner$i &&
359
+ git init $name &&
360
+ git -C $name commit --allow-empty -m $name ||
361
+ return 1
362
+ done &&
363
+ git add . 2>actual &&
364
+ cat >expect <<-EOF &&
365
+ warning: adding embedded git repository: inner1
366
+ hint: You${SQ}ve added another git repository inside your current repository.
367
+ hint: Clones of the outer repository will not contain the contents of
368
+ hint: the embedded repository and will not know how to obtain it.
369
+ hint: If you meant to add a submodule, use:
370
+ hint:
371
+ hint: git submodule add <url> inner1
372
+ hint:
373
+ hint: If you added this path by mistake, you can remove it from the
374
+ hint: index with:
375
+ hint:
376
+ hint: git rm --cached inner1
377
+ hint:
378
+ hint: See "git help submodule" for more information.
379
+ hint: Disable this message with "git config advice.addEmbeddedRepo false"
380
+ warning: adding embedded git repository: inner2
381
+ EOF
382
+ test_cmp expect actual
383
+ )
384
+'
385
+
386
test_expect_success 'error on a repository with no commits' '
387
rm -fr empty &&
388
git init empty &&