|
1
|
# |
|
2
|
# Copyright (c) 2026 Dan Shearer |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
############################################################################ |
|
13
|
# |
|
14
|
# Tests of clone, push, pull and sync, over file: URLs and over HTTP to |
|
15
|
# "fossil server". After each operation, the repositories must hold the |
|
16
|
# same artifacts, except for private ones, and pass "fossil |
|
17
|
# test-integrity". |
|
18
|
# |
|
19
|
|
|
20
|
# The first sections run at every level, and the rest need |
|
21
|
# -assurance stress. |
|
22
|
require_no_open_checkout |
|
23
|
|
|
24
|
test_setup "" |
|
25
|
set dir [pwd] |
|
26
|
set ::env(FOSSIL_USER) tester |
|
27
|
|
|
28
|
# Returns the hashes of the artifacts in repository REPO that are |
|
29
|
# neither phantoms nor private, in order. |
|
30
|
# |
|
31
|
proc sync_artifacts {repo} { |
|
32
|
fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0\ |
|
33
|
AND rid NOT IN private ORDER BY uuid" |
|
34
|
return [normalize_result] |
|
35
|
} |
|
36
|
|
|
37
|
# Returns the hashes of the check-ins in repository REPO that are not |
|
38
|
# private, in order. |
|
39
|
# |
|
40
|
proc sync_checkins {repo} { |
|
41
|
fossil sql -R $repo "SELECT uuid FROM blob JOIN event ON objid=rid\ |
|
42
|
WHERE type='ci' AND rid NOT IN private\ |
|
43
|
ORDER BY uuid" |
|
44
|
return [normalize_result] |
|
45
|
} |
|
46
|
|
|
47
|
proc sync_private_count {repo} { |
|
48
|
fossil sql -R $repo "SELECT count(*) FROM private" |
|
49
|
return [normalize_result] |
|
50
|
} |
|
51
|
|
|
52
|
# Test NAME passes when "fossil test-integrity" finds no problems in |
|
53
|
# repository REPO. |
|
54
|
# |
|
55
|
proc sync_test_integrity {name repo} { |
|
56
|
fossil test-integrity -R $repo |
|
57
|
test_match $name [normalize_result] {checked: 0 errors} |
|
58
|
} |
|
59
|
|
|
60
|
# Commits a change to FILE in check-out DIR, with the comment COMMENT |
|
61
|
# and the extra commit options in ARGS. |
|
62
|
# |
|
63
|
proc sync_commit {dir file comment args} { |
|
64
|
write_file [file join $dir $file] "$comment\n" |
|
65
|
fossil add $file --chdir $dir |
|
66
|
fossil commit -m $comment --chdir $dir {*}$args |
|
67
|
} |
|
68
|
|
|
69
|
# Returns COUNT bytes of pseudo-random binary data, the same bytes for |
|
70
|
# the same seed given to srand(). |
|
71
|
# |
|
72
|
proc sync_random_bytes {count} { |
|
73
|
set bytes "" |
|
74
|
while {[string length $bytes] < $count} { |
|
75
|
append bytes [binary format i [expr {int(rand()*4294967296)}]] |
|
76
|
} |
|
77
|
return [string range $bytes 0 [expr {$count-1}]] |
|
78
|
} |
|
79
|
|
|
80
|
# The origin repository, with three check-ins, a tag and a wiki page. |
|
81
|
fossil new a.fossil |
|
82
|
fossil user capabilities nobody gio -R a.fossil |
|
83
|
file mkdir a |
|
84
|
fossil open ../a.fossil --chdir a |
|
85
|
sync_commit a f1.txt one |
|
86
|
sync_commit a f2.txt two |
|
87
|
sync_commit a f1.txt three --tag release |
|
88
|
write_file wiki.txt "A page" |
|
89
|
fossil wiki create Page wiki.txt -R a.fossil |
|
90
|
|
|
91
|
fossil clone file://[file join $dir a.fossil] b.fossil |
|
92
|
test sync-clone-file {$CODE == 0} |
|
93
|
test_eq sync-clone-file-artifacts [sync_artifacts b.fossil] \ |
|
94
|
[sync_artifacts a.fossil] |
|
95
|
sync_test_integrity sync-clone-file-integrity b.fossil |
|
96
|
fossil clone [file join $dir a.fossil] c.fossil |
|
97
|
test_eq sync-clone-path-artifacts [sync_artifacts c.fossil] \ |
|
98
|
[sync_artifacts a.fossil] |
|
99
|
file delete c.fossil |
|
100
|
|
|
101
|
# Push and pull between file: URLs. |
|
102
|
file mkdir b |
|
103
|
fossil open ../b.fossil --chdir b |
|
104
|
sync_commit b f3.txt four |
|
105
|
fossil push -R b.fossil |
|
106
|
test sync-push-file {$CODE == 0} |
|
107
|
test_eq sync-push-file-checkins [sync_checkins a.fossil] \ |
|
108
|
[sync_checkins b.fossil] |
|
109
|
fossil update --chdir a |
|
110
|
sync_commit a f4.txt five |
|
111
|
fossil pull -R b.fossil |
|
112
|
test_eq sync-pull-file-artifacts [sync_artifacts b.fossil] \ |
|
113
|
[sync_artifacts a.fossil] |
|
114
|
fossil update --chdir b |
|
115
|
|
|
116
|
# A private check-in stays in the repository that made it. |
|
117
|
sync_commit b f5.txt secret --private |
|
118
|
fossil push -R b.fossil |
|
119
|
test sync-private-made {[sync_private_count b.fossil] > 0} |
|
120
|
test_eq sync-private-not-pushed [sync_private_count a.fossil] 0 |
|
121
|
test_eq sync-private-artifacts [sync_artifacts a.fossil] \ |
|
122
|
[sync_artifacts b.fossil] |
|
123
|
fossil update trunk --chdir b |
|
124
|
|
|
125
|
# The sections below that were written for a checkout of their own each |
|
126
|
# run in a directory of their own, with a repository of their own and |
|
127
|
# without the user name that the sections above set. |
|
128
|
proc sync_enter {name} { |
|
129
|
global dir |
|
130
|
file mkdir [file join $dir $name] |
|
131
|
cd [file join $dir $name] |
|
132
|
set ::syncUser $::env(FOSSIL_USER) |
|
133
|
unset ::env(FOSSIL_USER) |
|
134
|
fossil new .rep.fossil |
|
135
|
fossil open .rep.fossil |
|
136
|
fossil set mtime-changes off |
|
137
|
} |
|
138
|
proc sync_leave {} { |
|
139
|
global dir |
|
140
|
cd $dir |
|
141
|
set ::env(FOSSIL_USER) $::syncUser |
|
142
|
} |
|
143
|
|
|
144
|
############################################################################### |
|
145
|
# Whole syncs between repositories on one machine. A push, pull or sync |
|
146
|
# with a repository named by its file starts "fossil http" on that file, |
|
147
|
# so both sides speak the sync protocol in full, and the other side |
|
148
|
# grants every permission. Where the other side has to check |
|
149
|
# permissions, the messages go through standin/scenario-wire.tcl. |
|
150
|
|
|
151
|
sync_enter xfer-sync |
|
152
|
|
|
153
|
set syncXferDir [pwd] |
|
154
|
set syncXferSrv [file join $syncXferDir srv.fossil] |
|
155
|
|
|
156
|
proc sync_sql {repo sql} { |
|
157
|
return [fossil_sql $sql $repo] |
|
158
|
} |
|
159
|
|
|
160
|
# How many timeline entries of REPO have the comment COMMENT. |
|
161
|
proc sync_has {repo comment} { |
|
162
|
return [sync_sql $repo "SELECT count(*) FROM event |
|
163
|
WHERE comment='$comment'"] |
|
164
|
} |
|
165
|
|
|
166
|
# The artifacts REPO holds that are neither phantoms nor private. |
|
167
|
proc sync_public {repo} { |
|
168
|
return [sync_sql $repo "SELECT group_concat(uuid, ' ') FROM (SELECT uuid |
|
169
|
FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"] |
|
170
|
} |
|
171
|
proc sync_private_held {repo} { |
|
172
|
return [sync_sql $repo "SELECT count(*) FROM private, blob |
|
173
|
WHERE private.rid=blob.rid AND size>=0"] |
|
174
|
} |
|
175
|
proc sync_integrity {name repo} { |
|
176
|
fossil test-integrity -R $repo |
|
177
|
test $name {$::CODE == 0} |
|
178
|
} |
|
179
|
|
|
180
|
# Commit FILE with CONTENT in the checkout and return the check-in's hash. |
|
181
|
proc sync_checkin {file content comment args} { |
|
182
|
set new [expr {![file exists $file]}] |
|
183
|
write_file $file $content |
|
184
|
if {$new} {fossil add $file} |
|
185
|
fossil commit -m $comment --no-warnings {*}$args |
|
186
|
return [sync_sql .rep.fossil "SELECT uuid FROM blob, event |
|
187
|
WHERE objid=rid AND comment='$comment'"] |
|
188
|
} |
|
189
|
|
|
190
|
set syncXferText "" |
|
191
|
for {set syncXferI 0} {$syncXferI < 60} {incr syncXferI} { |
|
192
|
append syncXferText "line $syncXferI of a file that is kept in versions\n" |
|
193
|
} |
|
194
|
fossil settings autosync off |
|
195
|
sync_checkin a.txt $syncXferText xfersync-first |
|
196
|
file copy .rep.fossil srv.fossil |
|
197
|
file copy .rep.fossil c2.fossil |
|
198
|
file copy .rep.fossil c3.fossil |
|
199
|
|
|
200
|
############################################################################### |
|
201
|
# A check-in that was private and is made public, while its file is still |
|
202
|
# stored as a delta from a private one. Neither a push nor a clone may |
|
203
|
# hand out the delta: the other side lacks what it was made from. |
|
204
|
|
|
205
|
set syncXferG1 [sync_checkin big.txt "${syncXferText}first\n" \ |
|
206
|
xfersync-g1 --private] |
|
207
|
set syncXferG2 [sync_checkin big.txt "${syncXferText}first\nsecond\n" \ |
|
208
|
xfersync-g2] |
|
209
|
fossil publish $syncXferG1 |
|
210
|
test xfer-sync-publish {$CODE == 0} |
|
211
|
test xfer-sync-public-delta-from-private {[sync_sql .rep.fossil "SELECT |
|
212
|
count(*) FROM delta WHERE rid NOT IN private AND srcid IN private"] > 0} |
|
213
|
|
|
214
|
fossil push $syncXferSrv |
|
215
|
test xfer-sync-push {$CODE == 0} |
|
216
|
test_eq xfer-sync-push-published [sync_has srv.fossil xfersync-g1] 1 |
|
217
|
test_eq xfer-sync-push-not-private [sync_has srv.fossil xfersync-g2] 0 |
|
218
|
test_eq xfer-sync-push-no-private-artifacts [sync_private_held srv.fossil] 0 |
|
219
|
test_eq xfer-sync-push-artifacts [sync_public srv.fossil] \ |
|
220
|
[sync_public .rep.fossil] |
|
221
|
fossil cat big.txt -R srv.fossil -r $syncXferG1 |
|
222
|
test_eq xfer-sync-push-content $RESULT "${syncXferText}first" |
|
223
|
sync_integrity xfer-sync-push-integrity srv.fossil |
|
224
|
|
|
225
|
set syncXferWire [file join $syncXferDir wire.tcl] |
|
226
|
file copy [file join $::testfiledir standin scenario-wire.tcl] $syncXferWire |
|
227
|
set syncXferWire "\"[info nameofexecutable]\" \"$syncXferWire\"" |
|
228
|
set ::env(SCN_EXE) $::fossilexe |
|
229
|
set ::env(SCN_REPO) [file join $syncXferDir .rep.fossil] |
|
230
|
set ::env(SCN_FAULT) 0 |
|
231
|
fossil_raw -seconds 120 clone http://xfersync.invalid/x c4.fossil \ |
|
232
|
--transport-command $syncXferWire --no-open |
|
233
|
test xfer-sync-clone {$CODE == 0} |
|
234
|
test_eq xfer-sync-clone-artifacts [sync_public c4.fossil] \ |
|
235
|
[sync_public .rep.fossil] |
|
236
|
test_eq xfer-sync-clone-no-private [sync_has c4.fossil xfersync-g2] 0 |
|
237
|
fossil cat big.txt -R c4.fossil -r $syncXferG1 |
|
238
|
test_eq xfer-sync-clone-content $RESULT "${syncXferText}first" |
|
239
|
sync_integrity xfer-sync-clone-integrity c4.fossil |
|
240
|
|
|
241
|
if {[test_assurance] ne "stress"} { |
|
242
|
test_skip "the tests after the first sections need -assurance stress" |
|
243
|
} |
|
244
|
|
|
245
|
############################################################################### |
|
246
|
# Private check-ins go only when asked for, and stay private where they |
|
247
|
# arrive. |
|
248
|
|
|
249
|
fossil push --private $syncXferSrv |
|
250
|
test xfer-sync-push-private {$CODE == 0} |
|
251
|
test_eq xfer-sync-push-private-arrived [sync_has srv.fossil xfersync-g2] 1 |
|
252
|
test xfer-sync-push-private-marked {[sync_private_held srv.fossil] > 0} |
|
253
|
test_eq xfer-sync-push-private-count [sync_private_held srv.fossil] \ |
|
254
|
[sync_private_held .rep.fossil] |
|
255
|
|
|
256
|
fossil pull $syncXferSrv -R c2.fossil |
|
257
|
test xfer-sync-pull {$CODE == 0} |
|
258
|
test_eq xfer-sync-pull-no-private [sync_has c2.fossil xfersync-g2] 0 |
|
259
|
test_eq xfer-sync-pull-artifacts [sync_public c2.fossil] \ |
|
260
|
[sync_public srv.fossil] |
|
261
|
fossil pull --private $syncXferSrv -R c2.fossil |
|
262
|
test xfer-sync-pull-private {$CODE == 0} |
|
263
|
test_eq xfer-sync-pull-private-arrived [sync_has c2.fossil xfersync-g2] 1 |
|
264
|
test_eq xfer-sync-pull-private-count [sync_private_held c2.fossil] \ |
|
265
|
[sync_private_held srv.fossil] |
|
266
|
fossil cat big.txt -R c2.fossil -r $syncXferG2 |
|
267
|
test_eq xfer-sync-pull-private-content $RESULT "${syncXferText}first\nsecond" |
|
268
|
sync_integrity xfer-sync-pull-private-integrity c2.fossil |
|
269
|
|
|
270
|
# With --verily each side lists everything it holds. The result is the |
|
271
|
# same. The options that change only what is printed do not change it |
|
272
|
# either. |
|
273
|
fossil pull --verily $syncXferSrv -R c3.fossil |
|
274
|
test xfer-sync-pull-verily {$CODE == 0} |
|
275
|
test_eq xfer-sync-pull-verily-artifacts [sync_public c3.fossil] \ |
|
276
|
[sync_public srv.fossil] |
|
277
|
fossil sync --verily --private $syncXferSrv -R c3.fossil |
|
278
|
test xfer-sync-sync-verily {$CODE == 0} |
|
279
|
test_eq xfer-sync-sync-verily-private [sync_private_held c3.fossil] \ |
|
280
|
[sync_private_held srv.fossil] |
|
281
|
fossil sync -v -v --no-http-compression $syncXferSrv -R c3.fossil |
|
282
|
test xfer-sync-verbose {$CODE == 0 && [string first "Sent:" $RESULT] >= 0} |
|
283
|
fossil sync --quiet $syncXferSrv -R c3.fossil |
|
284
|
test xfer-sync-quiet {$CODE == 0} |
|
285
|
sync_integrity xfer-sync-verily-integrity c3.fossil |
|
286
|
|
|
287
|
############################################################################### |
|
288
|
# Unversioned files. The newer of two versions wins, whichever side has |
|
289
|
# it; a removal is a version like any other. |
|
290
|
|
|
291
|
proc sync_uv {repo name} { |
|
292
|
return [sync_sql $repo "SELECT ifnull(hash,'removed') || ' ' || mtime |
|
293
|
FROM unversioned WHERE name='$name'"] |
|
294
|
} |
|
295
|
proc sync_uvtime {text} { |
|
296
|
return [sync_sql .rep.fossil "SELECT strftime('%s','$text')"] |
|
297
|
} |
|
298
|
|
|
299
|
write_file one.txt "the first version of one\n" |
|
300
|
fossil uv add one.txt --mtime 2026-01-01T00:00:00 |
|
301
|
fossil uv sync $syncXferSrv |
|
302
|
test xfer-sync-uv-push {$CODE == 0} |
|
303
|
test_eq xfer-sync-uv-push-arrived [sync_uv srv.fossil one.txt] \ |
|
304
|
[sync_uv .rep.fossil one.txt] |
|
305
|
fossil uv cat one.txt -R srv.fossil |
|
306
|
test_eq xfer-sync-uv-push-content $RESULT "the first version of one" |
|
307
|
|
|
308
|
write_file two.txt "a file added on the other side\n" |
|
309
|
fossil uv add two.txt -R srv.fossil --mtime 2026-01-02T00:00:00 |
|
310
|
fossil uv sync -v $syncXferSrv |
|
311
|
test xfer-sync-uv-pull {$CODE == 0} |
|
312
|
test xfer-sync-uv-pull-said \ |
|
313
|
{[holds_strings $RESULT {"UV-PULL: two.txt" |
|
314
|
"Unversioned-file received: two.txt"}]} |
|
315
|
fossil uv cat two.txt |
|
316
|
test_eq xfer-sync-uv-pull-content $RESULT "a file added on the other side" |
|
317
|
|
|
318
|
# A trial run says what would go and sends nothing. |
|
319
|
write_file one.txt "the second version of one\n" |
|
320
|
fossil uv add one.txt --mtime 2026-01-03T00:00:00 |
|
321
|
fossil uv sync -n $syncXferSrv |
|
322
|
test xfer-sync-uv-dry-run {$CODE == 0 && |
|
323
|
[string first "UV-PUSH: one.txt" $RESULT] >= 0} |
|
324
|
fossil uv cat one.txt -R srv.fossil |
|
325
|
test_eq xfer-sync-uv-dry-run-sent-nothing $RESULT "the first version of one" |
|
326
|
|
|
327
|
# A revert takes the other side's version although it is older. |
|
328
|
fossil uv revert $syncXferSrv |
|
329
|
test xfer-sync-uv-revert {$CODE == 0} |
|
330
|
fossil uv cat one.txt |
|
331
|
test_eq xfer-sync-uv-revert-content $RESULT "the first version of one" |
|
332
|
|
|
333
|
write_file one.txt "the second version of one\n" |
|
334
|
fossil uv add one.txt --mtime 2026-01-03T00:00:00 |
|
335
|
fossil uv sync -v $syncXferSrv |
|
336
|
test xfer-sync-uv-push-newer {$CODE == 0} |
|
337
|
test xfer-sync-uv-push-newer-said \ |
|
338
|
{[holds_strings $RESULT {"UV-PUSH: one.txt" |
|
339
|
"Unversioned-file sent: one.txt"}]} |
|
340
|
fossil uv cat one.txt -R srv.fossil |
|
341
|
test_eq xfer-sync-uv-push-newer-content $RESULT "the second version of one" |
|
342
|
|
|
343
|
# A removal on the other side. |
|
344
|
fossil uv rm two.txt -R srv.fossil --mtime 2026-01-04T00:00:00 |
|
345
|
fossil uv sync -v $syncXferSrv |
|
346
|
test xfer-sync-uv-removal {$CODE == 0} |
|
347
|
test_eq xfer-sync-uv-removal-arrived [sync_uv .rep.fossil two.txt] \ |
|
348
|
"removed [sync_uvtime 2026-01-04T00:00:00]" |
|
349
|
|
|
350
|
# The same content with a newer time, first there and then here. |
|
351
|
fossil uv touch one.txt -R srv.fossil --mtime 2026-01-05T00:00:00 |
|
352
|
fossil uv sync -v $syncXferSrv |
|
353
|
test xfer-sync-uv-time-pulled {$CODE == 0 && |
|
354
|
[string first "UV-PULL-MTIME-ONLY: one.txt" $RESULT] >= 0} |
|
355
|
test_eq xfer-sync-uv-time-pulled-value \ |
|
356
|
[lindex [sync_uv .rep.fossil one.txt] 1] \ |
|
357
|
[sync_uvtime 2026-01-05T00:00:00] |
|
358
|
fossil uv touch one.txt --mtime 2026-01-06T00:00:00 |
|
359
|
fossil uv sync -v $syncXferSrv |
|
360
|
test xfer-sync-uv-time-pushed {$CODE == 0 && |
|
361
|
[string first "UV-PUSH-MTIME-ONLY: one.txt" $RESULT] >= 0} |
|
362
|
test_eq xfer-sync-uv-time-pushed-value \ |
|
363
|
[lindex [sync_uv srv.fossil one.txt] 1] \ |
|
364
|
[sync_uvtime 2026-01-06T00:00:00] |
|
365
|
test_eq xfer-sync-uv-same-at-end [sync_uv srv.fossil one.txt] \ |
|
366
|
[sync_uv .rep.fossil one.txt] |
|
367
|
|
|
368
|
# A user who may read and not write unversioned files is told so, and |
|
369
|
# what was to be sent stays here. |
|
370
|
set ::env(SCN_REPO) $syncXferSrv |
|
371
|
set ::env(SCN_AUTH) 1 |
|
372
|
fossil sql -R srv.fossil \ |
|
373
|
"UPDATE user SET cap='o' WHERE login IN ('nobody','anonymous')" |
|
374
|
fossil uv touch one.txt --mtime 2026-01-07T00:00:00 |
|
375
|
fossil_raw -seconds 120 uv sync -v http://xfersync.invalid/x \ |
|
376
|
--transport-command $syncXferWire |
|
377
|
test xfer-sync-uv-pull-only {[string first "uv-pull-only" $RESULT] >= 0} |
|
378
|
test_eq xfer-sync-uv-pull-only-not-sent \ |
|
379
|
[lindex [sync_uv srv.fossil one.txt] 1] \ |
|
380
|
[sync_uvtime 2026-01-06T00:00:00] |
|
381
|
|
|
382
|
# The same for a file that the other side has never held. |
|
383
|
fossil uv touch one.txt --mtime 2026-01-06T00:00:00 |
|
384
|
write_file three.txt "a file the other side will not take\n" |
|
385
|
fossil uv add three.txt --mtime 2026-01-07T00:00:00 |
|
386
|
fossil_raw -seconds 120 uv sync -v http://xfersync.invalid/x \ |
|
387
|
--transport-command $syncXferWire |
|
388
|
set syncXferSaid $RESULT |
|
389
|
test_eq xfer-sync-uv-pull-only-new-not-sent [sync_uv srv.fossil three.txt] "" |
|
390
|
test xfer-sync-uv-pull-only-new-said \ |
|
391
|
{[string first "uv-pull-only" $syncXferSaid] >= 0} |
|
392
|
test xfer-sync-uv-pull-only-new-kept {[sync_uv .rep.fossil three.txt] ne ""} |
|
393
|
|
|
394
|
# A revert from such a server still makes this side match it: the file |
|
395
|
# the server never had goes, and nothing is said about pushing. |
|
396
|
fossil_raw -seconds 120 uv revert http://xfersync.invalid/x \ |
|
397
|
--transport-command $syncXferWire |
|
398
|
test xfer-sync-uv-pull-only-revert {$CODE == 0 && |
|
399
|
[string first "uv-pull-only" $RESULT] < 0} |
|
400
|
test_eq xfer-sync-uv-pull-only-revert-removed [sync_uv .rep.fossil three.txt] "" |
|
401
|
unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH) |
|
402
|
|
|
403
|
############################################################################### |
|
404
|
# A project that was split off pulls from the project it came from only |
|
405
|
# when it says that it means to. |
|
406
|
|
|
407
|
file copy srv.fossil child2.fossil |
|
408
|
fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime) |
|
409
|
VALUES('project-name','xfersync parent',now())" |
|
410
|
file copy srv.fossil child.fossil |
|
411
|
fossil_raw -input "y\n" detach child.fossil |
|
412
|
test xfer-sync-detach {$CODE == 0} |
|
413
|
test xfer-sync-detach-new-code {[sync_sql child.fossil "SELECT value |
|
414
|
FROM config WHERE name='project-code'"] ne [sync_sql srv.fossil "SELECT |
|
415
|
value FROM config WHERE name='project-code'"]} |
|
416
|
sync_checkin a.txt "${syncXferText}more\n" xfersync-after-split |
|
417
|
fossil push --private $syncXferSrv |
|
418
|
test_eq xfer-sync-parent-has-new [sync_has srv.fossil xfersync-after-split] 1 |
|
419
|
fossil pull $syncXferSrv -R child.fossil -expectError |
|
420
|
test xfer-sync-child-plain-pull-refused {$CODE != 0} |
|
421
|
test_eq xfer-sync-child-plain-pull-nothing \ |
|
422
|
[sync_has child.fossil xfersync-after-split] 0 |
|
423
|
# The new check-in follows a private one, so it is private too. |
|
424
|
fossil pull --from-parent-project $syncXferSrv -R child.fossil |
|
425
|
test xfer-sync-child-parent-pull-public-only {$CODE == 0 && |
|
426
|
[sync_has child.fossil xfersync-after-split] == 0} |
|
427
|
fossil pull --private --from-parent-project $syncXferSrv -R child.fossil |
|
428
|
test xfer-sync-child-parent-pull {$CODE == 0} |
|
429
|
test_eq xfer-sync-child-parent-pull-arrived \ |
|
430
|
[sync_has child.fossil xfersync-after-split] 1 |
|
431
|
sync_integrity xfer-sync-child-integrity child.fossil |
|
432
|
|
|
433
|
# The same when the project it came from has no name. |
|
434
|
fossil_raw -input "y\n" detach child2.fossil |
|
435
|
fossil_raw pull --from-parent-project $syncXferSrv -R child2.fossil |
|
436
|
test xfer-sync-unnamed-parent-pull {$CODE == 0} |
|
437
|
test_eq xfer-sync-unnamed-parent-pull-arrived [sync_public child2.fossil] \ |
|
438
|
[sync_public srv.fossil] |
|
439
|
|
|
440
|
sync_leave |
|
441
|
|
|
442
|
############################################################################### |
|
443
|
# A clone made over the sync protocol. "fossil clone" of a file on the |
|
444
|
# same machine copies the file and never speaks the protocol, so here a |
|
445
|
# real client clones from a real server through |
|
446
|
# standin/scenario-wire.tcl, which hands each request to "fossil http" |
|
447
|
# on the server's repository. |
|
448
|
|
|
449
|
sync_enter xfer-clone |
|
450
|
|
|
451
|
# The server: several versions of one file, so that it stores deltas, an |
|
452
|
# empty file, a branch, a tag, a wiki page and an unversioned file. |
|
453
|
set syncCloneText "" |
|
454
|
for {set syncCloneI 0} {$syncCloneI < 40} {incr syncCloneI} { |
|
455
|
append syncCloneText "line $syncCloneI of a file with several versions\n" |
|
456
|
} |
|
457
|
write_file empty.txt "" |
|
458
|
fossil add empty.txt |
|
459
|
foreach syncCloneI {1 2 3 4 5} { |
|
460
|
append syncCloneText "version $syncCloneI\n" |
|
461
|
write_file a.txt $syncCloneText |
|
462
|
if {$syncCloneI == 1} {fossil add a.txt} |
|
463
|
fossil commit -m "xferclone-v$syncCloneI" --no-warnings |
|
464
|
} |
|
465
|
fossil branch new side trunk |
|
466
|
fossil tag add marked trunk |
|
467
|
write_file page.txt "a wiki page\n" |
|
468
|
fossil wiki create ClonePage page.txt |
|
469
|
write_file note.txt "an unversioned note\n" |
|
470
|
fossil unversioned add note.txt |
|
471
|
file copy .rep.fossil srv.fossil |
|
472
|
|
|
473
|
set syncCloneWire [file join [pwd] wire.tcl] |
|
474
|
file copy [file join $::testfiledir standin scenario-wire.tcl] $syncCloneWire |
|
475
|
set syncCloneWire "\"[info nameofexecutable]\" \"$syncCloneWire\"" |
|
476
|
set ::env(SCN_EXE) $::fossilexe |
|
477
|
set ::env(SCN_REPO) [file join [pwd] srv.fossil] |
|
478
|
set ::env(SCN_FAULT) 0 |
|
479
|
|
|
480
|
# Clone the server into the repository file NAME, with any more |
|
481
|
# arguments for "fossil clone". |
|
482
|
# |
|
483
|
proc sync_clone_wire {name args} { |
|
484
|
global syncCloneWire |
|
485
|
fossil_raw -seconds 120 clone http://xferclone.invalid/x $name \ |
|
486
|
--transport-command $syncCloneWire --no-open {*}$args |
|
487
|
} |
|
488
|
|
|
489
|
# What a repository holds: the artifacts with content, the timeline, the |
|
490
|
# branches and tags, and the unversioned files. |
|
491
|
# |
|
492
|
proc sync_holds {repo} { |
|
493
|
fossil sql -R $repo "SELECT group_concat(uuid, ' ') FROM (SELECT uuid |
|
494
|
FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid); |
|
495
|
SELECT group_concat(x, ' ') FROM (SELECT type || comment AS x |
|
496
|
FROM event ORDER BY mtime, objid); |
|
497
|
SELECT group_concat(x, ' ') FROM (SELECT tagname || tagtype AS x |
|
498
|
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid AND tagname LIKE 'sym-%' |
|
499
|
ORDER BY 1)" |
|
500
|
return [string trim $::RESULT] |
|
501
|
} |
|
502
|
proc sync_uv_files {repo} { |
|
503
|
fossil sql -R $repo "SELECT group_concat(name || '/' || hash, ' ') |
|
504
|
FROM unversioned WHERE hash IS NOT NULL" |
|
505
|
return [string trim $::RESULT] |
|
506
|
} |
|
507
|
|
|
508
|
set syncCloneWant [sync_holds srv.fossil] |
|
509
|
|
|
510
|
############################################################################### |
|
511
|
# An ordinary clone holds what the server holds, and is sound. |
|
512
|
|
|
513
|
sync_clone_wire c1.fossil |
|
514
|
test xfer-clone {$CODE == 0} |
|
515
|
test_eq xfer-clone-holds [sync_holds c1.fossil] $syncCloneWant |
|
516
|
fossil test-integrity -R c1.fossil |
|
517
|
test xfer-clone-integrity {$CODE == 0} |
|
518
|
fossil sql -R c1.fossil "SELECT value FROM config WHERE name='project-code'" |
|
519
|
set syncCloneCode [string trim $RESULT] |
|
520
|
fossil sql -R srv.fossil "SELECT value FROM config WHERE name='project-code'" |
|
521
|
test_eq xfer-clone-project-code $syncCloneCode [string trim $RESULT] |
|
522
|
|
|
523
|
# The files of the newest and of the first check-in can be read from it. |
|
524
|
fossil cat a.txt -R c1.fossil -r trunk |
|
525
|
test_eq xfer-clone-newest-file [string trim $RESULT] \ |
|
526
|
[string trim $syncCloneText] |
|
527
|
fossil cat empty.txt -R c1.fossil -r trunk |
|
528
|
test_eq xfer-clone-empty-file $RESULT "" |
|
529
|
|
|
530
|
# Unversioned files come only when they are asked for. |
|
531
|
fossil sql -R c1.fossil "SELECT count(*) FROM sqlite_schema |
|
532
|
WHERE name='unversioned'" |
|
533
|
set syncCloneHasUv [string trim $RESULT] |
|
534
|
test xfer-clone-without-unversioned \ |
|
535
|
{!$syncCloneHasUv || [sync_uv_files c1.fossil] eq ""} |
|
536
|
sync_clone_wire c2.fossil --unversioned |
|
537
|
test xfer-clone-unversioned {$CODE == 0} |
|
538
|
test_eq xfer-clone-unversioned-files [sync_uv_files c2.fossil] \ |
|
539
|
[sync_uv_files srv.fossil] |
|
540
|
test_eq xfer-clone-unversioned-holds [sync_holds c2.fossil] $syncCloneWant |
|
541
|
|
|
542
|
# With small messages the clone takes many round trips and ends the same. |
|
543
|
fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime) |
|
544
|
VALUES('max-download',2000,now())" |
|
545
|
sync_clone_wire c3.fossil |
|
546
|
test xfer-clone-small-replies {$CODE == 0} |
|
547
|
test_eq xfer-clone-small-replies-holds [sync_holds c3.fossil] \ |
|
548
|
$syncCloneWant |
|
549
|
fossil test-integrity -R c3.fossil |
|
550
|
test xfer-clone-small-replies-integrity {$CODE == 0} |
|
551
|
fossil sql -R srv.fossil "DELETE FROM config WHERE name='max-download'" |
|
552
|
|
|
553
|
############################################################################### |
|
554
|
# A server that checks permissions refuses a clone to a user without the |
|
555
|
# permission, and no repository is left behind. |
|
556
|
|
|
557
|
set ::env(SCN_AUTH) 1 |
|
558
|
fossil sql -R srv.fossil \ |
|
559
|
"UPDATE user SET cap='o' WHERE login IN ('nobody','anonymous')" |
|
560
|
sync_clone_wire c4.fossil |
|
561
|
test xfer-clone-refused \ |
|
562
|
{$CODE != 0 && [string first "not authorized to clone" $RESULT] >= 0} |
|
563
|
test xfer-clone-refused-leaves-nothing {![file exists c4.fossil]} |
|
564
|
fossil sql -R srv.fossil \ |
|
565
|
"UPDATE user SET cap='go' WHERE login IN ('nobody','anonymous')" |
|
566
|
sync_clone_wire c5.fossil |
|
567
|
test xfer-clone-permitted {$CODE == 0} |
|
568
|
test_eq xfer-clone-permitted-holds [sync_holds c5.fossil] $syncCloneWant |
|
569
|
|
|
570
|
unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH) |
|
571
|
|
|
572
|
sync_leave |
|
573
|
|
|
574
|
############################################################################### |
|
575
|
|
|
576
|
if {![loopback_available]} { |
|
577
|
unset ::env(FOSSIL_USER) |
|
578
|
test_skip "the tests that run fossil server cannot start a server" |
|
579
|
} |
|
580
|
set server [test_start_server a.fossil stopArg] |
|
581
|
set url http://127.0.0.1:[lindex $server 1] |
|
582
|
|
|
583
|
fossil clone --proxy off $url c.fossil |
|
584
|
test sync-clone-http {$CODE == 0} |
|
585
|
test_eq sync-clone-http-artifacts [sync_artifacts c.fossil] \ |
|
586
|
[sync_artifacts a.fossil] |
|
587
|
sync_test_integrity sync-clone-http-integrity c.fossil |
|
588
|
|
|
589
|
# Two clones commit at once on trunk, then sync with the server. Both |
|
590
|
# end with both check-ins, as two leaves. |
|
591
|
file mkdir c |
|
592
|
fossil open ../c.fossil --chdir c |
|
593
|
fossil settings autosync off --chdir c |
|
594
|
fossil settings autosync off --chdir b |
|
595
|
fossil remote $url --chdir b |
|
596
|
sync_commit b f6.txt from-b |
|
597
|
sync_commit c f7.txt from-c |
|
598
|
fossil sync --proxy off -R b.fossil |
|
599
|
test sync-http-b {$CODE == 0} |
|
600
|
fossil sync --proxy off -R c.fossil -expectError |
|
601
|
test_match sync-http-c-fork-warning [normalize_result] \ |
|
602
|
{WARNING: a fork has occurred} |
|
603
|
fossil sync --proxy off -R b.fossil -expectError |
|
604
|
test_eq sync-http-same-checkins [sync_checkins c.fossil] \ |
|
605
|
[sync_checkins b.fossil] |
|
606
|
fossil sql -R c.fossil "SELECT count(*) FROM leaf" |
|
607
|
test_eq sync-http-fork [normalize_result] 2 |
|
608
|
foreach repo {a b c} { |
|
609
|
sync_test_integrity sync-http-integrity-$repo $repo.fossil |
|
610
|
} |
|
611
|
|
|
612
|
# An artifact whose content does not match its hash. test-integrity |
|
613
|
# reports it, and a clone of the repository fails. |
|
614
|
file copy a.fossil d.fossil |
|
615
|
fossil sql -R d.fossil "UPDATE blob SET uuid='[string repeat 0 40]'\ |
|
616
|
WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\ |
|
617
|
WHERE name='f2.txt' LIMIT 1)" |
|
618
|
fossil test-integrity -R d.fossil -expectError |
|
619
|
test_match sync-bad-hash-integrity [normalize_result] {checked: 1 errors} |
|
620
|
test sync-bad-hash-integrity-status {$CODE != 0} |
|
621
|
test_stop_server $stopArg [lindex $server 0] [lindex $server 2] |
|
622
|
set server [test_start_server d.fossil stopArg] |
|
623
|
set url http://127.0.0.1:[lindex $server 1] |
|
624
|
fossil clone --proxy off $url e.fossil -expectError |
|
625
|
test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug |
|
626
|
test_stop_server $stopArg [lindex $server 0] [lindex $server 2] |
|
627
|
|
|
628
|
############################################################################### |
|
629
|
# A sync that gets no reply must not report success. |
|
630
|
|
|
631
|
if {$::tcl_platform(platform) ne "windows"} { |
|
632
|
fossil new nr.fossil |
|
633
|
file mkdir nr |
|
634
|
fossil open ../nr.fossil --chdir nr |
|
635
|
sync_commit nr nf.txt one |
|
636
|
set syncWire [file join $dir no-reply] |
|
637
|
file mkdir $syncWire |
|
638
|
write_file [file join $syncWire reply.1] "" |
|
639
|
set ::env(TRANSPORT_DIR) $syncWire |
|
640
|
set syncWrapper \ |
|
641
|
[test_standin transport.sh [file join $syncWire transport.sh]] |
|
642
|
fossil sync http://sync-test.invalid/x --once \ |
|
643
|
--transport-command $syncWrapper --chdir nr -expectError |
|
644
|
test sync-no-reply-fails {$CODE != 0} |
|
645
|
test_match sync-no-reply-message [normalize_result] {empty reply} |
|
646
|
unset ::env(TRANSPORT_DIR) |
|
647
|
} |
|
648
|
|
|
649
|
############################################################################### |
|
650
|
# An unversioned file pushed together with a commit that spans more than |
|
651
|
# one message must arrive. |
|
652
|
|
|
653
|
fossil new uva.fossil |
|
654
|
fossil clone [file join $dir uva.fossil] uvb.fossil |
|
655
|
file mkdir uvco |
|
656
|
fossil open ../uvb.fossil --chdir uvco |
|
657
|
fossil settings autosync off --chdir uvco |
|
658
|
expr {srand(1)} |
|
659
|
foreach syncI {1 2 3 4 5 6} { |
|
660
|
write_file [file join uvco big$syncI.bin] [sync_random_bytes 200000] |
|
661
|
fossil add big$syncI.bin --chdir uvco |
|
662
|
} |
|
663
|
fossil commit -m big --chdir uvco --no-warnings |
|
664
|
write_file [file join uvco note.txt] "an unversioned file\n" |
|
665
|
fossil uv add note.txt --chdir uvco |
|
666
|
fossil sync -u [file join $dir uva.fossil] --chdir uvco |
|
667
|
test sync-unversioned-with-large-commit {$CODE == 0} |
|
668
|
fossil uv list -R uva.fossil |
|
669
|
test_match sync-unversioned-arrived [normalize_result] {note\.txt} |
|
670
|
|
|
671
|
test_cleanup |
|
672
|
unset ::env(FOSSIL_USER) |
|
673
|
|