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