3 test_description='Test submodule absorbgitdirs
5 This test verifies that `git submodue absorbgitdirs` moves a submodules git
6 directory into the superproject.
11 test_expect_success 'setup a real submodule' '
13 test_commit -C sub1 first &&
14 git submodule add ./sub1 &&
16 git commit -m superproject
19 test_expect_success 'absorb the git dir' '
24 git status >expect.1 &&
25 git -C sub1 rev-parse HEAD >expect.2 &&
26 git submodule absorbgitdirs &&
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 &&
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 &&
40 test_cmp expect actual
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 &&
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 &&
57 git -C sub1 commit -m "add nested" &&
59 git commit -m "sub1 to include nested submodule"
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
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)
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 &&
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
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 &&
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
106 test_expect_success 'setup a gitlink with missing .gitmodules entry' '
108 test_commit -C sub2 first &&
110 git commit -m superproject
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 &&
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
125 test_expect_success 'setup a submodule with multiple worktrees' '
126 # first create another unembedded git dir in a new submodule
128 test_commit -C sub3 first &&
129 git submodule add ./sub3 &&
131 git commit -m "add another submodule" &&
132 git -C sub3 worktree add ../sub3_second_work_tree
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