Submodules: Add the new "ignore" config option for diff and status
[git/git.git] / t / t4027-diff-submodule.sh
CommitLineData
2b459b48
JH
1#!/bin/sh
2
3test_description='difference in submodules'
4
5. ./test-lib.sh
bfdbee98 6. "$TEST_DIRECTORY"/diff-lib.sh
2b459b48
JH
7
8_z40=0000000000000000000000000000000000000000
9test_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 ) &&
18
19 test_tick &&
20 echo frotz >nitfol &&
21 git add nitfol sub &&
22 git commit -m superproject &&
23
24 (
25 cd sub &&
26 echo goodbye >world &&
27 git add world &&
28 git commit -m "submodule #2"
29 ) &&
30
31 set x $(
32 cd sub &&
33 git rev-list HEAD
34 ) &&
8e08b419
JH
35 echo ":160000 160000 $3 $_z40 M sub" >expect &&
36 subtip=$3 subprev=$2
2b459b48
JH
37'
38
39test_expect_success 'git diff --raw HEAD' '
40 git diff --raw --abbrev=40 HEAD >actual &&
82ebb0b6 41 test_cmp expect actual
2b459b48
JH
42'
43
44test_expect_success 'git diff-index --raw HEAD' '
45 git diff-index --raw HEAD >actual.index &&
82ebb0b6 46 test_cmp expect actual.index
2b459b48
JH
47'
48
49test_expect_success 'git diff-files --raw' '
50 git diff-files --raw >actual.files &&
82ebb0b6 51 test_cmp expect actual.files
2b459b48
JH
52'
53
8e08b419
JH
54expect_from_to () {
55 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
56 "-" "$1" "$2"
57}
58
59test_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
66test_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
74test_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
87test_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
100test_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 &&
dd44d419
JL
106 test_cmp expect.body actual.body &&
107 git diff --ignore-submodules HEAD >actual2 &&
6ed7ddaa 108 ! test -s actual2 &&
dd44d419
JL
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 &&
6ed7ddaa 114 ! test -s actual4
8e08b419 115'
6ed7ddaa 116
aee9c7d6
JL
117test_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'
141
8e08b419
JH
142test_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'
154
155test_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 &&
dd44d419
JL
165 test_cmp expect.body actual.body &&
166 git diff --ignore-submodules=all HEAD >actual2 &&
6ed7ddaa 167 ! test -s actual2 &&
dd44d419 168 git diff --ignore-submodules=untracked HEAD >actual3 &&
6ed7ddaa 169 ! test -s actual3 &&
dd44d419 170 git diff --ignore-submodules=dirty HEAD >actual4 &&
6ed7ddaa 171 ! test -s actual4
8e08b419
JH
172'
173
aee9c7d6
JL
174test_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'
191
192test_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'
204
205test_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'
224
1392a377 225test_expect_success 'git diff (empty submodule dir)' '
7c08a2a6
PY
226 : >empty &&
227 rm -rf sub/* sub/.git &&
228 git diff > actual.empty &&
229 test_cmp empty actual.empty
230'
231
7dae8b21
JH
232test_expect_success 'conflicted submodule setup' '
233
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
243index 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'\'' &&
250
251 hh=$(git rev-parse HEAD) &&
252 sed -e "s/$_z40/$hh/" expect.nosub >expect.withsub
253
254'
255
256test_expect_success 'combined (empty submodule)' '
257 rm -fr sub && mkdir sub &&
258 git diff >actual &&
259 test_cmp expect.nosub actual
260'
261
262test_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'
268
269
270
2b459b48 271test_done