for-each-repo: test outside of repo context

The 'git for-each-repo' tool is frequently run outside of a repo context in the real world. For example, it powers background maintenance. Despite this typical case, we have not been testing it without a local repository. Update t0068 to stop creating a test repo and to use global config everywhere. This has some subtle changes to test across the file. This was noticed because an earlier attempt to remove the_repository from builtin/for-each-repo.c did not catch a segmentation fault since the passed 'repo' is NULL. This use of the_repository will need to stay until we have a better way to handle config queries outside of a repo context. Similar use still exists in builtin/config.c for the same reason. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Mar 3, 2026 at 17:31 UTC c5e62e1aa07c7436cb081c7ef3a6995578f38b27
1 file changed +12 -7
t/t0068-for-each-repo.sh
+12 -7
@@ -2,6 +2,9 @@
2
3 test_description='git for-each-repo builtin'
4
5 +# We need to test running 'git for-each-repo' outside of a repo context.
6 +TEST_NO_CREATE_REPO=1
7 +
8 . ./test-lib.sh
9
10 test_expect_success 'run based on configured value' '
@@ -10,9 +13,10 @@ test_expect_success 'run based on configured value' '
13 git init three &&
14 git init ~/four &&
15 git -C two commit --allow-empty -m "DID NOT RUN" &&
13 - git config run.key "$TRASH_DIRECTORY/one" &&
14 - git config --add run.key "$TRASH_DIRECTORY/three" &&
15 - git config --add run.key "~/four" &&
16 + git config --global run.key "$TRASH_DIRECTORY/one" &&
17 + git config --global --add run.key "$TRASH_DIRECTORY/three" &&
18 + git config --global --add run.key "~/four" &&
19 +
20 git for-each-repo --config=run.key commit --allow-empty -m "ran" &&
21 git -C one log -1 --pretty=format:%s >message &&
22 grep ran message &&
@@ -22,6 +26,7 @@ test_expect_success 'run based on configured value' '
26 grep ran message &&
27 git -C ~/four log -1 --pretty=format:%s >message &&
28 grep ran message &&
29 +
30 git for-each-repo --config=run.key -- commit --allow-empty -m "ran again" &&
31 git -C one log -1 --pretty=format:%s >message &&
32 grep again message &&
@@ -46,7 +51,7 @@ test_expect_success 'error on bad config keys' '
51 '
52
53 test_expect_success 'error on NULL value for config keys' '
49 - cat >>.git/config <<-\EOF &&
54 + cat >>.gitconfig <<-\EOF &&
55 [empty]
56 key
57 EOF
@@ -59,8 +64,8 @@ test_expect_success 'error on NULL value for config keys' '
64 '
65
66 test_expect_success '--keep-going' '
62 - git config keep.going non-existing &&
63 - git config --add keep.going . &&
67 + git config --global keep.going non-existing &&
68 + git config --global --add keep.going one &&
69
70 test_must_fail git for-each-repo --config=keep.going \
71 -- branch >out 2>err &&
@@ -70,7 +75,7 @@ test_expect_success '--keep-going' '
75 test_must_fail git for-each-repo --config=keep.going --keep-going \
76 -- branch >out 2>err &&
77 test_grep "cannot change to .*non-existing" err &&
73 - git branch >expect &&
78 + git -C one branch >expect &&
79 test_cmp expect out
80 '
81