]>
Commit | Line | Data |
---|---|---|
f6f85861 SB |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test submodule absorbgitdirs | |
4 | ||
5 | This test verifies that `git submodue absorbgitdirs` moves a submodules git | |
6 | directory into the superproject. | |
7 | ' | |
8 | ||
d40c42e0 | 9 | TEST_PASSES_SANITIZE_LEAK=true |
f6f85861 SB |
10 | . ./test-lib.sh |
11 | ||
12 | test_expect_success 'setup a real submodule' ' | |
13 | git init sub1 && | |
14 | test_commit -C sub1 first && | |
15 | git submodule add ./sub1 && | |
16 | test_tick && | |
17 | git commit -m superproject | |
18 | ' | |
19 | ||
20 | test_expect_success 'absorb the git dir' ' | |
21 | >expect.1 && | |
22 | >expect.2 && | |
23 | >actual.1 && | |
24 | >actual.2 && | |
25 | git status >expect.1 && | |
26 | git -C sub1 rev-parse HEAD >expect.2 && | |
27 | git submodule absorbgitdirs && | |
28 | git fsck && | |
29 | test -f sub1/.git && | |
30 | test -d .git/modules/sub1 && | |
31 | git status >actual.1 && | |
32 | git -C sub1 rev-parse HEAD >actual.2 && | |
33 | test_cmp expect.1 actual.1 && | |
34 | test_cmp expect.2 actual.2 | |
35 | ' | |
36 | ||
64127575 | 37 | test_expect_success 'absorbing does not fail for deinitialized submodules' ' |
f6f85861 SB |
38 | test_when_finished "git submodule update --init" && |
39 | git submodule deinit --all && | |
40 | git submodule absorbgitdirs && | |
41 | test -d .git/modules/sub1 && | |
42 | test -d sub1 && | |
43 | ! test -e sub1/.git | |
44 | ' | |
45 | ||
46 | test_expect_success 'setup nested submodule' ' | |
47 | git init sub1/nested && | |
48 | test_commit -C sub1/nested first_nested && | |
49 | git -C sub1 submodule add ./nested && | |
50 | test_tick && | |
51 | git -C sub1 commit -m "add nested" && | |
52 | git add sub1 && | |
53 | git commit -m "sub1 to include nested submodule" | |
54 | ' | |
55 | ||
56 | test_expect_success 'absorb the git dir in a nested submodule' ' | |
57 | git status >expect.1 && | |
58 | git -C sub1/nested rev-parse HEAD >expect.2 && | |
59 | git submodule absorbgitdirs && | |
60 | test -f sub1/nested/.git && | |
61 | test -d .git/modules/sub1/modules/nested && | |
62 | git status >actual.1 && | |
63 | git -C sub1/nested rev-parse HEAD >actual.2 && | |
64 | test_cmp expect.1 actual.1 && | |
65 | test_cmp expect.2 actual.2 | |
66 | ' | |
67 | ||
ec9629b3 SB |
68 | test_expect_success 're-setup nested submodule' ' |
69 | # un-absorb the direct submodule, to test if the nested submodule | |
70 | # is still correct (needs a rewrite of the gitfile only) | |
71 | rm -rf sub1/.git && | |
72 | mv .git/modules/sub1 sub1/.git && | |
73 | GIT_WORK_TREE=. git -C sub1 config --unset core.worktree && | |
74 | # fixup the nested submodule | |
75 | echo "gitdir: ../.git/modules/nested" >sub1/nested/.git && | |
76 | GIT_WORK_TREE=../../../nested git -C sub1/.git/modules/nested config \ | |
77 | core.worktree "../../../nested" && | |
78 | # make sure this re-setup is correct | |
98bf6674 SB |
79 | git status --ignore-submodules=none && |
80 | ||
81 | # also make sure this old setup does not regress | |
82 | git submodule update --init --recursive >out 2>err && | |
83 | test_must_be_empty out && | |
84 | test_must_be_empty err | |
ec9629b3 SB |
85 | ' |
86 | ||
87 | test_expect_success 'absorb the git dir in a nested submodule' ' | |
88 | git status >expect.1 && | |
89 | git -C sub1/nested rev-parse HEAD >expect.2 && | |
90 | git submodule absorbgitdirs && | |
91 | test -f sub1/.git && | |
92 | test -f sub1/nested/.git && | |
93 | test -d .git/modules/sub1/modules/nested && | |
94 | git status >actual.1 && | |
95 | git -C sub1/nested rev-parse HEAD >actual.2 && | |
96 | test_cmp expect.1 actual.1 && | |
97 | test_cmp expect.2 actual.2 | |
98 | ' | |
99 | ||
f6f85861 SB |
100 | test_expect_success 'setup a gitlink with missing .gitmodules entry' ' |
101 | git init sub2 && | |
102 | test_commit -C sub2 first && | |
103 | git add sub2 && | |
104 | git commit -m superproject | |
105 | ' | |
106 | ||
107 | test_expect_success 'absorbing the git dir fails for incomplete submodules' ' | |
108 | git status >expect.1 && | |
109 | git -C sub2 rev-parse HEAD >expect.2 && | |
110 | test_must_fail git submodule absorbgitdirs && | |
111 | git -C sub2 fsck && | |
112 | test -d sub2/.git && | |
113 | git status >actual && | |
114 | git -C sub2 rev-parse HEAD >actual.2 && | |
115 | test_cmp expect.1 actual.1 && | |
116 | test_cmp expect.2 actual.2 | |
117 | ' | |
118 | ||
119 | test_expect_success 'setup a submodule with multiple worktrees' ' | |
120 | # first create another unembedded git dir in a new submodule | |
121 | git init sub3 && | |
122 | test_commit -C sub3 first && | |
123 | git submodule add ./sub3 && | |
124 | test_tick && | |
125 | git commit -m "add another submodule" && | |
126 | git -C sub3 worktree add ../sub3_second_work_tree | |
127 | ' | |
128 | ||
129 | 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 | |
132 | ' | |
133 | ||
134 | test_done |