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