3 test_description
='Test submodule absorbgitdirs
5 This test verifies that `git submodue absorbgitdirs` moves a submodules git
6 directory into the superproject.
9 TEST_PASSES_SANITIZE_LEAK
=true
12 test_expect_success
'setup a real submodule' '
14 test_commit -C sub1 first &&
15 git submodule add ./sub1 &&
17 git commit -m superproject
20 test_expect_success
'absorb the git dir' '
25 git status >expect.1 &&
26 git -C sub1 rev-parse HEAD >expect.2 &&
27 git submodule absorbgitdirs &&
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
37 test_expect_success
'absorbing does not fail for deinitialized submodules' '
38 test_when_finished "git submodule update --init" &&
39 git submodule deinit --all &&
40 git submodule absorbgitdirs &&
41 test -d .git/modules/sub1 &&
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 &&
51 git -C sub1 commit -m "add nested" &&
53 git commit -m "sub1 to include nested submodule"
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
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)
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
79 git status --ignore-submodules=none &&
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
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 &&
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
100 test_expect_success
'setup a gitlink with missing .gitmodules entry' '
102 test_commit -C sub2 first &&
104 git commit -m superproject
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 &&
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
119 test_expect_success
'setup a submodule with multiple worktrees' '
120 # first create another unembedded git dir in a new submodule
122 test_commit -C sub3 first &&
123 git submodule add ./sub3 &&
125 git commit -m "add another submodule" &&
126 git -C sub3 worktree add ../sub3_second_work_tree
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