Skip to content

Commit 6412d01

Browse files
rjustogitster
authored andcommitted
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 5321399 (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 <[email protected]> Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1028db0 commit 6412d01

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

builtin/add.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ static void check_embedded_repo(const char *path)
310310
strbuf_strip_suffix(&name, "/");
311311

312312
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);
316316
adviced_on_embedded_repo = 1;
317317
}
318318

t/t3700-add.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,40 @@ test_expect_success '"git add ." in empty repo' '
349349
)
350350
'
351351

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+
352386
test_expect_success 'error on a repository with no commits' '
353387
rm -fr empty &&
354388
git init empty &&

0 commit comments

Comments
 (0)