commit-graph: when incompatible with graphs, indicate why
[git] / t / t4027-diff-submodule.sh
1 #!/bin/sh
2
3 test_description='difference in submodules'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/diff-lib.sh
7
8 test_expect_success setup '
9         test_tick &&
10         test_create_repo sub &&
11         (
12                 cd sub &&
13                 echo hello >world &&
14                 git add world &&
15                 git commit -m submodule
16         ) &&
17
18         test_tick &&
19         echo frotz >nitfol &&
20         git add nitfol sub &&
21         git commit -m superproject &&
22
23         (
24                 cd sub &&
25                 echo goodbye >world &&
26                 git add world &&
27                 git commit -m "submodule #2"
28         ) &&
29
30         set x $(
31                 cd sub &&
32                 git rev-list HEAD
33         ) &&
34         echo ":160000 160000 $3 $ZERO_OID M     sub" >expect &&
35         subtip=$3 subprev=$2
36 '
37
38 test_expect_success 'git diff --raw HEAD' '
39         hexsz=$(test_oid hexsz) &&
40         git diff --raw --abbrev=$hexsz HEAD >actual &&
41         test_cmp expect actual
42 '
43
44 test_expect_success 'git diff-index --raw HEAD' '
45         git diff-index --raw HEAD >actual.index &&
46         test_cmp expect actual.index
47 '
48
49 test_expect_success 'git diff-files --raw' '
50         git diff-files --raw >actual.files &&
51         test_cmp expect actual.files
52 '
53
54 expect_from_to () {
55         printf "%sSubproject commit %s\n+Subproject commit %s\n" \
56                 "-" "$1" "$2"
57 }
58
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 '
65
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 '
73
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 '
86
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 '
99
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_must_be_empty 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_must_be_empty actual4
115 '
116
117 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
118         git config diff.ignoreSubmodules dirty &&
119         git diff HEAD >actual &&
120         test_must_be_empty actual &&
121         git config --add -f .gitmodules submodule.subname.ignore none &&
122         git config --add -f .gitmodules submodule.subname.path sub &&
123         git diff HEAD >actual &&
124         sed -e "1,/^@@/d" actual >actual.body &&
125         expect_from_to >expect.body $subprev $subprev-dirty &&
126         test_cmp expect.body actual.body &&
127         git config -f .gitmodules submodule.subname.ignore all &&
128         git config -f .gitmodules submodule.subname.path sub &&
129         git diff HEAD >actual2 &&
130         test_must_be_empty actual2 &&
131         git config -f .gitmodules submodule.subname.ignore untracked &&
132         git diff HEAD >actual3 &&
133         sed -e "1,/^@@/d" actual3 >actual3.body &&
134         expect_from_to >expect.body $subprev $subprev-dirty &&
135         test_cmp expect.body actual3.body &&
136         git config -f .gitmodules submodule.subname.ignore dirty &&
137         git diff HEAD >actual4 &&
138         test_must_be_empty actual4 &&
139         git config submodule.subname.ignore none &&
140         git config submodule.subname.path sub &&
141         git diff HEAD >actual &&
142         sed -e "1,/^@@/d" actual >actual.body &&
143         expect_from_to >expect.body $subprev $subprev-dirty &&
144         test_cmp expect.body actual.body &&
145         git config --remove-section submodule.subname &&
146         git config --remove-section -f .gitmodules submodule.subname &&
147         git config --unset diff.ignoreSubmodules &&
148         rm .gitmodules
149 '
150
151 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
152         (
153                 cd sub &&
154                 git reset --hard &&
155                 echo >>world &&
156                 git add world
157         ) &&
158         git diff HEAD >actual &&
159         sed -e "1,/^@@/d" actual >actual.body &&
160         expect_from_to >expect.body $subprev $subprev-dirty &&
161         test_cmp expect.body actual.body
162 '
163
164 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
165         (
166                 cd sub &&
167                 git reset --hard &&
168                 git clean -qfdx &&
169                 >cruft
170         ) &&
171         git diff HEAD >actual &&
172         sed -e "1,/^@@/d" actual >actual.body &&
173         expect_from_to >expect.body $subprev $subprev-dirty &&
174         test_cmp expect.body actual.body &&
175         git diff --ignore-submodules=all HEAD >actual2 &&
176         test_must_be_empty actual2 &&
177         git diff --ignore-submodules=untracked HEAD >actual3 &&
178         test_must_be_empty actual3 &&
179         git diff --ignore-submodules=dirty HEAD >actual4 &&
180         test_must_be_empty actual4
181 '
182
183 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
184         git config --add -f .gitmodules submodule.subname.ignore all &&
185         git config --add -f .gitmodules submodule.subname.path sub &&
186         git diff HEAD >actual2 &&
187         test_must_be_empty actual2 &&
188         git config -f .gitmodules submodule.subname.ignore untracked &&
189         git diff HEAD >actual3 &&
190         test_must_be_empty actual3 &&
191         git config -f .gitmodules submodule.subname.ignore dirty &&
192         git diff HEAD >actual4 &&
193         test_must_be_empty actual4 &&
194         git config submodule.subname.ignore none &&
195         git config submodule.subname.path sub &&
196         git diff HEAD >actual &&
197         sed -e "1,/^@@/d" actual >actual.body &&
198         expect_from_to >expect.body $subprev $subprev-dirty &&
199         test_cmp expect.body actual.body &&
200         git config --remove-section submodule.subname &&
201         git config --remove-section -f .gitmodules submodule.subname &&
202         rm .gitmodules
203 '
204
205 test_expect_success 'git diff between submodule commits' '
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 diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
211         sed -e "1,/^@@/d" actual >actual.body &&
212         expect_from_to >expect.body $subtip $subprev &&
213         test_cmp expect.body actual.body &&
214         git diff --ignore-submodules HEAD^..HEAD >actual &&
215         test_must_be_empty actual
216 '
217
218 test_expect_success 'git diff between submodule commits [.gitmodules]' '
219         git diff HEAD^..HEAD >actual &&
220         sed -e "1,/^@@/d" actual >actual.body &&
221         expect_from_to >expect.body $subtip $subprev &&
222         test_cmp expect.body actual.body &&
223         git config --add -f .gitmodules submodule.subname.ignore dirty &&
224         git config --add -f .gitmodules submodule.subname.path sub &&
225         git diff HEAD^..HEAD >actual &&
226         sed -e "1,/^@@/d" actual >actual.body &&
227         expect_from_to >expect.body $subtip $subprev &&
228         test_cmp expect.body actual.body &&
229         git config -f .gitmodules submodule.subname.ignore all &&
230         git diff HEAD^..HEAD >actual &&
231         test_must_be_empty actual &&
232         git config submodule.subname.ignore dirty &&
233         git config submodule.subname.path sub &&
234         git diff  HEAD^..HEAD >actual &&
235         sed -e "1,/^@@/d" actual >actual.body &&
236         expect_from_to >expect.body $subtip $subprev &&
237         git config --remove-section submodule.subname &&
238         git config --remove-section -f .gitmodules submodule.subname &&
239         rm .gitmodules
240 '
241
242 test_expect_success 'git diff (empty submodule dir)' '
243         rm -rf sub/* sub/.git &&
244         git diff > actual.empty &&
245         test_must_be_empty actual.empty
246 '
247
248 test_expect_success 'conflicted submodule setup' '
249         c=$(test_oid ff_1) &&
250         (
251                 echo "000000 $ZERO_OID 0        sub" &&
252                 echo "160000 1$c 1      sub" &&
253                 echo "160000 2$c 2      sub" &&
254                 echo "160000 3$c 3      sub"
255         ) | git update-index --index-info &&
256         echo >expect.nosub "diff --cc sub
257 index 2ffffff,3ffffff..0000000
258 --- a/sub
259 +++ b/sub
260 @@@ -1,1 -1,1 +1,1 @@@
261 - Subproject commit 2$c
262  -Subproject commit 3$c
263 ++Subproject commit $ZERO_OID" &&
264
265         hh=$(git rev-parse HEAD) &&
266         sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
267
268 '
269
270 test_expect_success 'combined (empty submodule)' '
271         rm -fr sub && mkdir sub &&
272         git diff >actual &&
273         test_cmp expect.nosub actual
274 '
275
276 test_expect_success 'combined (with submodule)' '
277         rm -fr sub &&
278         git clone --no-checkout . sub &&
279         git diff >actual &&
280         test_cmp expect.withsub actual
281 '
282
283
284
285 test_done