-
Notifications
You must be signed in to change notification settings - Fork 60
/
t0100-init.sh
executable file
·281 lines (256 loc) · 5.42 KB
/
t0100-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/sh
test_description="git-repo init"
. lib/test-lib.sh
# Create manifest repositories
manifest_url="file://${REPO_TEST_REPOSITORIES}/hello/manifests"
test_expect_success "setup" '
# create .repo file as a barrier, not find .repo deeper
touch .repo &&
mkdir work
'
test_expect_success "git-repo init -u" '
(
cd work &&
git-repo init -u $manifest_url
)
'
test_expect_success "check installed hooks" '
cat >expect<<-EOF &&
#!/bin/sh
EOF
head -1 .git-repo/hooks/commit-msg >actual &&
test_cmp expect actual &&
test -x .git-repo/hooks/commit-msg
'
test_expect_success "manifest points to default.xml" '
(
cd work &&
test -f .repo/manifest.xml &&
echo manifests/default.xml >expect &&
readlink .repo/manifest.xml >actual &&
test_cmp expect actual
)
'
test_expect_success "git config variable manifest.name = default.xml" '
(
cd work &&
echo default.xml >expect &&
(
cd .repo/manifests &&
git config manifest.name
) >actual &&
test_cmp expect actual
)
'
test_expect_success "two xml files checkout" '
(
cd work &&
# Has three xml files
ls .repo/manifests/*.xml >actual &&
cat >expect<<-EOF &&
.repo/manifests/default.xml
.repo/manifests/next.xml
.repo/manifests/remote-ro.xml
EOF
test_cmp expect actual
)
'
test_expect_success "current branch = default" '
(
cd work &&
echo "ref: refs/heads/default" >expect &&
cp .repo/manifests.git/HEAD actual &&
test_cmp expect actual
)
'
test_expect_success "remote track: master" '
(
cd work &&
cat >expect <<-EOF &&
refs/heads/master
EOF
(
cd .repo/manifests &&
git config branch.default.merge
) >actual &&
test_cmp expect actual
)
'
test_expect_success "test init in subdir" '
(
cd work &&
mkdir -p a/b/c &&
cd a/b/c &&
git-repo init -u $manifest_url &&
test ! -d .repo &&
cd "$HOME/work" &&
rm -rf a
)
'
test_expect_success "switch file: test init -m <file>" '
(
cd work &&
git-repo init -u $manifest_url -b master -m next.xml &&
# manifest.xml => manifests/next.xml
test -f .repo/manifest.xml &&
echo manifests/next.xml >expect &&
readlink .repo/manifest.xml >actual &&
test_cmp expect actual &&
# git config variable manifest.name => next.xml
echo next.xml >expect &&
(
cd .repo/manifests &&
git config manifest.name
) >actual &&
test_cmp expect actual
)
'
test_expect_success "switch branch: maint, no rollback" '
(
cd work &&
git-repo init -u $manifest_url -b Maint -m default.xml &&
cat >expect<<-EOF &&
.repo/manifests/default.xml
EOF
ls .repo/manifests/*.xml >actual &&
test_cmp expect actual
)
'
test_expect_success "after switch, remote track: maint" '
(
cd work &&
cat >expect <<-EOF &&
refs/heads/Maint
EOF
(
cd .repo/manifests &&
git config branch.default.merge
) >actual &&
test_cmp expect actual
)
'
test_expect_success "no -b for repo init, use previous branch" '
(
cd work &&
git-repo init -u $manifest_url &&
cat >expect <<-EOF &&
refs/heads/Maint
EOF
(
cd .repo/manifests &&
git config branch.default.merge
) >actual &&
test_cmp expect actual
)
'
test_expect_success "detached manifest, drop default branch" '
(
cd work/.repo/manifests &&
git checkout HEAD^0 &&
git branch -D default
)
'
test_expect_success "switch branch: Maint, file: default.xml" '
(
cd work &&
git-repo init -u $manifest_url -b Maint -m default.xml &&
# manifest.xml => manifests/default.xml
echo manifests/default.xml >expect &&
readlink .repo/manifest.xml >actual &&
test_cmp expect actual
)
'
test_expect_success "check default branch and tracking branch" '
(
cd work &&
(
cd .repo/manifests &&
git symbolic-ref HEAD &&
echo "----" &&
git config branch.default.remote &&
git config branch.default.merge &&
git config manifest.name
) >actual &&
cat >expect <<-EOF &&
refs/heads/default
----
origin
refs/heads/Maint
default.xml
EOF
test_cmp expect actual
)
'
test_expect_success "branch: Maint, no next.xml" '
(
cd work &&
# Branch switched, no release.xml
cat >expect<<-EOF &&
.repo/manifests/default.xml
EOF
ls .repo/manifests/*.xml >actual &&
test_cmp expect actual
)
'
test_expect_success "detached manifest, drop default branch" '
(
cd work/.repo/manifests &&
git checkout HEAD^0 &&
git branch -D default
)
'
test_expect_success "switch to tag: v0.1" '
(
cd work &&
git-repo init -u $manifest_url -b refs/tags/v0.1 &&
(
cd .repo/manifests &&
test_must_fail git symbolic-ref HEAD &&
test_must_fail git config branch.default.remote &&
test_must_fail git config branch.default.merge &&
git config manifest.name &&
git describe
) >actual &&
cat >expect <<-EOF &&
default.xml
v0.1
EOF
test_cmp expect actual
)
'
test_expect_success "switch branch: master, next.xml is back" '
(
cd work &&
git-repo init -u $manifest_url -b master &&
# Has two xml files
ls .repo/manifests/*.xml >actual &&
cat >expect<<-EOF &&
.repo/manifests/default.xml
.repo/manifests/next.xml
.repo/manifests/remote-ro.xml
EOF
test_cmp expect actual
)
'
test_expect_success "check default branch and tracking branch" '
(
cd work &&
(
cd .repo/manifests &&
git symbolic-ref HEAD &&
echo "----" &&
git config branch.default.remote &&
git config branch.default.merge &&
git config manifest.name
) >actual &&
cat >expect <<-EOF &&
refs/heads/default
----
origin
refs/heads/master
default.xml
EOF
test_cmp expect actual
)
'
test_done