68367285173d3579c79bcb378b91354564ba8637
1 #!/bin/sh
3 test_description='difference in submodules'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/diff-lib.sh
8 _z40=0000000000000000000000000000000000000000
9 test_expect_success setup '
10 test_tick &&
11 test_create_repo sub &&
12 (
13 cd sub &&
14 echo hello >world &&
15 git add world &&
16 git commit -m submodule
17 ) &&
19 test_tick &&
20 echo frotz >nitfol &&
21 git add nitfol sub &&
22 git commit -m superproject &&
24 (
25 cd sub &&
26 echo goodbye >world &&
27 git add world &&
28 git commit -m "submodule #2"
29 ) &&
31 set x $(
32 cd sub &&
33 git rev-list HEAD
34 ) &&
35 echo ":160000 160000 $3 $_z40 M sub" >expect &&
36 subtip=$3 subprev=$2
37 '
39 test_expect_success 'git diff --raw HEAD' '
40 git diff --raw --abbrev=40 HEAD >actual &&
41 test_cmp expect actual
42 '
44 test_expect_success 'git diff-index --raw HEAD' '
45 git diff-index --raw HEAD >actual.index &&
46 test_cmp expect actual.index
47 '
49 test_expect_success 'git diff-files --raw' '
50 git diff-files --raw >actual.files &&
51 test_cmp expect actual.files
52 '
54 expect_from_to () {
55 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
56 "-" "$1" "$2"
57 }
59 test_expect_success 'git diff HEAD' '
60 git diff HEAD >actual &&
61 sed -e "1,/^@@/d" actual >actual.body &&
62 expect_from_to >expect.body $subtip $subprev &&
63 test_cmp expect.body actual.body
64 '
66 test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
67 echo >>sub/world &&
68 git diff HEAD >actual &&
69 sed -e "1,/^@@/d" actual >actual.body &&
70 expect_from_to >expect.body $subtip $subprev-dirty &&
71 test_cmp expect.body actual.body
72 '
74 test_expect_success 'git diff HEAD with dirty submodule (index)' '
75 (
76 cd sub &&
77 git reset --hard &&
78 echo >>world &&
79 git add world
80 ) &&
81 git diff HEAD >actual &&
82 sed -e "1,/^@@/d" actual >actual.body &&
83 expect_from_to >expect.body $subtip $subprev-dirty &&
84 test_cmp expect.body actual.body
85 '
87 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
88 (
89 cd sub &&
90 git reset --hard &&
91 git clean -qfdx &&
92 >cruft
93 ) &&
94 git diff HEAD >actual &&
95 sed -e "1,/^@@/d" actual >actual.body &&
96 expect_from_to >expect.body $subtip $subprev-dirty &&
97 test_cmp expect.body actual.body
98 '
100 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
101 git commit -m "x" sub &&
102 echo >>sub/world &&
103 git diff HEAD >actual &&
104 sed -e "1,/^@@/d" actual >actual.body &&
105 expect_from_to >expect.body $subprev $subprev-dirty &&
106 test_cmp expect.body actual.body &&
107 git diff --ignore-submodules HEAD >actual2 &&
108 ! test -s actual2 &&
109 git diff --ignore-submodules=untracked HEAD >actual3 &&
110 sed -e "1,/^@@/d" actual3 >actual3.body &&
111 expect_from_to >expect.body $subprev $subprev-dirty &&
112 test_cmp expect.body actual3.body &&
113 git diff --ignore-submodules=dirty HEAD >actual4 &&
114 ! test -s actual4
115 '
117 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.git/config]' '
118 git config submodule.subname.ignore none &&
119 git config submodule.subname.path sub &&
120 git diff HEAD >actual &&
121 sed -e "1,/^@@/d" actual >actual.body &&
122 expect_from_to >expect.body $subprev $subprev-dirty &&
123 test_cmp expect.body actual.body &&
124 git config submodule.subname.ignore all &&
125 git diff HEAD >actual2 &&
126 ! test -s actual2 &&
127 git config submodule.subname.ignore untracked &&
128 git diff HEAD >actual3 &&
129 sed -e "1,/^@@/d" actual3 >actual3.body &&
130 expect_from_to >expect.body $subprev $subprev-dirty &&
131 test_cmp expect.body actual3.body &&
132 git config submodule.subname.ignore dirty &&
133 git diff HEAD >actual4 &&
134 ! test -s actual4 &&
135 git diff HEAD --ignore-submodules=none >actual &&
136 sed -e "1,/^@@/d" actual >actual.body &&
137 expect_from_to >expect.body $subprev $subprev-dirty &&
138 test_cmp expect.body actual.body &&
139 git config --remove-section submodule.subname
140 '
142 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
143 (
144 cd sub &&
145 git reset --hard &&
146 echo >>world &&
147 git add world
148 ) &&
149 git diff HEAD >actual &&
150 sed -e "1,/^@@/d" actual >actual.body &&
151 expect_from_to >expect.body $subprev $subprev-dirty &&
152 test_cmp expect.body actual.body
153 '
155 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
156 (
157 cd sub &&
158 git reset --hard &&
159 git clean -qfdx &&
160 >cruft
161 ) &&
162 git diff HEAD >actual &&
163 sed -e "1,/^@@/d" actual >actual.body &&
164 expect_from_to >expect.body $subprev $subprev-dirty &&
165 test_cmp expect.body actual.body &&
166 git diff --ignore-submodules=all HEAD >actual2 &&
167 ! test -s actual2 &&
168 git diff --ignore-submodules=untracked HEAD >actual3 &&
169 ! test -s actual3 &&
170 git diff --ignore-submodules=dirty HEAD >actual4 &&
171 ! test -s actual4
172 '
174 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.git/config]' '
175 git config submodule.subname.ignore all &&
176 git config submodule.subname.path sub &&
177 git diff HEAD >actual2 &&
178 ! test -s actual2 &&
179 git config submodule.subname.ignore untracked &&
180 git diff HEAD >actual3 &&
181 ! test -s actual3 &&
182 git config submodule.subname.ignore dirty &&
183 git diff HEAD >actual4 &&
184 ! test -s actual4 &&
185 git diff --ignore-submodules=none HEAD >actual &&
186 sed -e "1,/^@@/d" actual >actual.body &&
187 expect_from_to >expect.body $subprev $subprev-dirty &&
188 test_cmp expect.body actual.body &&
189 git config --remove-section submodule.subname
190 '
192 test_expect_success 'git diff between submodule commits' '
193 git diff HEAD^..HEAD >actual &&
194 sed -e "1,/^@@/d" actual >actual.body &&
195 expect_from_to >expect.body $subtip $subprev &&
196 test_cmp expect.body actual.body &&
197 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
198 sed -e "1,/^@@/d" actual >actual.body &&
199 expect_from_to >expect.body $subtip $subprev &&
200 test_cmp expect.body actual.body &&
201 git diff --ignore-submodules HEAD^..HEAD >actual &&
202 ! test -s actual
203 '
205 test_expect_success 'git diff between submodule commits [.git/config]' '
206 git diff HEAD^..HEAD >actual &&
207 sed -e "1,/^@@/d" actual >actual.body &&
208 expect_from_to >expect.body $subtip $subprev &&
209 test_cmp expect.body actual.body &&
210 git config submodule.subname.ignore dirty &&
211 git config submodule.subname.path sub &&
212 git diff HEAD^..HEAD >actual &&
213 sed -e "1,/^@@/d" actual >actual.body &&
214 expect_from_to >expect.body $subtip $subprev &&
215 test_cmp expect.body actual.body &&
216 git config submodule.subname.ignore all &&
217 git diff HEAD^..HEAD >actual &&
218 ! test -s actual &&
219 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
220 sed -e "1,/^@@/d" actual >actual.body &&
221 expect_from_to >expect.body $subtip $subprev &&
222 git config --remove-section submodule.subname
223 '
225 test_expect_success 'git diff (empty submodule dir)' '
226 : >empty &&
227 rm -rf sub/* sub/.git &&
228 git diff > actual.empty &&
229 test_cmp empty actual.empty
230 '
232 test_expect_success 'conflicted submodule setup' '
234 # 39 efs
235 c=fffffffffffffffffffffffffffffffffffffff
236 (
237 echo "000000 $_z40 0 sub"
238 echo "160000 1$c 1 sub"
239 echo "160000 2$c 2 sub"
240 echo "160000 3$c 3 sub"
241 ) | git update-index --index-info &&
242 echo >expect.nosub '\''diff --cc sub
243 index 2ffffff,3ffffff..0000000
244 --- a/sub
245 +++ b/sub
246 @@@ -1,1 -1,1 +1,1 @@@
247 - Subproject commit 2fffffffffffffffffffffffffffffffffffffff
248 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
249 ++Subproject commit 0000000000000000000000000000000000000000'\'' &&
251 hh=$(git rev-parse HEAD) &&
252 sed -e "s/$_z40/$hh/" expect.nosub >expect.withsub
254 '
256 test_expect_success 'combined (empty submodule)' '
257 rm -fr sub && mkdir sub &&
258 git diff >actual &&
259 test_cmp expect.nosub actual
260 '
262 test_expect_success 'combined (with submodule)' '
263 rm -fr sub &&
264 git clone --no-checkout . sub &&
265 git diff >actual &&
266 test_cmp expect.withsub actual
267 '
271 test_done