Skip to content

Commit 86140d5

Browse files
jlehmanngitster
authored andcommitted
add tests for git diff --submodule
Copied from the submodule summary test and changed to reflect the differences in the output of git diff --submodule. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 752c0c2 commit 86140d5

File tree

1 file changed

+260
-0
lines changed

1 file changed

+260
-0
lines changed

t/t4041-diff-submodule.sh

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
4+
#
5+
6+
test_description='Support for verbose submodule differences in git diff
7+
8+
This test tries to verify the sanity of the --submodule option of git diff.
9+
'
10+
11+
. ./test-lib.sh
12+
13+
add_file () {
14+
sm=$1
15+
shift
16+
owd=$(pwd)
17+
cd "$sm"
18+
for name; do
19+
echo "$name" > "$name" &&
20+
git add "$name" &&
21+
test_tick &&
22+
git commit -m "Add $name"
23+
done >/dev/null
24+
git rev-parse --verify HEAD | cut -c1-7
25+
cd "$owd"
26+
}
27+
commit_file () {
28+
test_tick &&
29+
git commit "$@" -m "Commit $*" >/dev/null
30+
}
31+
32+
test_create_repo sm1 &&
33+
add_file . foo >/dev/null
34+
35+
head1=$(add_file sm1 foo1 foo2)
36+
37+
test_expect_success 'added submodule' "
38+
git add sm1 &&
39+
git diff-index -p --submodule=log HEAD >actual &&
40+
diff actual - <<-EOF
41+
Submodule sm1 0000000...$head1 (new submodule)
42+
EOF
43+
"
44+
45+
commit_file sm1 &&
46+
head2=$(add_file sm1 foo3)
47+
48+
test_expect_success 'modified submodule(forward)' "
49+
git diff-index -p --submodule=log HEAD >actual &&
50+
diff actual - <<-EOF
51+
Submodule sm1 $head1..$head2:
52+
> Add foo3
53+
EOF
54+
"
55+
56+
test_expect_success 'modified submodule(forward)' "
57+
git diff --submodule=log >actual &&
58+
diff actual - <<-EOF
59+
Submodule sm1 $head1..$head2:
60+
> Add foo3
61+
EOF
62+
"
63+
64+
test_expect_success 'modified submodule(forward) --submodule' "
65+
git diff --submodule >actual &&
66+
diff actual - <<-EOF
67+
Submodule sm1 $head1..$head2:
68+
> Add foo3
69+
EOF
70+
"
71+
72+
fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
73+
fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
74+
test_expect_success 'modified submodule(forward) --submodule=short' "
75+
git diff --submodule=short >actual &&
76+
diff actual - <<-EOF
77+
diff --git a/sm1 b/sm1
78+
index $head1..$head2 160000
79+
--- a/sm1
80+
+++ b/sm1
81+
@@ -1 +1 @@
82+
-Subproject commit $fullhead1
83+
+Subproject commit $fullhead2
84+
EOF
85+
"
86+
87+
commit_file sm1 &&
88+
cd sm1 &&
89+
git reset --hard HEAD~2 >/dev/null &&
90+
head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
91+
cd ..
92+
93+
test_expect_success 'modified submodule(backward)' "
94+
git diff-index -p --submodule=log HEAD >actual &&
95+
diff actual - <<-EOF
96+
Submodule sm1 $head2..$head3 (rewind):
97+
< Add foo3
98+
< Add foo2
99+
EOF
100+
"
101+
102+
head4=$(add_file sm1 foo4 foo5) &&
103+
head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
104+
test_expect_success 'modified submodule(backward and forward)' "
105+
git diff-index -p --submodule=log HEAD >actual &&
106+
diff actual - <<-EOF
107+
Submodule sm1 $head2...$head4:
108+
> Add foo5
109+
> Add foo4
110+
< Add foo3
111+
< Add foo2
112+
EOF
113+
"
114+
115+
commit_file sm1 &&
116+
mv sm1 sm1-bak &&
117+
echo sm1 >sm1 &&
118+
head5=$(git hash-object sm1 | cut -c1-7) &&
119+
git add sm1 &&
120+
rm -f sm1 &&
121+
mv sm1-bak sm1
122+
123+
test_expect_success 'typechanged submodule(submodule->blob), --cached' "
124+
git diff --submodule=log --cached >actual &&
125+
diff actual - <<-EOF
126+
Submodule sm1 41fbea9...0000000 (submodule deleted)
127+
diff --git a/sm1 b/sm1
128+
new file mode 100644
129+
index 0000000..9da5fb8
130+
--- /dev/null
131+
+++ b/sm1
132+
@@ -0,0 +1 @@
133+
+sm1
134+
EOF
135+
"
136+
137+
test_expect_success 'typechanged submodule(submodule->blob)' "
138+
git diff --submodule=log >actual &&
139+
diff actual - <<-EOF
140+
diff --git a/sm1 b/sm1
141+
deleted file mode 100644
142+
index 9da5fb8..0000000
143+
--- a/sm1
144+
+++ /dev/null
145+
@@ -1 +0,0 @@
146+
-sm1
147+
Submodule sm1 0000000...$head4 (new submodule)
148+
EOF
149+
"
150+
151+
rm -rf sm1 &&
152+
git checkout-index sm1
153+
test_expect_success 'typechanged submodule(submodule->blob)' "
154+
git diff-index -p --submodule=log HEAD >actual &&
155+
diff actual - <<-EOF
156+
Submodule sm1 $head4...0000000 (submodule deleted)
157+
diff --git a/sm1 b/sm1
158+
new file mode 100644
159+
index 0000000..$head5
160+
--- /dev/null
161+
+++ b/sm1
162+
@@ -0,0 +1 @@
163+
+sm1
164+
EOF
165+
"
166+
167+
rm -f sm1 &&
168+
test_create_repo sm1 &&
169+
head6=$(add_file sm1 foo6 foo7)
170+
fullhead6=$(cd sm1; git rev-list --max-count=1 $head6)
171+
test_expect_success 'nonexistent commit' "
172+
git diff-index -p --submodule=log HEAD >actual &&
173+
diff actual - <<-EOF
174+
Submodule sm1 $head4...$head6 (commits not present)
175+
EOF
176+
"
177+
178+
commit_file
179+
test_expect_success 'typechanged submodule(blob->submodule)' "
180+
git diff-index -p --submodule=log HEAD >actual &&
181+
diff actual - <<-EOF
182+
diff --git a/sm1 b/sm1
183+
deleted file mode 100644
184+
index $head5..0000000
185+
--- a/sm1
186+
+++ /dev/null
187+
@@ -1 +0,0 @@
188+
-sm1
189+
Submodule sm1 0000000...$head6 (new submodule)
190+
EOF
191+
"
192+
193+
commit_file sm1 &&
194+
rm -rf sm1
195+
test_expect_success 'deleted submodule' "
196+
git diff-index -p --submodule=log HEAD >actual &&
197+
diff actual - <<-EOF
198+
Submodule sm1 $head6...0000000 (submodule deleted)
199+
EOF
200+
"
201+
202+
test_create_repo sm2 &&
203+
head7=$(add_file sm2 foo8 foo9) &&
204+
git add sm2
205+
206+
test_expect_success 'multiple submodules' "
207+
git diff-index -p --submodule=log HEAD >actual &&
208+
diff actual - <<-EOF
209+
Submodule sm1 $head6...0000000 (submodule deleted)
210+
Submodule sm2 0000000...$head7 (new submodule)
211+
EOF
212+
"
213+
214+
test_expect_success 'path filter' "
215+
git diff-index -p --submodule=log HEAD sm2 >actual &&
216+
diff actual - <<-EOF
217+
Submodule sm2 0000000...$head7 (new submodule)
218+
EOF
219+
"
220+
221+
commit_file sm2
222+
test_expect_success 'given commit' "
223+
git diff-index -p --submodule=log HEAD^ >actual &&
224+
diff actual - <<-EOF
225+
Submodule sm1 $head6...0000000 (submodule deleted)
226+
Submodule sm2 0000000...$head7 (new submodule)
227+
EOF
228+
"
229+
230+
test_expect_success 'given commit --submodule' "
231+
git diff-index -p --submodule HEAD^ >actual &&
232+
diff actual - <<-EOF
233+
Submodule sm1 $head6...0000000 (submodule deleted)
234+
Submodule sm2 0000000...$head7 (new submodule)
235+
EOF
236+
"
237+
238+
fullhead7=$(cd sm2; git rev-list --max-count=1 $head7)
239+
240+
test_expect_success 'given commit --submodule=short' "
241+
git diff-index -p --submodule=short HEAD^ >actual &&
242+
diff actual - <<-EOF
243+
diff --git a/sm1 b/sm1
244+
deleted file mode 160000
245+
index $head6..0000000
246+
--- a/sm1
247+
+++ /dev/null
248+
@@ -1 +0,0 @@
249+
-Subproject commit $fullhead6
250+
diff --git a/sm2 b/sm2
251+
new file mode 160000
252+
index 0000000..$head7
253+
--- /dev/null
254+
+++ b/sm2
255+
@@ -0,0 +1 @@
256+
+Subproject commit $fullhead7
257+
EOF
258+
"
259+
260+
test_done

0 commit comments

Comments
 (0)