Skip to content

Commit c5e62e1

Browse files
derrickstoleegitster
authored andcommitted
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>
1 parent 67ad421 commit c5e62e1

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

t/t0068-for-each-repo.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
test_description='git for-each-repo builtin'
44

5+
# We need to test running 'git for-each-repo' outside of a repo context.
6+
TEST_NO_CREATE_REPO=1
7+
58
. ./test-lib.sh
69

710
test_expect_success 'run based on configured value' '
@@ -10,9 +13,10 @@ test_expect_success 'run based on configured value' '
1013
git init three &&
1114
git init ~/four &&
1215
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+
1620
git for-each-repo --config=run.key commit --allow-empty -m "ran" &&
1721
git -C one log -1 --pretty=format:%s >message &&
1822
grep ran message &&
@@ -22,6 +26,7 @@ test_expect_success 'run based on configured value' '
2226
grep ran message &&
2327
git -C ~/four log -1 --pretty=format:%s >message &&
2428
grep ran message &&
29+
2530
git for-each-repo --config=run.key -- commit --allow-empty -m "ran again" &&
2631
git -C one log -1 --pretty=format:%s >message &&
2732
grep again message &&
@@ -46,7 +51,7 @@ test_expect_success 'error on bad config keys' '
4651
'
4752

4853
test_expect_success 'error on NULL value for config keys' '
49-
cat >>.git/config <<-\EOF &&
54+
cat >>.gitconfig <<-\EOF &&
5055
[empty]
5156
key
5257
EOF
@@ -59,8 +64,8 @@ test_expect_success 'error on NULL value for config keys' '
5964
'
6065

6166
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 &&
6469
6570
test_must_fail git for-each-repo --config=keep.going \
6671
-- branch >out 2>err &&
@@ -70,7 +75,7 @@ test_expect_success '--keep-going' '
7075
test_must_fail git for-each-repo --config=keep.going --keep-going \
7176
-- branch >out 2>err &&
7277
test_grep "cannot change to .*non-existing" err &&
73-
git branch >expect &&
78+
git -C one branch >expect &&
7479
test_cmp expect out
7580
'
7681

0 commit comments

Comments
 (0)