git-submodule summary: test
Signed-off-by: Ping Yin <pkufranky@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ping Yin committed
Mar 11, 2008 at 21:52 UTC
2da2ddc664538f64c4d8a4ab61ef93b2b77a50d5
1 file changed
+195
t/t7401-submodule-summary.sh
new
+195
@@ -0,0 +1,195 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2008 Ping Yin
4
+#
5
+
6
+test_description='Summary support for submodules
7
+
8
+This test tries to verify the sanity of summary subcommand of git-submodule.
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
34
+
35
+head1=$(add_file sm1 foo1 foo2)
36
+
37
+test_expect_success 'added submodule' "
38
+ git add sm1 &&
39
+ git submodule summary >actual &&
40
+ diff actual - <<-EOF
41
+* sm1 0000000...$head1 (2):
42
+ > Add foo2
43
+
44
+EOF
45
+"
46
+
47
+commit_file sm1 &&
48
+head2=$(add_file sm1 foo3)
49
+
50
+test_expect_success 'modified submodule(forward)' "
51
+ git submodule summary >actual &&
52
+ diff actual - <<-EOF
53
+* sm1 $head1...$head2 (1):
54
+ > Add foo3
55
+
56
+EOF
57
+"
58
+
59
+commit_file sm1 &&
60
+cd sm1 &&
61
+git reset --hard HEAD~2 >/dev/null &&
62
+head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
63
+cd ..
64
+
65
+test_expect_success 'modified submodule(backward)' "
66
+ git submodule summary >actual &&
67
+ diff actual - <<-EOF
68
+* sm1 $head2...$head3 (2):
69
+ < Add foo3
70
+ < Add foo2
71
+
72
+EOF
73
+"
74
+
75
+head4=$(add_file sm1 foo4 foo5) &&
76
+head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
77
+test_expect_success 'modified submodule(backward and forward)' "
78
+ git submodule summary >actual &&
79
+ diff actual - <<-EOF
80
+* sm1 $head2...$head4 (4):
81
+ > Add foo5
82
+ > Add foo4
83
+ < Add foo3
84
+ < Add foo2
85
+
86
+EOF
87
+"
88
+
89
+test_expect_success '--summary-limit' "
90
+ git submodule summary -n 3 >actual &&
91
+ diff actual - <<-EOF
92
+* sm1 $head2...$head4 (4):
93
+ > Add foo5
94
+ > Add foo4
95
+ < Add foo3
96
+
97
+EOF
98
+"
99
+
100
+commit_file sm1 &&
101
+mv sm1 sm1-bak &&
102
+echo sm1 >sm1 &&
103
+head5=$(git hash-object sm1 | cut -c1-7) &&
104
+git add sm1 &&
105
+rm -f sm1 &&
106
+mv sm1-bak sm1
107
+
108
+test_expect_success 'typechanged submodule(submodule->blob), --cached' "
109
+ git submodule summary --cached >actual &&
110
+ diff actual - <<-EOF
111
+* sm1 $head4(submodule)->$head5(blob) (3):
112
+ < Add foo5
113
+
114
+EOF
115
+"
116
+
117
+rm -rf sm1 &&
118
+git checkout-index sm1
119
+test_expect_success 'typechanged submodule(submodule->blob)' "
120
+ git submodule summary >actual &&
121
+ diff actual - <<-EOF
122
+* sm1 $head4(submodule)->$head5(blob):
123
+
124
+EOF
125
+"
126
+
127
+rm -f sm1 &&
128
+test_create_repo sm1 &&
129
+head6=$(add_file sm1 foo6 foo7)
130
+test_expect_success 'nonexistent commit' "
131
+ git submodule summary >actual &&
132
+ diff actual - <<-EOF
133
+* sm1 $head4...$head6:
134
+ Warn: sm1 doesn't contain commit $head4_full
135
+
136
+EOF
137
+"
138
+
139
+commit_file
140
+test_expect_success 'typechanged submodule(blob->submodule)' "
141
+ git submodule summary >actual &&
142
+ diff actual - <<-EOF
143
+* sm1 $head5(blob)->$head6(submodule) (2):
144
+ > Add foo7
145
+
146
+EOF
147
+"
148
+
149
+commit_file sm1 &&
150
+rm -rf sm1
151
+test_expect_success 'deleted submodule' "
152
+ git submodule summary >actual &&
153
+ diff actual - <<-EOF
154
+* sm1 $head6...0000000:
155
+
156
+EOF
157
+"
158
+
159
+test_create_repo sm2 &&
160
+head7=$(add_file sm2 foo8 foo9) &&
161
+git add sm2
162
+
163
+test_expect_success 'multiple submodules' "
164
+ git submodule summary >actual &&
165
+ diff actual - <<-EOF
166
+* sm1 $head6...0000000:
167
+
168
+* sm2 0000000...$head7 (2):
169
+ > Add foo9
170
+
171
+EOF
172
+"
173
+
174
+test_expect_success 'path filter' "
175
+ git submodule summary sm2 >actual &&
176
+ diff actual - <<-EOF
177
+* sm2 0000000...$head7 (2):
178
+ > Add foo9
179
+
180
+EOF
181
+"
182
+
183
+commit_file sm2
184
+test_expect_success 'given commit' "
185
+ git submodule summary HEAD^ >actual &&
186
+ diff actual - <<-EOF
187
+* sm1 $head6...0000000:
188
+
189
+* sm2 0000000...$head7 (2):
190
+ > Add foo9
191
+
192
+EOF
193
+"
194
+
195
+test_done