Skip to content

Commit 49eb1d3

Browse files
avargitster
authored andcommitted
submodule absorbgitdirs tests: add missing "Migrating git..." tests
Fix a blind spots in the tests surrounding "submodule absorbgitdirs" and test what output we emit, and how emitted the message and behavior interacts with a "git worktree" where the repository isn't at the base of the working directory. The "$(pwd)" instead of "$PWD" here is needed due to Windows, where the latter will be a path like "/d/a/git/[...]", whereas we need "D:/a/git/[...]". Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57e2c6e commit 49eb1d3

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

t/t7412-submodule-absorbgitdirs.sh

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TEST_PASSES_SANITIZE_LEAK=true
1010
. ./test-lib.sh
1111

1212
test_expect_success 'setup a real submodule' '
13+
cwd="$(pwd)" &&
1314
git init sub1 &&
1415
test_commit -C sub1 first &&
1516
git submodule add ./sub1 &&
@@ -18,13 +19,21 @@ test_expect_success 'setup a real submodule' '
1819
'
1920

2021
test_expect_success 'absorb the git dir' '
22+
>expect &&
23+
>actual &&
2124
>expect.1 &&
2225
>expect.2 &&
2326
>actual.1 &&
2427
>actual.2 &&
2528
git status >expect.1 &&
2629
git -C sub1 rev-parse HEAD >expect.2 &&
27-
git submodule absorbgitdirs &&
30+
cat >expect <<-EOF &&
31+
Migrating git directory of '\''sub1'\'' from
32+
'\''$cwd/sub1/.git'\'' to
33+
'\''$cwd/.git/modules/sub1'\''
34+
EOF
35+
git submodule absorbgitdirs 2>actual &&
36+
test_cmp expect actual &&
2837
git fsck &&
2938
test -f sub1/.git &&
3039
test -d .git/modules/sub1 &&
@@ -37,7 +46,8 @@ test_expect_success 'absorb the git dir' '
3746
test_expect_success 'absorbing does not fail for deinitialized submodules' '
3847
test_when_finished "git submodule update --init" &&
3948
git submodule deinit --all &&
40-
git submodule absorbgitdirs &&
49+
git submodule absorbgitdirs 2>err &&
50+
test_must_be_empty err &&
4151
test -d .git/modules/sub1 &&
4252
test -d sub1 &&
4353
! test -e sub1/.git
@@ -56,7 +66,13 @@ test_expect_success 'setup nested submodule' '
5666
test_expect_success 'absorb the git dir in a nested submodule' '
5767
git status >expect.1 &&
5868
git -C sub1/nested rev-parse HEAD >expect.2 &&
59-
git submodule absorbgitdirs &&
69+
cat >expect <<-EOF &&
70+
Migrating git directory of '\''sub1/nested'\'' from
71+
'\''$cwd/sub1/nested/.git'\'' to
72+
'\''$cwd/.git/modules/sub1/modules/nested'\''
73+
EOF
74+
git submodule absorbgitdirs 2>actual &&
75+
test_cmp expect actual &&
6076
test -f sub1/nested/.git &&
6177
test -d .git/modules/sub1/modules/nested &&
6278
git status >actual.1 &&
@@ -87,7 +103,13 @@ test_expect_success 're-setup nested submodule' '
87103
test_expect_success 'absorb the git dir in a nested submodule' '
88104
git status >expect.1 &&
89105
git -C sub1/nested rev-parse HEAD >expect.2 &&
90-
git submodule absorbgitdirs &&
106+
cat >expect <<-EOF &&
107+
Migrating git directory of '\''sub1'\'' from
108+
'\''$cwd/sub1/.git'\'' to
109+
'\''$cwd/.git/modules/sub1'\''
110+
EOF
111+
git submodule absorbgitdirs 2>actual &&
112+
test_cmp expect actual &&
91113
test -f sub1/.git &&
92114
test -f sub1/nested/.git &&
93115
test -d .git/modules/sub1/modules/nested &&
@@ -97,6 +119,27 @@ test_expect_success 'absorb the git dir in a nested submodule' '
97119
test_cmp expect.2 actual.2
98120
'
99121

122+
test_expect_success 'absorb the git dir outside of primary worktree' '
123+
test_when_finished "rm -rf repo-bare.git" &&
124+
git clone --bare . repo-bare.git &&
125+
test_when_finished "rm -rf repo-wt" &&
126+
git -C repo-bare.git worktree add ../repo-wt &&
127+
128+
test_when_finished "rm -f .gitconfig" &&
129+
test_config_global protocol.file.allow always &&
130+
git -C repo-wt submodule update --init &&
131+
git init repo-wt/sub2 &&
132+
test_commit -C repo-wt/sub2 A &&
133+
git -C repo-wt submodule add ./sub2 sub2 &&
134+
cat >expect <<-EOF &&
135+
Migrating git directory of '\''sub2'\'' from
136+
'\''$cwd/repo-wt/sub2/.git'\'' to
137+
'\''$cwd/repo-bare.git/worktrees/repo-wt/modules/sub2'\''
138+
EOF
139+
git -C repo-wt submodule absorbgitdirs 2>actual &&
140+
test_cmp expect actual
141+
'
142+
100143
test_expect_success 'setup a gitlink with missing .gitmodules entry' '
101144
git init sub2 &&
102145
test_commit -C sub2 first &&
@@ -107,7 +150,11 @@ test_expect_success 'setup a gitlink with missing .gitmodules entry' '
107150
test_expect_success 'absorbing the git dir fails for incomplete submodules' '
108151
git status >expect.1 &&
109152
git -C sub2 rev-parse HEAD >expect.2 &&
110-
test_must_fail git submodule absorbgitdirs &&
153+
cat >expect <<-\EOF &&
154+
fatal: could not lookup name for submodule '\''sub2'\''
155+
EOF
156+
test_must_fail git submodule absorbgitdirs 2>actual &&
157+
test_cmp expect actual &&
111158
git -C sub2 fsck &&
112159
test -d sub2/.git &&
113160
git status >actual &&
@@ -127,8 +174,11 @@ test_expect_success 'setup a submodule with multiple worktrees' '
127174
'
128175

129176
test_expect_success 'absorbing fails for a submodule with multiple worktrees' '
130-
test_must_fail git submodule absorbgitdirs sub3 2>error &&
131-
test_i18ngrep "not supported" error
177+
cat >expect <<-\EOF &&
178+
fatal: could not lookup name for submodule '\''sub2'\''
179+
EOF
180+
test_must_fail git submodule absorbgitdirs 2>actual &&
181+
test_cmp expect actual
132182
'
133183

134184
test_done

0 commit comments

Comments
 (0)