|
1
|
# |
|
2
|
# Copyright (c) 2015 D. Richard Hipp |
|
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
|
# Author contact information: |
|
13
|
# [email protected] |
|
14
|
# http://www.hwaci.com/drh/ |
|
15
|
# |
|
16
|
############################################################################ |
|
17
|
# |
|
18
|
# Tests for the "amend" command. |
|
19
|
# |
|
20
|
|
|
21
|
proc artifact_from_timeline {res var} { |
|
22
|
upvar $var artid |
|
23
|
regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $res m artid |
|
24
|
} |
|
25
|
|
|
26
|
proc manifest_comment {comment} { |
|
27
|
string map [list { } {\\s} \n {\\n} \r {\\r}] $comment |
|
28
|
} |
|
29
|
|
|
30
|
proc uuid_from_commit {res var} { |
|
31
|
upvar $var HASH |
|
32
|
regexp {^New_Version: ([0-9a-f]{40})[0-9a-f]*$} $res m HASH |
|
33
|
} |
|
34
|
|
|
35
|
proc uuid_from_branch {res var} { |
|
36
|
upvar $var HASH |
|
37
|
regexp {^New branch: ([0-9a-f]{40})[0-9a-f]*$} $res m HASH |
|
38
|
} |
|
39
|
|
|
40
|
proc uuid_from_checkout {var} { |
|
41
|
global RESULT |
|
42
|
upvar $var HASH |
|
43
|
fossil status |
|
44
|
regexp {checkout:\s+([0-9a-f]{40})[0-9a-f]*} $RESULT m HASH |
|
45
|
} |
|
46
|
|
|
47
|
# Make sure we are not in an open repository and initialize new repository |
|
48
|
test_setup |
|
49
|
|
|
50
|
######################################## |
|
51
|
# Setup: Add file and commit # |
|
52
|
######################################## |
|
53
|
|
|
54
|
if {![uuid_from_checkout HASHINIT]} { |
|
55
|
test amend-checkout-failure false |
|
56
|
test_cleanup_then_return |
|
57
|
} |
|
58
|
write_file datafile "data" |
|
59
|
fossil add datafile |
|
60
|
fossil commit -m "c1" |
|
61
|
if {![uuid_from_commit $RESULT HASH]} { |
|
62
|
test amend-setup-failure false |
|
63
|
test_cleanup_then_return |
|
64
|
} |
|
65
|
|
|
66
|
######################################## |
|
67
|
# Test: -branch # |
|
68
|
######################################## |
|
69
|
set HASHB HASHB |
|
70
|
write_file datafile "data.file" |
|
71
|
fossil commit -m "c2" |
|
72
|
if {![uuid_from_commit $RESULT HASHB]} { |
|
73
|
test amend-branch.setup false |
|
74
|
} |
|
75
|
fossil amend $HASHB -branch amended-branch |
|
76
|
test amend-branch-1.1 {[regexp {tags:\s+amended-branch} $RESULT]} |
|
77
|
fossil branch ls |
|
78
|
test amend-branch-1.2 {[string first "* amended-branch" $RESULT] != -1} |
|
79
|
fossil tag list |
|
80
|
test amend-branch-1.3 {[string first amended-branch $RESULT] != -1} |
|
81
|
fossil tag list --raw $HASHB |
|
82
|
test amend-branch-1.4 {[string first "branch=amended-branch" $RESULT] != -1} |
|
83
|
test amend-branch-1.5 {[string first "sym-amended-branch" $RESULT] != -1} |
|
84
|
fossil timeline -n 1 |
|
85
|
test amend-branch-1.6 {[string match {*Move*to*branch*amended-branch*} $RESULT]} |
|
86
|
|
|
87
|
######################################## |
|
88
|
# Test: -bgcolor # |
|
89
|
######################################## |
|
90
|
set tc 0 |
|
91
|
foreach {color result} { |
|
92
|
0 0 |
|
93
|
a a |
|
94
|
abcdef #abcdef |
|
95
|
abc123 #abc123 |
|
96
|
123efg 123efg |
|
97
|
abcdefg abcdefg |
|
98
|
abcdeg abcdeg |
|
99
|
blue blue |
|
100
|
acf #acf |
|
101
|
123 #123 |
|
102
|
#1234 #1234 |
|
103
|
1234 1234 |
|
104
|
123456 #123456 |
|
105
|
} { |
|
106
|
incr tc |
|
107
|
fossil amend $HASH -bgcolor $color |
|
108
|
test amend-bgcolor-1.$tc.a {[string match "*hash:*$HASH*" $RESULT]} |
|
109
|
fossil tag list --raw $HASH |
|
110
|
test amend-bgcolor-1.$tc.b {[string first "bgcolor=$result" $RESULT] != -1} |
|
111
|
fossil timeline -n 1 |
|
112
|
test amend-bgcolor-1.$tc.c { |
|
113
|
[string match "*Change*background*color*to*\"$result\"*" $RESULT] |
|
114
|
} |
|
115
|
if {[artifact_from_timeline $RESULT artid]} { |
|
116
|
fossil artifact $artid |
|
117
|
test amend-bgcolor-1.$tc.d { |
|
118
|
[string match "*T +bgcolor $HASH* $result*" $RESULT] |
|
119
|
} |
|
120
|
} else { |
|
121
|
if {$VERBOSE} { protOut "No artifact found in timeline output" } |
|
122
|
test amend-bgcolor-1.$tc.d false |
|
123
|
} |
|
124
|
} |
|
125
|
fossil amend $HASH -bgcolor {} |
|
126
|
test amend-bgcolor-2.1 {[string match "*hash:*$HASH*" $RESULT]} |
|
127
|
fossil tag list --raw $HASH |
|
128
|
test amend-bgcolor-2.2 { |
|
129
|
[string first "bgcolor=" $RESULT] == -1 && |
|
130
|
[string first "bgcolor" $RESULT] != -1 |
|
131
|
} |
|
132
|
fossil timeline -n 1 |
|
133
|
test amend-bgcolor-2.3 {[string match "*Cancel*background*color.*" $RESULT]} |
|
134
|
if {[artifact_from_timeline $RESULT artid]} { |
|
135
|
fossil artifact $artid |
|
136
|
test amend-bgcolor-2.4 {[string match "*T -bgcolor $HASH*" $RESULT]} |
|
137
|
} else { |
|
138
|
if {$VERBOSE} { protOut "No artifact found in timeline output" } |
|
139
|
test amend-bgcolor-2.4 false |
|
140
|
} |
|
141
|
|
|
142
|
######################################## |
|
143
|
# Test: -branchcolor # |
|
144
|
######################################## |
|
145
|
set HASH2 HASH2 |
|
146
|
fossil branch new brclr $HASH |
|
147
|
if {![uuid_from_branch $RESULT HASH2]} { |
|
148
|
test amend-branchcolor.setup false |
|
149
|
} |
|
150
|
fossil update $HASH2 |
|
151
|
fossil amend $HASH2 -branchcolor yellow |
|
152
|
test amend-branchcolor-1.1 {[string match "*hash:*$HASH2*" $RESULT]} |
|
153
|
fossil tag ls --raw $HASH2 |
|
154
|
test amend-branchcolor-1.2 {[string first "bgcolor=yellow" $RESULT] != -1} |
|
155
|
fossil timeline -n 1 |
|
156
|
test amend-branchcolor-1.3 { |
|
157
|
[string match {*Change*branch*background*color*to*"yellow".*} $RESULT] |
|
158
|
} |
|
159
|
if {[regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $RESULT m artid]} { |
|
160
|
fossil artifact $artid |
|
161
|
test amend-branchcolor-1.4 { |
|
162
|
[string match "*T \*bgcolor $HASH2* yellow*" $RESULT] |
|
163
|
} |
|
164
|
} else { |
|
165
|
if {$VERBOSE} { protOut "No artifact found in timeline output" } |
|
166
|
test amend-branchcolor-1.4 false |
|
167
|
} |
|
168
|
|
|
169
|
set HASHN HASHN |
|
170
|
write_file datafile "brclr" |
|
171
|
fossil commit -m "brclr" |
|
172
|
if {![uuid_from_commit $RESULT HASHN]} { |
|
173
|
test amend-branchcolor-propagating.setup false |
|
174
|
} |
|
175
|
write_file datafile "bc1" |
|
176
|
fossil commit -m "mc1" |
|
177
|
write_file datafile "bc2" |
|
178
|
fossil commit -m "mc2" |
|
179
|
fossil amend $HASHN -branchcolor deadbe |
|
180
|
test amend-branchcolor-2.1 {[string match "*hash:*$HASHN*" $RESULT]} |
|
181
|
fossil tag ls --raw current |
|
182
|
test amend-branchcolor-2.2 {[string first "bgcolor=#deadbe" $RESULT] != -1} |
|
183
|
fossil timeline -n 1 |
|
184
|
test amend-branchcolor-2.3 { |
|
185
|
[string match {*Change*branch*background*color*to*"#deadbe".*} $RESULT] |
|
186
|
} |
|
187
|
|
|
188
|
######################################## |
|
189
|
# Test: -author # |
|
190
|
######################################## |
|
191
|
fossil amend $HASH -author author-test |
|
192
|
test amend-author-1.1 {[string match {*comment:*(user:*author-test)*} $RESULT]} |
|
193
|
fossil tag ls --raw $HASH |
|
194
|
test amend-author-1.2 {[string first "user=author-test" $RESULT] != -1} |
|
195
|
fossil timeline -n 1 |
|
196
|
test amend-author-1.3 {[string match {*Change*user*to*"author-test".*} $RESULT]} |
|
197
|
|
|
198
|
######################################## |
|
199
|
# Test: -date # |
|
200
|
######################################## |
|
201
|
set timestamp [clock scan yesterday] |
|
202
|
set date [clock format $timestamp -format "%Y-%m-%d" -gmt 1] |
|
203
|
set time [clock format $timestamp -format "%H:%M:%S" -gmt 1] |
|
204
|
set datetime "$date $time" |
|
205
|
fossil amend $HASHINIT -date $datetime |
|
206
|
test amend-date-1.1 {[string match "*hash:*$HASHINIT*$datetime*" $RESULT]} |
|
207
|
fossil tag ls --raw $HASHINIT |
|
208
|
test amend-date-1.2 {[string first "date=$datetime" $RESULT] != -1} |
|
209
|
fossil timeline -n 1 |
|
210
|
test amend-date-1.3 {[string match "*Timestamp*$date*$time*" $RESULT]} |
|
211
|
set badformats { |
|
212
|
"%+" |
|
213
|
"%Y-%m-%d %H:%M%:%S %Z" |
|
214
|
"%d/%m/%Y %H:%M%:%S %Z" |
|
215
|
"%d/%m/%Y %H:%M%:%S" |
|
216
|
"%d/%m/%Y" |
|
217
|
} |
|
218
|
set sc 0 |
|
219
|
foreach badformat $badformats { |
|
220
|
incr sc |
|
221
|
set datetime [clock format $timestamp -format $badformat -gmt 1] |
|
222
|
fossil amend $HASHINIT -date $datetime -expectError |
|
223
|
test amend-date-2.$sc {[string first "YYYY-MM-DD HH:MM:SS" $RESULT] != -1} |
|
224
|
} |
|
225
|
|
|
226
|
######################################## |
|
227
|
# Test: -hide # |
|
228
|
######################################## |
|
229
|
set HASHH HASHH |
|
230
|
fossil revert |
|
231
|
fossil update trunk |
|
232
|
fossil branch new tohide current |
|
233
|
if {![uuid_from_branch $RESULT HASHH]} { |
|
234
|
test amend-hide-setup false |
|
235
|
} |
|
236
|
fossil amend $HASHH -hide |
|
237
|
test amend-hide-1.1 {[string match "*hash:*$HASHH*" $RESULT]} |
|
238
|
fossil tag ls --raw $HASHH |
|
239
|
test amend-hide-1.2 {[string first "hidden" $RESULT] != -1} |
|
240
|
fossil timeline -n 1 |
|
241
|
test amend-hide-1.3 {[string match {*Add*propagating*"hidden".*} $RESULT]} |
|
242
|
|
|
243
|
######################################## |
|
244
|
# Test: -close # |
|
245
|
######################################## |
|
246
|
set HASHC HASHC |
|
247
|
fossil branch new cllf $HASH |
|
248
|
if {![uuid_from_branch $RESULT HASHC]} { |
|
249
|
test amend-close.setup false |
|
250
|
} |
|
251
|
fossil update $HASHC |
|
252
|
fossil amend $HASHC -close |
|
253
|
test amend-close-1.1.a {[string match "*hash:*$HASHC*" $RESULT]} |
|
254
|
test amend-close-1.1.b { |
|
255
|
[string match "*comment:*Create*new*branch*named*\"cllf\"*" $RESULT] |
|
256
|
} |
|
257
|
fossil tag ls --raw $HASHC |
|
258
|
test amend-close-1.2 {[string first "closed" $RESULT] != -1} |
|
259
|
fossil timeline -n 1 |
|
260
|
test amend-close-1.3 {[string match {*Mark*"Closed".*} $RESULT]} |
|
261
|
write_file datafile "cllf" |
|
262
|
fossil commit -m "should fail" -expectError |
|
263
|
test amend-close-2 {[string first "closed leaf" $RESULT] != -1} |
|
264
|
|
|
265
|
set HASH3 HASH3 |
|
266
|
fossil revert |
|
267
|
fossil update trunk |
|
268
|
write_file datafile "cb" |
|
269
|
fossil commit -m "closed-branch" --branch "closebranch" |
|
270
|
if {![uuid_from_commit $RESULT HASH3]} { |
|
271
|
test amend-close-3.setup false |
|
272
|
} |
|
273
|
write_file datafile "b1" |
|
274
|
fossil commit -m "m1" |
|
275
|
write_file datafile "b2" |
|
276
|
fossil commit -m "m2" |
|
277
|
fossil amend $HASH3 --close |
|
278
|
test amend-close-3.1 {[string match "*hash:*$HASH3*" $RESULT]} |
|
279
|
fossil tag ls --raw current |
|
280
|
test amend-close-3.2 {[string first "closed" $RESULT] != -1} |
|
281
|
fossil timeline -n 1 |
|
282
|
test amend-close-3.3 { |
|
283
|
[string match "*Add*propagating*\"closed\".*" $RESULT] |
|
284
|
} |
|
285
|
write_file datafile "changed" |
|
286
|
fossil commit -m "should fail" -expectError |
|
287
|
test amend-close-3.4 {[string first "closed leaf" $RESULT] != -1} |
|
288
|
|
|
289
|
######################################## |
|
290
|
# Test: -tag/-cancel # |
|
291
|
######################################## |
|
292
|
set tagtests { |
|
293
|
tagged tagged |
|
294
|
{000000 lower Upper alpha 0alpha} {000000 0alpha Upper alpha lower} |
|
295
|
} |
|
296
|
set tc 0 |
|
297
|
foreach {tagt result} $tagtests { |
|
298
|
incr tc |
|
299
|
set tags {} |
|
300
|
set cancels {} |
|
301
|
set t1exp [join $result ", "] |
|
302
|
set t2exp "*" |
|
303
|
set t3exp "*" |
|
304
|
set t5exp "*" |
|
305
|
foreach tag $tagt { |
|
306
|
lappend tags -tag $tag |
|
307
|
lappend cancels -cancel $tag |
|
308
|
} |
|
309
|
foreach res $result { |
|
310
|
append t3exp "Add*tag*\"$res\".*" |
|
311
|
append t5exp "Cancel*tag*\"$res\".*" |
|
312
|
} |
|
313
|
foreach res [lsort -nocase $result] { |
|
314
|
append t2exp "sym-$res*" |
|
315
|
} |
|
316
|
eval fossil amend $HASH $tags |
|
317
|
test amend-tag-$tc.1 {[string match "*hash:*$HASH*tags:*$t1exp*" $RESULT]} |
|
318
|
fossil tag ls --raw $HASH |
|
319
|
test amend-tag-$tc.2 {[string match $t2exp $RESULT]} |
|
320
|
fossil timeline -n 1 |
|
321
|
test amend-tag-$tc.3 {[string match $t3exp $RESULT]} |
|
322
|
eval fossil amend $HASH $cancels |
|
323
|
test amend-tag-$tc.4 {![string match "*tags:*$t1exp*" $RESULT]} |
|
324
|
fossil timeline -n 1 |
|
325
|
test amend-tag-$tc.5 {[string match $t5exp $RESULT]} |
|
326
|
} |
|
327
|
|
|
328
|
######################################## |
|
329
|
# Test: -comment # |
|
330
|
######################################## |
|
331
|
proc prep-test {comment content} { |
|
332
|
global HASH RESULT |
|
333
|
|
|
334
|
fossil revert |
|
335
|
fossil update trunk |
|
336
|
write_file datafile $comment |
|
337
|
fossil commit -m $content |
|
338
|
if {![uuid_from_commit $RESULT HASH]} { |
|
339
|
set HASH "" |
|
340
|
} |
|
341
|
} |
|
342
|
|
|
343
|
proc test-comment {name HASH comment} { |
|
344
|
global VERBOSE RESULT |
|
345
|
|
|
346
|
test amend-comment-$name.1 { |
|
347
|
[string match "*hash:*$HASH*comment:*$comment*" $RESULT] |
|
348
|
} |
|
349
|
fossil timeline -n 1 |
|
350
|
if {[artifact_from_timeline $RESULT artid]} { |
|
351
|
fossil artifact $artid |
|
352
|
test amend-comment-$name.2 { |
|
353
|
[string match "*T +comment $HASH* *[manifest_comment $comment]*" $RESULT] |
|
354
|
} |
|
355
|
} else { |
|
356
|
if {$VERBOSE} { protOut "No artifact found in timeline output: $RESULT" } |
|
357
|
test amend-comment-$name.2 false |
|
358
|
} |
|
359
|
fossil timeline -n 1 |
|
360
|
test amend-comment-$name.3 { |
|
361
|
[string match "*[short_uuid $HASH]*Edit*check-in*comment.*" $RESULT] |
|
362
|
} |
|
363
|
fossil info $HASH |
|
364
|
test amend-comment-$name.4 { |
|
365
|
[string match "*hash:*$HASH*comment:*$comment*" $RESULT] |
|
366
|
} |
|
367
|
} |
|
368
|
|
|
369
|
prep-test "revision 1" "revision 1" |
|
370
|
fossil amend $HASH -comment "revised revision 1" |
|
371
|
test-comment 1 $HASH "revised revision 1" |
|
372
|
|
|
373
|
prep-test "revision 2" "revision 2" |
|
374
|
fossil amend $HASH -m "revised revision 2 with -m" |
|
375
|
test-comment 2 $HASH "revised revision 2 with -m" |
|
376
|
|
|
377
|
prep-test "revision 3" "revision 3" |
|
378
|
write_file commitmsg "revision 3 revised" |
|
379
|
fossil amend $HASH -message-file commitmsg |
|
380
|
test-comment 3 $HASH "revision 3 revised" |
|
381
|
|
|
382
|
prep-test "revision 4" "revision 4" |
|
383
|
write_file commitmsg "revision 4 revised with -M" |
|
384
|
fossil amend $HASH -M commitmsg |
|
385
|
test-comment 4 $HASH "revision 4 revised with -M" |
|
386
|
|
|
387
|
prep-test "final comment" "final content" |
|
388
|
if {[catch {exec which ed} result] == 0} { |
|
389
|
fossil settings editor "ed -s" |
|
390
|
set comment "interactive edited comment" |
|
391
|
fossil_maybe_answer "a\n$comment\n.\nw\nq\n" amend $HASH --edit-comment |
|
392
|
test-comment 5 $HASH $comment |
|
393
|
} |
|
394
|
|
|
395
|
######################################## |
|
396
|
# Test: NULL hash # |
|
397
|
######################################## |
|
398
|
fossil amend {} -close -expectError |
|
399
|
test amend-null-uuid {$CODE && [string first "no such check-in" $RESULT] != -1} |
|
400
|
|
|
401
|
############################################################################### |
|
402
|
|
|
403
|
test_cleanup |
|
404
|
|