|
1
|
# |
|
2
|
# Copyright (c) 2026 Dan Mestas |
|
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
|
# Reading check-ins and their files in src/manifest.c: two check-ins |
|
15
|
# compared with "fossil diff --from --to", the /dir and /tree pages, |
|
16
|
# delta manifests read through their baseline, a file named in another |
|
17
|
# letter case, and artifact_to_json() for every kind of artifact. |
|
18
|
# |
|
19
|
|
|
20
|
test_setup |
|
21
|
|
|
22
|
# The hash of the check-in with the comment COMMENT. |
|
23
|
# |
|
24
|
proc manifest_ci {comment} { |
|
25
|
return [fossil_sql "SELECT uuid FROM blob, event |
|
26
|
WHERE objid=rid AND type='ci' AND comment='$comment'"] |
|
27
|
} |
|
28
|
|
|
29
|
# The reply of the server to a GET of PATH. |
|
30
|
# |
|
31
|
proc manifest_get {path} { |
|
32
|
return [fossil_http [file join [pwd] .rep.fossil] [request_get $path] \ |
|
33
|
--ipaddr 127.0.0.1 --localauth] |
|
34
|
} |
|
35
|
|
|
36
|
write_file a.txt "one\n" |
|
37
|
write_file b.txt "bee\n" |
|
38
|
write_file keep.txt "kept\n" |
|
39
|
fossil add a.txt b.txt keep.txt |
|
40
|
fossil commit -m first |
|
41
|
set manifestV1 [manifest_ci first] |
|
42
|
write_file a.txt "one\ntwo\n" |
|
43
|
fossil mv --hard b.txt c.txt |
|
44
|
fossil commit -m second |
|
45
|
set manifestV2 [manifest_ci second] |
|
46
|
|
|
47
|
############################################################################### |
|
48
|
# Two check-ins compared by name. |
|
49
|
|
|
50
|
fossil diff --from $manifestV1 --to $manifestV2 |
|
51
|
test manifest-diff-versions {$CODE == 0 && [string match "*+two*" $RESULT]} |
|
52
|
|
|
53
|
# A name that is not a check-in is refused before it is looked up. |
|
54
|
set manifestFile [fossil_sql "SELECT uuid FROM blob, mlink |
|
55
|
WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$manifestV2') |
|
56
|
AND fnid=(SELECT fnid FROM filename WHERE name='a.txt')"] |
|
57
|
fossil diff --from $manifestFile --to $manifestV2 -expectError |
|
58
|
test manifest-diff-not-checkin {$CODE != 0 |
|
59
|
&& [string match "*cannot resolve name*" $RESULT]} |
|
60
|
|
|
61
|
############################################################################### |
|
62
|
# The /dir and /tree pages of a check-in. |
|
63
|
|
|
64
|
set manifestReply [manifest_get "/dir?ci=$manifestV2"] |
|
65
|
test manifest-dir {[string match "*c.txt*" $manifestReply] |
|
66
|
&& ![string match "*b.txt*" $manifestReply]} |
|
67
|
set manifestReply [manifest_get "/tree?ci=$manifestV2"] |
|
68
|
test manifest-tree {[string match "*keep.txt*" $manifestReply]} |
|
69
|
set manifestReply [manifest_get "/dir?ci=$manifestFile"] |
|
70
|
test manifest-dir-not-checkin {[string match "HTTP/1.0 400 *" $manifestReply]} |
|
71
|
|
|
72
|
############################################################################### |
|
73
|
# A delta manifest names only what changed since its baseline. A file it |
|
74
|
# does not name is read from the baseline, and one it deletes is gone. |
|
75
|
|
|
76
|
fossil settings forbid-delta-manifests 0 |
|
77
|
write_file a.txt "one\ntwo\nthree\n" |
|
78
|
fossil commit --delta -m third |
|
79
|
set manifestV3 [manifest_ci third] |
|
80
|
fossil artifact $manifestV3 |
|
81
|
test manifest-delta-made {[string match "B *" $RESULT]} |
|
82
|
fossil cat keep.txt -r $manifestV3 |
|
83
|
test_eq manifest-delta-from-baseline [string trim $RESULT] kept |
|
84
|
fossil rm --hard keep.txt |
|
85
|
fossil commit --delta -m fourth |
|
86
|
set manifestV4 [manifest_ci fourth] |
|
87
|
fossil artifact $manifestV4 |
|
88
|
test manifest-delta-deletes {[string match "B *" $RESULT] |
|
89
|
&& [regexp {\nF keep.txt\n} $RESULT]} |
|
90
|
fossil cat keep.txt -r $manifestV4 -expectError |
|
91
|
test manifest-delta-deleted-gone {$CODE != 0} |
|
92
|
fossil diff --from $manifestV2 --to $manifestV4 |
|
93
|
test manifest-diff-delta {$CODE == 0 && [string match "*+three*" $RESULT] |
|
94
|
&& [string match "*DELETED keep.txt*" $RESULT]} |
|
95
|
|
|
96
|
# The JSON form of a delta manifest names its baseline in a B field. |
|
97
|
test_eq manifest-delta-json-baseline [fossil_sql "SELECT |
|
98
|
json_extract(artifact_to_json('$manifestV3'), '\$.B') = |
|
99
|
(SELECT uuid FROM blob WHERE rid=(SELECT baseid FROM plink |
|
100
|
WHERE cid=(SELECT rid FROM blob WHERE uuid='$manifestV3')))"] 1 |
|
101
|
|
|
102
|
############################################################################### |
|
103
|
# With case-sensitive off, a file named in another letter case is the file |
|
104
|
# the check-in holds. test-ci-mini does not commit without --wet-run. |
|
105
|
|
|
106
|
write_file a.txt "one\ntwo\nthree\nfour\n" |
|
107
|
fossil settings case-sensitive off |
|
108
|
fossil test-ci-mini -m case -r trunk --as A.TXT a.txt |
|
109
|
test manifest-case-insensitive-found {$CODE == 0} |
|
110
|
fossil cat NONE.TXT -r $manifestV3 -expectError |
|
111
|
test manifest-case-insensitive-missing-in-delta {$CODE != 0 |
|
112
|
&& [string match "*NONE.TXT*" $RESULT]} |
|
113
|
fossil settings case-sensitive on |
|
114
|
fossil test-ci-mini -m case -r trunk --as A.TXT a.txt -expectError |
|
115
|
test manifest-case-sensitive-new {$CODE != 0} |
|
116
|
test_eq manifest-case-no-commit [manifest_ci case] "" |
|
117
|
|
|
118
|
############################################################################### |
|
119
|
# artifact_to_json() describes every kind of artifact as JSON. |
|
120
|
|
|
121
|
write_file run.sh "#!/bin/sh\n" |
|
122
|
fossil add run.sh |
|
123
|
fossil commit -m exec |
|
124
|
file attributes run.sh -permissions 0755 |
|
125
|
fossil commit -m exec-set |
|
126
|
fossil branch new side $manifestV2 |
|
127
|
fossil update side |
|
128
|
test manifest-json-update-side {$CODE == 0} |
|
129
|
write_file side.txt "side\n" |
|
130
|
fossil add side.txt |
|
131
|
fossil commit -m side |
|
132
|
fossil update trunk |
|
133
|
fossil merge --cherrypick side |
|
134
|
fossil commit -m cherrypick |
|
135
|
fossil tag add release $manifestV1 |
|
136
|
fossil tag add level $manifestV2 2 |
|
137
|
write_file page.wiki "A page.\n" |
|
138
|
fossil wiki create Page page.wiki |
|
139
|
fossil wiki create Note page.wiki --technote 2026-01-01T00:00:00 |
|
140
|
fossil attachment add Page c.txt |
|
141
|
test manifest-json-attachment {$CODE == 0} |
|
142
|
fossil ticket add title "A ticket" status Open |
|
143
|
fossil test-create-clusters |
|
144
|
|
|
145
|
set manifestJson [fossil_sql "SELECT count(*), sum(json_valid(j)) |
|
146
|
FROM (SELECT artifact_to_json(rid) AS j FROM blob WHERE size>=0) |
|
147
|
WHERE j IS NOT NULL"] |
|
148
|
set manifestJson [split $manifestJson |] |
|
149
|
test manifest-json-all-valid \ |
|
150
|
{[lindex $manifestJson 0] == [lindex $manifestJson 1] |
|
151
|
&& [lindex $manifestJson 0] > 10} |
|
152
|
|
|
153
|
foreach {manifestName manifestPath manifestWant} [list \ |
|
154
|
exec "\$.F\[2\].perm" x \ |
|
155
|
rename "\$.F\[1\].rename" b.txt \ |
|
156
|
cherrypick "\$.Q\[0\].type" + \ |
|
157
|
tag "\$.T\[0\].name" sym-release \ |
|
158
|
] { |
|
159
|
switch $manifestName { |
|
160
|
exec { set manifestOf [manifest_ci exec-set] } |
|
161
|
rename { set manifestOf $manifestV2 } |
|
162
|
cherrypick { set manifestOf [manifest_ci cherrypick] } |
|
163
|
tag { |
|
164
|
set manifestOf [fossil_sql "SELECT uuid FROM blob, tagxref, tag |
|
165
|
WHERE blob.rid=srcid AND tag.tagid=tagxref.tagid |
|
166
|
AND tagname='sym-release'"] |
|
167
|
} |
|
168
|
} |
|
169
|
test_eq manifest-json-$manifestName [fossil_sql \ |
|
170
|
"SELECT json_extract(artifact_to_json('$manifestOf'), '$manifestPath')"] \ |
|
171
|
$manifestWant |
|
172
|
} |
|
173
|
|
|
174
|
# Content that is not an artifact gives NULL, and a value that is neither |
|
175
|
# a record number nor a name is an error. |
|
176
|
test_eq manifest-json-not-artifact [fossil_sql \ |
|
177
|
"SELECT artifact_to_json('$manifestFile') IS NULL"] 1 |
|
178
|
fossil sql "SELECT artifact_to_json(1.5)" -expectError |
|
179
|
test manifest-json-bad-argument \ |
|
180
|
{[string match "*Expecting one argument*" $RESULT]} |
|
181
|
|
|
182
|
############################################################################### |
|
183
|
# "tag add --root" puts a tag on the first check-in of the line that a |
|
184
|
# check-in is on, and says so when it only tries. |
|
185
|
|
|
186
|
set manifestRoot [fossil_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid |
|
187
|
FROM plink WHERE pid NOT IN (SELECT cid FROM plink) LIMIT 1)"] |
|
188
|
fossil tag add --root --dry-run rooted $manifestV2 |
|
189
|
test manifest-tag-root-dry-run {$CODE == 0 && [string match \ |
|
190
|
"*to root ancestor [string range $manifestRoot 0 9]*" $RESULT]} |
|
191
|
test_eq manifest-tag-root-dry-run-no-tag [fossil_sql "SELECT count(*) |
|
192
|
FROM tag WHERE tagname='sym-rooted'"] 0 |
|
193
|
fossil tag add --root rooted $manifestV2 |
|
194
|
test manifest-tag-root {$CODE == 0} |
|
195
|
test_eq manifest-tag-root-on-first [fossil_sql "SELECT tagtype FROM tagxref, |
|
196
|
tag, blob WHERE tag.tagid=tagxref.tagid AND tagname='sym-rooted' |
|
197
|
AND tagxref.rid=blob.rid AND tagxref.srcid>0 |
|
198
|
AND uuid='$manifestRoot'"] 2 |
|
199
|
fossil tag list --root $manifestV2 |
|
200
|
test manifest-tag-root-list {$CODE == 0 && [string match "*rooted*" $RESULT]} |
|
201
|
|
|
202
|
############################################################################### |
|
203
|
# A repository that has lost the content of the baseline of a delta |
|
204
|
# manifest: a file the delta manifest leaves to its baseline cannot be |
|
205
|
# read. |
|
206
|
|
|
207
|
fossil artifact $manifestV3 |
|
208
|
regexp {^B ([0-9a-f]+)} $RESULT manifestAll manifestBase |
|
209
|
file copy [file join [pwd] .rep.fossil] lost-base.fossil |
|
210
|
fossil sql -R lost-base.fossil "DELETE FROM delta WHERE rid=(SELECT rid |
|
211
|
FROM blob WHERE uuid='$manifestBase'); |
|
212
|
UPDATE blob SET size=-1, content=NULL WHERE uuid='$manifestBase'" |
|
213
|
fossil cat keep.txt -r $manifestV3 -R lost-base.fossil -expectError |
|
214
|
test manifest-lost-baseline {$CODE != 0 |
|
215
|
&& [string match "*cannot access baseline manifest*" $RESULT]} |
|
216
|
|
|
217
|
# A repository that has lost the content of a check-in: the check of all |
|
218
|
# artifacts reports it, and the check-in cannot be compared. |
|
219
|
file copy [file join [pwd] .rep.fossil] lost-ci.fossil |
|
220
|
fossil sql -R lost-ci.fossil "DELETE FROM delta WHERE rid=(SELECT rid |
|
221
|
FROM blob WHERE uuid='$manifestV1'); |
|
222
|
UPDATE blob SET size=-1, content=NULL WHERE uuid='$manifestV1'" |
|
223
|
fossil test-parse-all-blobs -R lost-ci.fossil |
|
224
|
test manifest-lost-checkin-reported {$CODE == 0 |
|
225
|
&& [regexp {\d+ ERROR: } $RESULT] |
|
226
|
&& [string match "*tests with 1 errors*" $RESULT]} |
|
227
|
fossil diff --from $manifestV1 --to $manifestV2 -R lost-ci.fossil -expectError |
|
228
|
test manifest-lost-checkin-diff {$CODE != 0 |
|
229
|
&& [string match "*cannot parse manifest for check-in*" $RESULT]} |
|
230
|
|
|
231
|
############################################################################### |
|
232
|
# A signed check-in whose parent is not in the repository. With the |
|
233
|
# manifest setting on, the manifest file of a checkout of it carries a |
|
234
|
# line that keeps the file from being an artifact, placed before the |
|
235
|
# signature. "prev" names nothing that can be compared. |
|
236
|
|
|
237
|
write_file signed-body.txt "C signed |
|
238
|
D 2026-05-01T10:00:00.000 |
|
239
|
F a.txt $manifestFile |
|
240
|
P [string repeat 3a 20] |
|
241
|
U alice |
|
242
|
" |
|
243
|
fossil md5sum signed-body.txt |
|
244
|
set manifestSigned "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n" |
|
245
|
append manifestSigned [read_file signed-body.txt] "Z [lindex $RESULT 0]\n" |
|
246
|
append manifestSigned "-----BEGIN PGP SIGNATURE-----\nabc\n" |
|
247
|
append manifestSigned "-----END PGP SIGNATURE-----\n" |
|
248
|
write_file signed.txt $manifestSigned |
|
249
|
fossil test-content-put --crosslink signed.txt |
|
250
|
set manifestSignedHash [manifest_ci signed] |
|
251
|
test manifest-signed-stored {$CODE == 0 && $manifestSignedHash ne ""} |
|
252
|
fossil settings manifest on |
|
253
|
fossil update $manifestSignedHash |
|
254
|
test manifest-signed-update {$CODE == 0} |
|
255
|
test manifest-signed-manifest-file {[string match \ |
|
256
|
[join [list \ |
|
257
|
"*\nZ *\n" \ |
|
258
|
"# Remove this line to create a well-formed Fossil " \ |
|
259
|
"manifest.\n-----BEGIN PGP SIGNATURE-----\n*"] ""] \ |
|
260
|
[read_file manifest]]} |
|
261
|
fossil diff --from prev --to current -expectError |
|
262
|
test manifest-prev-not-checkin {$CODE != 0 |
|
263
|
&& [string match "*no such check-in: prev*" $RESULT]} |
|
264
|
fossil settings manifest off |
|
265
|
fossil update trunk |
|
266
|
test manifest-signed-update-back {$CODE == 0} |
|
267
|
|
|
268
|
############################################################################### |
|
269
|
|
|
270
|
test_cleanup |
|
271
|
|