8e2449d24409bab14558f83617f651c3f7255627
[git/git.git] / t / t7406-submodule-update.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 Red Hat, Inc.
4 #
5
6 test_description='Test updating submodules
7
8 This test verifies that "git submodule update" detaches the HEAD of the
9 submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
10 '
11
12 . ./test-lib.sh
13
14
15 compare_head()
16 {
17 sha_master=`git rev-list --max-count=1 master`
18 sha_head=`git rev-list --max-count=1 HEAD`
19
20 test "$sha_master" = "$sha_head"
21 }
22
23
24 test_expect_success 'setup a submodule tree' '
25 echo file > file &&
26 git add file &&
27 test_tick &&
28 git commit -m upstream
29 git clone . super &&
30 git clone super submodule &&
31 (cd super &&
32 git submodule add ../submodule submodule &&
33 test_tick &&
34 git commit -m "submodule" &&
35 git submodule init submodule
36 ) &&
37 (cd submodule &&
38 echo "line2" > file &&
39 git add file &&
40 git commit -m "Commit 2"
41 ) &&
42 (cd super &&
43 (cd submodule &&
44 git pull --rebase origin
45 ) &&
46 git add submodule &&
47 git commit -m "submodule update"
48 )
49 '
50
51 test_expect_success 'submodule update detaching the HEAD ' '
52 (cd super/submodule &&
53 git reset --hard HEAD~1
54 ) &&
55 (cd super &&
56 (cd submodule &&
57 compare_head
58 ) &&
59 git submodule update submodule &&
60 cd submodule &&
61 ! compare_head
62 )
63 '
64
65 test_expect_success 'submodule update --rebase staying on master' '
66 (cd super/submodule &&
67 git checkout master
68 ) &&
69 (cd super &&
70 (cd submodule &&
71 compare_head
72 ) &&
73 git submodule update --rebase submodule &&
74 cd submodule &&
75 compare_head
76 )
77 '
78
79 test_expect_success 'submodule update --merge staying on master' '
80 (cd super/submodule &&
81 git reset --hard HEAD~1
82 ) &&
83 (cd super &&
84 (cd submodule &&
85 compare_head
86 ) &&
87 git submodule update --merge submodule &&
88 cd submodule &&
89 compare_head
90 )
91 '
92
93 test_expect_success 'submodule update - rebase in .git/config' '
94 (cd super &&
95 git config submodule.submodule.update rebase
96 ) &&
97 (cd super/submodule &&
98 git reset --hard HEAD~1
99 ) &&
100 (cd super &&
101 (cd submodule &&
102 compare_head
103 ) &&
104 git submodule update submodule &&
105 cd submodule &&
106 compare_head
107 )
108 '
109
110 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
111 (cd super &&
112 git config submodule.submodule.update checkout
113 ) &&
114 (cd super/submodule &&
115 git reset --hard HEAD~1
116 ) &&
117 (cd super &&
118 (cd submodule &&
119 compare_head
120 ) &&
121 git submodule update --rebase submodule &&
122 cd submodule &&
123 compare_head
124 )
125 '
126
127 test_expect_success 'submodule update - merge in .git/config' '
128 (cd super &&
129 git config submodule.submodule.update merge
130 ) &&
131 (cd super/submodule &&
132 git reset --hard HEAD~1
133 ) &&
134 (cd super &&
135 (cd submodule &&
136 compare_head
137 ) &&
138 git submodule update submodule &&
139 cd submodule &&
140 compare_head
141 )
142 '
143
144 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
145 (cd super &&
146 git config submodule.submodule.update checkout
147 ) &&
148 (cd super/submodule &&
149 git reset --hard HEAD~1
150 ) &&
151 (cd super &&
152 (cd submodule &&
153 compare_head
154 ) &&
155 git submodule update --merge submodule &&
156 cd submodule &&
157 compare_head
158 )
159 '
160
161 test_expect_success 'submodule update - checkout in .git/config' '
162 (cd super &&
163 git config submodule.submodule.update checkout
164 ) &&
165 (cd super/submodule &&
166 git reset --hard HEAD^
167 ) &&
168 (cd super &&
169 (cd submodule &&
170 compare_head
171 ) &&
172 git submodule update submodule &&
173 cd submodule &&
174 ! compare_head
175 )
176 '
177
178 test_expect_success 'submodule init picks up rebase' '
179 (cd super &&
180 git config submodule.rebasing.url git://non-existing/git &&
181 git config submodule.rebasing.path does-not-matter &&
182 git config submodule.rebasing.update rebase &&
183 git submodule init rebasing &&
184 test "rebase" = $(git config submodule.rebasing.update)
185 )
186 '
187
188 test_expect_success 'submodule init picks up merge' '
189 (cd super &&
190 git config submodule.merging.url git://non-existing/git &&
191 git config submodule.merging.path does-not-matter &&
192 git config submodule.merging.update merge &&
193 git submodule init merging &&
194 test "merge" = $(git config submodule.merging.update)
195 )
196 '
197
198 test_done