22
33test_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
710test_expect_success ' run based on configured value' '
8- git init one &&
9- git init two &&
10- git init three &&
11- git init ~/four &&
11+ git init --initial-branch=one one &&
12+ git init --initial-branch=two two &&
13+ git -C two worktree add --orphan ../three &&
14+ git -C three checkout -b three &&
15+ git init --initial-branch=four ~/four &&
16+
1217 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" &&
18+ git config --global run.key "$TRASH_DIRECTORY/one" &&
19+ git config --global --add run.key "$TRASH_DIRECTORY/three" &&
20+ git config --global --add run.key "~/four" &&
21+
1622 git for-each-repo --config=run.key commit --allow-empty -m "ran" &&
1723 git -C one log -1 --pretty=format:%s >message &&
1824 grep ran message &&
@@ -22,6 +28,7 @@ test_expect_success 'run based on configured value' '
2228 grep ran message &&
2329 git -C ~/four log -1 --pretty=format:%s >message &&
2430 grep ran message &&
31+
2532 git for-each-repo --config=run.key -- commit --allow-empty -m "ran again" &&
2633 git -C one log -1 --pretty=format:%s >message &&
2734 grep again message &&
@@ -30,7 +37,43 @@ test_expect_success 'run based on configured value' '
3037 git -C three log -1 --pretty=format:%s >message &&
3138 grep again message &&
3239 git -C ~/four log -1 --pretty=format:%s >message &&
33- grep again message
40+ grep again message &&
41+
42+ git -C three for-each-repo --config=run.key -- \
43+ commit --allow-empty -m "ran from worktree" &&
44+ git -C one log -1 --pretty=format:%s >message &&
45+ test_grep "ran from worktree" message &&
46+ git -C two log -1 --pretty=format:%s >message &&
47+ test_grep ! "ran from worktree" message &&
48+ git -C three log -1 --pretty=format:%s >message &&
49+ test_grep "ran from worktree" message &&
50+ git -C ~/four log -1 --pretty=format:%s >message &&
51+ test_grep "ran from worktree" message &&
52+
53+ # Test running with config values set by environment
54+ cat >expect <<-EOF &&
55+ ran from worktree (HEAD -> refs/heads/one)
56+ ran from worktree (HEAD -> refs/heads/three)
57+ ran from worktree (HEAD -> refs/heads/four)
58+ EOF
59+
60+ GIT_CONFIG_PARAMETERS="${SQ}log.decorate=full${SQ}" \
61+ git -C three for-each-repo --config=run.key -- log --format="%s%d" -1 >out &&
62+ test_cmp expect out &&
63+
64+ cat >test-config <<-EOF &&
65+ [run]
66+ key = $(pwd)/one
67+ key = $(pwd)/three
68+ key = $(pwd)/four
69+
70+ [log]
71+ decorate = full
72+ EOF
73+
74+ GIT_CONFIG_GLOBAL="$(pwd)/test-config" \
75+ git -C three for-each-repo --config=run.key -- log --format="%s%d" -1 >out &&
76+ test_cmp expect out
3477'
3578
3679test_expect_success ' do nothing on empty config' '
@@ -46,7 +89,7 @@ test_expect_success 'error on bad config keys' '
4689'
4790
4891test_expect_success ' error on NULL value for config keys' '
49- cat >>.git/config <<-\EOF &&
92+ cat >>.gitconfig <<-\EOF &&
5093 [empty]
5194 key
5295 EOF
@@ -59,8 +102,8 @@ test_expect_success 'error on NULL value for config keys' '
59102'
60103
61104test_expect_success ' --keep-going' '
62- git config keep.going non-existing &&
63- git config --add keep.going . &&
105+ git config --global keep.going non-existing &&
106+ git config --global -- add keep.going one &&
64107
65108 test_must_fail git for-each-repo --config=keep.going \
66109 -- branch >out 2>err &&
@@ -70,7 +113,7 @@ test_expect_success '--keep-going' '
70113 test_must_fail git for-each-repo --config=keep.going --keep-going \
71114 -- branch >out 2>err &&
72115 test_grep "cannot change to .*non-existing" err &&
73- git branch >expect &&
116+ git -C one branch >expect &&
74117 test_cmp expect out
75118'
76119
0 commit comments