Debian Codegraph @

tests/test-lfs.t

raw
1 #require no-chg
2
3 $ hg init requirements
4 $ cd requirements
5
6 # LFS not loaded by default.
7
8 $ hg config extensions
9 [1]
10
11 # Adding lfs to requires file will auto-load lfs extension.
12
13 $ echo lfs >> .hg/requires
14 $ hg config extensions
15 extensions.lfs=
16
17 # But only if there is no config entry for the extension already.
18
19 $ cat > .hg/hgrc << EOF
20 > [extensions]
21 > lfs=!
22 > EOF
23
24 $ hg config extensions
25 abort: repository requires features unknown to this Mercurial: lfs
26 (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
27 [255]
28
29 $ cat > .hg/hgrc << EOF
30 > [extensions]
31 > lfs=
32 > EOF
33
34 $ hg config extensions
35 extensions.lfs=
36
37 $ cat > .hg/hgrc << EOF
38 > [extensions]
39 > lfs = missing.py
40 > EOF
41
42 $ hg config extensions
43 \*\*\* failed to import extension "lfs" from missing.py: [Errno *] $ENOENT$: 'missing.py' (glob)
44 abort: repository requires features unknown to this Mercurial: lfs
45 (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
46 [255]
47
48 $ cd ..
49
50 # Initial setup
51
52 $ cat >> $HGRCPATH << EOF
53 > [extensions]
54 > lfs=
55 > [lfs]
56 > # Test deprecated config
57 > threshold=1000B
58 > EOF
59
60 $ LONG=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
61
62 # Prepare server and enable extension
63 $ hg init server
64 $ hg clone -q server client
65 $ cd client
66
67 # Commit small file
68 $ echo s > smallfile
69 $ echo '**.py = LF' > .hgeol
70 $ hg --config lfs.track='"size(\">1000B\")"' commit -Aqm "add small file"
71 hg: parse error: unsupported file pattern: size(">1000B")
72 (paths must be prefixed with "path:")
73 [10]
74 $ hg --config lfs.track='size(">1000B")' commit -Aqm "add small file"
75
76 # Commit large file
77 $ echo $LONG > largefile
78 $ hg debugrequires | grep lfs
79 [1]
80 $ hg commit --traceback -Aqm "add large file"
81 $ hg debugrequires | grep lfs
82 lfs
83
84 # Ensure metadata is stored
85 $ hg debugdata largefile 0
86 version https://git-lfs.github.com/spec/v1
87 oid sha256:f11e77c257047a398492d8d6cb9f6acf3aa7c4384bb23080b43546053e183e4b
88 size 1501
89 x-is-binary 0
90
91 # Check the blobstore is populated
92 $ find .hg/store/lfs/objects | sort
93 .hg/store/lfs/objects
94 .hg/store/lfs/objects/f1
95 .hg/store/lfs/objects/f1/1e77c257047a398492d8d6cb9f6acf3aa7c4384bb23080b43546053e183e4b
96
97 # Check the blob stored contains the actual contents of the file
98 $ cat .hg/store/lfs/objects/f1/1e77c257047a398492d8d6cb9f6acf3aa7c4384bb23080b43546053e183e4b
99 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
100
101 # Push changes to the server
102
103 $ hg push
104 pushing to $TESTTMP/server
105 searching for changes
106 abort: lfs.url needs to be configured
107 [255]
108
109 $ cat >> $HGRCPATH << EOF
110 > [lfs]
111 > url=file:$TESTTMP/dummy-remote/
112 > EOF
113
114 Push to a local non-lfs repo with the extension enabled will add the
115 lfs requirement
116
117 $ hg debugrequires -R $TESTTMP/server/ | grep lfs
118 [1]
119 $ hg push -v | grep -E -v '^(uncompressed| )'
120 pushing to $TESTTMP/server
121 searching for changes
122 lfs: found f11e77c257047a398492d8d6cb9f6acf3aa7c4384bb23080b43546053e183e4b in the local lfs store
123 2 changesets found
124 adding changesets
125 adding manifests
126 adding file changes
127 calling hook pretxnchangegroup.lfs: hgext.lfs.checkrequireslfs
128 added 2 changesets with 3 changes to 3 files
129 $ hg debugrequires -R $TESTTMP/server/ | grep lfs
130 lfs
131
132 # Unknown URL scheme
133
134 $ hg push --config lfs.url=ftp://foobar
135 abort: lfs: unknown url scheme: ftp
136 [255]
137
138 $ cd ../
139
140 # Initialize new client (not cloning) and setup extension
141 $ hg init client2
142 $ cd client2
143 $ cat >> .hg/hgrc <<EOF
144 > [paths]
145 > default = $TESTTMP/server
146 > EOF
147
148 # Pull from server
149
150 Pulling a local lfs repo into a local non-lfs repo with the extension
151 enabled adds the lfs requirement
152
153 $ hg debugrequires | grep lfs || true
154 $ hg debugrequires -R $TESTTMP/server/ | grep lfs
155 lfs
156 $ hg pull default
157 pulling from $TESTTMP/server
158 requesting all changes
159 adding changesets
160 adding manifests
161 adding file changes
162 added 2 changesets with 3 changes to 3 files
163 new changesets 0ead593177f7:b88141481348
164 (run 'hg update' to get a working copy)
165 $ hg debugrequires | grep lfs
166 lfs
167 $ hg debugrequires -R $TESTTMP/server/ | grep lfs
168 lfs
169
170 # Check the blobstore is not yet populated
171 $ [ -d .hg/store/lfs/objects ]
172 [1]
173
174 # Update to the last revision containing the large file
175 $ hg update
176 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
177
178 # Check the blobstore has been populated on update
179 $ find .hg/store/lfs/objects | sort
180 .hg/store/lfs/objects
181 .hg/store/lfs/objects/f1
182 .hg/store/lfs/objects/f1/1e77c257047a398492d8d6cb9f6acf3aa7c4384bb23080b43546053e183e4b
183
184 # Check the contents of the file are fetched from blobstore when requested
185 $ hg cat -r . largefile
186 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB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CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
191
192 $ cd ..
193
194 # Check rename, and switch between large and small files
195
196 $ hg init repo3
197 $ cd repo3
198 $ cat >> .hg/hgrc << EOF
199 > [lfs]
200 > track=size(">10B")
201 > EOF
202
203 $ echo LONGER-THAN-TEN-BYTES-WILL-TRIGGER-LFS > large
204 $ echo SHORTER > small
205 $ hg add . -q
206 $ hg commit -m 'commit with lfs content'
207
208 $ hg files -r . 'set:added()'
209 large
210 small
211 $ hg files -r . 'set:added() & lfs()'
212 large
213
214 $ hg mv large l
215 $ hg mv small s
216 $ hg status 'set:removed()'
217 R large
218 R small
219 $ hg status 'set:removed() & lfs()'
220 R large
221 $ hg commit -m 'renames'
222
223 $ hg cat -r . l -T '{rawdata}\n'
224 version https://git-lfs.github.com/spec/v1
225 oid sha256:66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e
226 size 39
227 x-hg-copy large
228 x-hg-copyrev 2c531e0992ff3107c511b53cb82a91b6436de8b2
229 x-is-binary 0
230
231
232 $ hg files -r . 'set:copied()'
233 l
234 s
235 $ hg files -r . 'set:copied() & lfs()'
236 l
237 $ hg status --change . 'set:removed()'
238 R large
239 R small
240 $ hg status --change . 'set:removed() & lfs()'
241 R large
242
243 $ echo SHORT > l
244 $ echo BECOME-LARGER-FROM-SHORTER > s
245 $ hg commit -m 'large to small, small to large'
246
247 $ echo 1 >> l
248 $ echo 2 >> s
249 $ hg commit -m 'random modifications'
250
251 $ echo RESTORE-TO-BE-LARGE > l
252 $ echo SHORTER > s
253 $ hg commit -m 'switch large and small again'
254
255 # Test lfs_files template
256
257 $ hg log -r 'all()' -T '{rev} {join(lfs_files, ", ")}\n'
258 0 large
259 1 l, large
260 2 s
261 3 s
262 4 l
263
264 # Push and pull the above repo
265
266 $ hg --cwd .. init repo4
267 $ hg push ../repo4
268 pushing to ../repo4
269 searching for changes
270 adding changesets
271 adding manifests
272 adding file changes
273 added 5 changesets with 10 changes to 4 files
274
275 $ hg --cwd .. init repo5
276 $ hg --cwd ../repo5 pull ../repo3
277 pulling from ../repo3
278 requesting all changes
279 adding changesets
280 adding manifests
281 adding file changes
282 added 5 changesets with 10 changes to 4 files
283 new changesets fd47a419c4f7:5adf850972b9
284 (run 'hg update' to get a working copy)
285
286 $ cd ..
287
288 # Test clone
289
290 $ hg init repo6
291 $ cd repo6
292 $ cat >> .hg/hgrc << EOF
293 > [lfs]
294 > track=size(">30B")
295 > EOF
296
297 $ echo LARGE-BECAUSE-IT-IS-MORE-THAN-30-BYTES > large
298 $ echo SMALL > small
299 $ hg commit -Aqm 'create a lfs file' large small
300 $ hg debuglfsupload -r 'all()' -v
301 lfs: found 8e92251415339ae9b148c8da89ed5ec665905166a1ab11b09dca8fad83344738 in the local lfs store
302
303 $ cd ..
304
305 $ hg clone repo6 repo7
306 updating to branch default
307 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
308 $ cd repo7
309 $ cat large
310 LARGE-BECAUSE-IT-IS-MORE-THAN-30-BYTES
311 $ cat small
312 SMALL
313
314 $ cd ..
315
316 $ hg --config extensions.share= share repo7 sharedrepo
317 updating working directory
318 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
319 $ hg debugrequires -R sharedrepo/ | grep lfs
320 lfs
321
322 # Test rename and status
323
324 $ hg init repo8
325 $ cd repo8
326 $ cat >> .hg/hgrc << EOF
327 > [lfs]
328 > track=size(">10B")
329 > EOF
330
331 $ echo THIS-IS-LFS-BECAUSE-10-BYTES > a1
332 $ echo SMALL > a2
333 $ hg commit -m a -A a1 a2
334 $ hg status
335 $ hg mv a1 b1
336 $ hg mv a2 a1
337 $ hg mv b1 a2
338 $ hg commit -m b
339 $ hg status
340 >>> with open('a2', 'wb') as f:
341 ... f.write(b'\1\nSTART-WITH-HG-FILELOG-METADATA') and None
342 >>> with open('a1', 'wb') as f:
343 ... f.write(b'\1\nMETA\n') and None
344 $ hg commit -m meta
345 $ hg status
346 $ hg log -T '{rev}: {file_copies} | {file_dels} | {file_adds}\n'
347 2: | |
348 1: a1 (a2)a2 (a1) | |
349 0: | | a1 a2
350
351 $ for n in a1 a2; do
352 > for r in 0 1 2; do
353 > printf '\n%s @ %s\n' $n $r
354 > hg debugdata $n $r
355 > done
356 > done
357
358 a1 @ 0
359 version https://git-lfs.github.com/spec/v1
360 oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
361 size 29
362 x-is-binary 0
363
364 a1 @ 1
365 \x01 (esc)
366 copy: a2
367 copyrev: 50470ad23cf937b1f4b9f80bfe54df38e65b50d9
368 \x01 (esc)
369 SMALL
370
371 a1 @ 2
372 \x01 (esc)
373 \x01 (esc)
374 \x01 (esc)
375 META
376
377 a2 @ 0
378 SMALL
379
380 a2 @ 1
381 version https://git-lfs.github.com/spec/v1
382 oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
383 size 29
384 x-hg-copy a1
385 x-hg-copyrev be23af27908a582af43e5cda209a5a9b319de8d4
386 x-is-binary 0
387
388 a2 @ 2
389 version https://git-lfs.github.com/spec/v1
390 oid sha256:876dadc86a8542f9798048f2c47f51dbf8e4359aed883e8ec80c5db825f0d943
391 size 32
392 x-is-binary 0
393
394 # Verify commit hashes include rename metadata
395
396 $ hg log -T '{rev}:{node|short} {desc}\n'
397 2:0fae949de7fa meta
398 1:9cd6bdffdac0 b
399 0:7f96794915f7 a
400
401 $ cd ..
402
403 # Test bundle
404
405 $ hg init repo9
406 $ cd repo9
407 $ cat >> .hg/hgrc << EOF
408 > [lfs]
409 > track=size(">10B")
410 > [diff]
411 > git=1
412 > EOF
413
414 $ for i in 0 single two three 4; do
415 > echo 'THIS-IS-LFS-'$i > a
416 > hg commit -m a-$i -A a
417 > done
418
419 $ hg update 2 -q
420 $ echo 'THIS-IS-LFS-2-CHILD' > a
421 $ hg commit -m branching -q
422
423 $ hg bundle --base 1 bundle.hg -v
424 lfs: found 5ab7a3739a5feec94a562d070a14f36dba7cad17e5484a4a89eea8e5f3166888 in the local lfs store
425 lfs: found a9c7d1cd6ce2b9bbdf46ed9a862845228717b921c089d0d42e3bcaed29eb612e in the local lfs store
426 lfs: found f693890c49c409ec33673b71e53f297681f76c1166daf33b2ad7ebf8b1d3237e in the local lfs store
427 lfs: found fda198fea753eb66a252e9856915e1f5cddbe41723bd4b695ece2604ad3c9f75 in the local lfs store
428 4 changesets found
429 uncompressed size of bundle content:
430 * (changelog) (glob)
431 * (manifests) (glob)
432 * a (glob)
433 $ hg --config extensions.strip= strip -r 2 --no-backup --force -q
434 $ hg -R bundle.hg log -p -T '{rev} {desc}\n' a
435 5 branching
436 diff --git a/a b/a
437 --- a/a
438 +++ b/a
439 @@ -1,1 +1,1 @@
440 -THIS-IS-LFS-two
441 +THIS-IS-LFS-2-CHILD
442
443 4 a-4
444 diff --git a/a b/a
445 --- a/a
446 +++ b/a
447 @@ -1,1 +1,1 @@
448 -THIS-IS-LFS-three
449 +THIS-IS-LFS-4
450
451 3 a-three
452 diff --git a/a b/a
453 --- a/a
454 +++ b/a
455 @@ -1,1 +1,1 @@
456 -THIS-IS-LFS-two
457 +THIS-IS-LFS-three
458
459 2 a-two
460 diff --git a/a b/a
461 --- a/a
462 +++ b/a
463 @@ -1,1 +1,1 @@
464 -THIS-IS-LFS-single
465 +THIS-IS-LFS-two
466
467 1 a-single
468 diff --git a/a b/a
469 --- a/a
470 +++ b/a
471 @@ -1,1 +1,1 @@
472 -THIS-IS-LFS-0
473 +THIS-IS-LFS-single
474
475 0 a-0
476 diff --git a/a b/a
477 new file mode 100644
478 --- /dev/null
479 +++ b/a
480 @@ -0,0 +1,1 @@
481 +THIS-IS-LFS-0
482
483 $ hg bundle -R bundle.hg --base 1 bundle-again.hg -q
484 $ hg -R bundle-again.hg log -p -T '{rev} {desc}\n' a
485 5 branching
486 diff --git a/a b/a
487 --- a/a
488 +++ b/a
489 @@ -1,1 +1,1 @@
490 -THIS-IS-LFS-two
491 +THIS-IS-LFS-2-CHILD
492
493 4 a-4
494 diff --git a/a b/a
495 --- a/a
496 +++ b/a
497 @@ -1,1 +1,1 @@
498 -THIS-IS-LFS-three
499 +THIS-IS-LFS-4
500
501 3 a-three
502 diff --git a/a b/a
503 --- a/a
504 +++ b/a
505 @@ -1,1 +1,1 @@
506 -THIS-IS-LFS-two
507 +THIS-IS-LFS-three
508
509 2 a-two
510 diff --git a/a b/a
511 --- a/a
512 +++ b/a
513 @@ -1,1 +1,1 @@
514 -THIS-IS-LFS-single
515 +THIS-IS-LFS-two
516
517 1 a-single
518 diff --git a/a b/a
519 --- a/a
520 +++ b/a
521 @@ -1,1 +1,1 @@
522 -THIS-IS-LFS-0
523 +THIS-IS-LFS-single
524
525 0 a-0
526 diff --git a/a b/a
527 new file mode 100644
528 --- /dev/null
529 +++ b/a
530 @@ -0,0 +1,1 @@
531 +THIS-IS-LFS-0
532
533 $ cd ..
534
535 # Test isbinary
536
537 $ hg init repo10
538 $ cd repo10
539 $ cat >> .hg/hgrc << EOF
540 > [extensions]
541 > lfs=
542 > [lfs]
543 > track=all()
544 > EOF
545 $ "$PYTHON" <<'EOF'
546 > def write(path, content):
547 > with open(path, 'wb') as f:
548 > f.write(content)
549 > write('a', b'\0\0')
550 > write('b', b'\1\n')
551 > write('c', b'\1\n\0')
552 > write('d', b'xx')
553 > EOF
554 $ hg add a b c d
555 $ hg diff --stat
556 a | Bin
557 b | 1 +
558 c | Bin
559 d | 1 +
560 4 files changed, 2 insertions(+), 0 deletions(-)
561 $ hg commit -m binarytest
562 $ cat > $TESTTMP/dumpbinary.py << EOF
563 > from mercurial.utils import (
564 > stringutil,
565 > )
566 > def reposetup(ui, repo):
567 > for n in (b'a', b'b', b'c', b'd'):
568 > ui.write((b'%s: binary=%s\n')
569 > % (n, stringutil.pprint(repo[b'.'][n].isbinary())))
570 > EOF
571 $ hg --config extensions.dumpbinary=$TESTTMP/dumpbinary.py id --trace
572 a: binary=True
573 b: binary=False
574 c: binary=True
575 d: binary=False
576 b55353847f02 tip
577
578 Binary blobs don't need to be present to be skipped in filesets. (And their
579 absence doesn't cause an abort.)
580
581 $ rm .hg/store/lfs/objects/96/a296d224f285c67bee93c30f8a309157f0daa35dc5b87e410b78630a09cfc7
582 $ rm .hg/store/lfs/objects/92/f76135a4baf4faccb8586a60faf830c2bdfce147cefa188aaf4b790bd01b7e
583
584 $ hg files --debug -r . 'set:eol("unix")' --config 'experimental.lfs.disableusercache=True'
585 lfs: found c04b5bb1a5b2eb3e9cd4805420dba5a9d133da5b7adeeafb5474c4adae9faa80 in the local lfs store
586 2 b
587 lfs: found 5dde896887f6754c9b15bfe3a441ae4806df2fde94001311e08bf110622e0bbe in the local lfs store
588
589 $ hg files --debug -r . 'set:binary()' --config 'experimental.lfs.disableusercache=True'
590 2 a
591 3 c
592
593 $ cd ..
594
595 # Test fctx.cmp fastpath - diff without LFS blobs
596
597 $ hg init repo12
598 $ cd repo12
599 $ cat >> .hg/hgrc <<EOF
600 > [lfs]
601 > threshold=1
602 > EOF
603 $ cat > ../patch.diff <<EOF
604 > # HG changeset patch
605 > 2
606 >
607 > diff --git a/a b/a
608 > old mode 100644
609 > new mode 100755
610 > EOF
611
612 $ for i in 1 2 3; do
613 > cp ../repo10/a a
614 > if [ $i = 3 ]; then
615 > # make a content-only change
616 > hg import -q --bypass ../patch.diff
617 > hg update -q
618 > rm ../patch.diff
619 > else
620 > echo $i >> a
621 > hg commit -m $i -A a
622 > fi
623 > done
624 $ [ -d .hg/store/lfs/objects ]
625
626 $ cd ..
627
628 $ hg clone repo12 repo13 --noupdate
629 $ cd repo13
630 $ hg log --removed -p a -T '{desc}\n' --config diff.nobinary=1 --git
631 2
632 diff --git a/a b/a
633 old mode 100644
634 new mode 100755
635
636 2
637 diff --git a/a b/a
638 Binary file a has changed
639
640 1
641 diff --git a/a b/a
642 new file mode 100644
643 Binary file a has changed
644
645 $ [ -d .hg/store/lfs/objects ]
646 [1]
647
648 $ cd ..
649
650 # Test filter
651
652 $ hg init repo11
653 $ cd repo11
654 $ cat >> .hg/hgrc << EOF
655 > [lfs]
656 > track=(**.a & size(">5B")) | (**.b & !size(">5B"))
657 > | (**.c & "path:d" & !"path:d/c.c") | size(">10B")
658 > EOF
659
660 $ mkdir a
661 $ echo aaaaaa > a/1.a
662 $ echo a > a/2.a
663 $ echo aaaaaa > 1.b
664 $ echo a > 2.b
665 $ echo a > 1.c
666 $ mkdir d
667 $ echo a > d/c.c
668 $ echo a > d/d.c
669 $ echo aaaaaaaaaaaa > x
670 $ hg add . -q
671 $ hg commit -m files
672
673 $ for p in a/1.a a/2.a 1.b 2.b 1.c d/c.c d/d.c x; do
674 > if hg debugdata $p 0 2>&1 | grep git-lfs >/dev/null; then
675 > echo "${p}: is lfs"
676 > else
677 > echo "${p}: not lfs"
678 > fi
679 > done
680 a/1.a: is lfs
681 a/2.a: not lfs
682 1.b: not lfs
683 2.b: is lfs
684 1.c: not lfs
685 d/c.c: not lfs
686 d/d.c: is lfs
687 x: is lfs
688
689 $ cd ..
690
691 # Verify the repos
692
693 $ cat > $TESTTMP/dumpflog.py << EOF
694 > # print raw revision sizes, flags, and hashes for certain files
695 > import hashlib
696 > from mercurial.node import short
697 > from mercurial import (
698 > pycompat,
699 > revlog,
700 > )
701 > from mercurial.utils import (
702 > procutil,
703 > stringutil,
704 > )
705 > def hash(rawtext):
706 > h = hashlib.sha512()
707 > h.update(rawtext)
708 > return pycompat.sysbytes(h.hexdigest()[:4])
709 > def reposetup(ui, repo):
710 > # these 2 files are interesting
711 > for name in [b'l', b's']:
712 > fl = repo.file(name)
713 > if len(fl) == 0:
714 > continue
715 > sizes = [fl._revlog.rawsize(i) for i in fl]
716 > texts = [fl.rawdata(i) for i in fl]
717 > flags = [int(fl._revlog.flags(i)) for i in fl]
718 > hashes = [hash(t) for t in texts]
719 > procutil.stdout.write(b' %s: rawsizes=%r flags=%r hashes=%s\n'
720 > % (name, sizes, flags, stringutil.pprint(hashes)))
721 > EOF
722
723 $ for i in client client2 server repo3 repo4 repo5 repo6 repo7 repo8 repo9 \
724 > repo10; do
725 > echo 'repo:' $i
726 > hg --cwd $i verify --config extensions.dumpflog=$TESTTMP/dumpflog.py -q
727 > done
728 repo: client
729 repo: client2
730 repo: server
731 repo: repo3
732 l: rawsizes=[211, 6, 8, 141] flags=[8192, 0, 0, 8192] hashes=['d2b8', '948c', 'cc88', '724d']
733 s: rawsizes=[74, 141, 141, 8] flags=[0, 8192, 8192, 0] hashes=['3c80', 'fce0', '874a', '826b']
734 repo: repo4
735 l: rawsizes=[211, 6, 8, 141] flags=[8192, 0, 0, 8192] hashes=['d2b8', '948c', 'cc88', '724d']
736 s: rawsizes=[74, 141, 141, 8] flags=[0, 8192, 8192, 0] hashes=['3c80', 'fce0', '874a', '826b']
737 repo: repo5
738 l: rawsizes=[211, 6, 8, 141] flags=[8192, 0, 0, 8192] hashes=['d2b8', '948c', 'cc88', '724d']
739 s: rawsizes=[74, 141, 141, 8] flags=[0, 8192, 8192, 0] hashes=['3c80', 'fce0', '874a', '826b']
740 repo: repo6
741 repo: repo7
742 repo: repo8
743 repo: repo9
744 repo: repo10
745
746 repo13 doesn't have any cached lfs files and its source never pushed its
747 files. Therefore, the files don't exist in the remote store. Use the files in
748 the user cache.
749
750 $ test -d $TESTTMP/repo13/.hg/store/lfs/objects
751 [1]
752
753 $ hg --config extensions.share= share repo13 repo14
754 updating working directory
755 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
756 $ hg -R repo14 -q verify
757
758 $ hg clone repo13 repo15
759 updating to branch default
760 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
761 $ hg -R repo15 -q verify
762
763 If the source repo doesn't have the blob (maybe it was pulled or cloned with
764 --noupdate), the blob is still accessible via the global cache to send to the
765 remote store.
766
767 $ rm -rf $TESTTMP/repo15/.hg/store/lfs
768 $ hg init repo16
769 $ hg -R repo15 push repo16
770 pushing to repo16
771 searching for changes
772 adding changesets
773 adding manifests
774 adding file changes
775 added 3 changesets with 2 changes to 1 files
776 $ hg -R repo15 -q verify
777
778 Test damaged file scenarios. (This also damages the usercache because of the
779 hardlinks.)
780
781 $ echo 'damage' >> repo5/.hg/store/lfs/objects/66/100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e
782
783 Repo with damaged lfs objects in any revision will fail verification.
784
785 $ hg -R repo5 verify
786 checking changesets
787 checking manifests
788 crosschecking files in changesets and manifests
789 checking files
790 l@1: unpacking 46a2f24864bc: integrity check failed on l:0
791 large@0: unpacking 2c531e0992ff: integrity check failed on large:0
792 not checking dirstate because of previous errors
793 checked 5 changesets with 10 changes to 4 files
794 2 integrity errors encountered!
795 (first damaged changeset appears to be 0)
796 [1]
797
798 Updates work after cloning a damaged repo, if the damaged lfs objects aren't in
799 the update destination. Those objects won't be added to the new repo's store
800 because they aren't accessed.
801
802 $ hg clone -v repo5 fromcorrupt
803 updating to branch default
804 resolving manifests
805 getting l
806 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the usercache
807 getting s
808 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
809 $ test -f fromcorrupt/.hg/store/lfs/objects/66/100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e
810 [1]
811
812 Verify will not try to download lfs blobs, if told not to process lfs content.
813 The extension makes sure that the filelog.renamed() path is taken on a missing
814 blob, and the output shows that it isn't fetched.
815
816 $ cat > $TESTTMP/lfsrename.py <<EOF
817 > import sys
818 >
819 > from mercurial import (
820 > exthelper,
821 > pycompat,
822 > )
823 >
824 > from hgext.lfs import (
825 > pointer,
826 > wrapper,
827 > )
828 >
829 > eh = exthelper.exthelper()
830 > uisetup = eh.finaluisetup
831 >
832 > @eh.wrapfunction(wrapper, 'filelogrenamed')
833 > def filelogrenamed(orig, orig1, self, node):
834 > ret = orig(orig1, self, node)
835 > if wrapper._islfs(self._revlog, node) and ret:
836 > rawtext = self._revlog.rawdata(node)
837 > metadata = pointer.deserialize(rawtext)
838 > print('lfs blob %s renamed %s -> %s'
839 > % (pycompat.sysstr(metadata[b'oid']),
840 > pycompat.sysstr(ret[0]),
841 > pycompat.fsdecode(self._revlog.filename)))
842 > sys.stdout.flush()
843 > return ret
844 > EOF
845
846 $ hg -R fromcorrupt --config lfs.usercache=emptycache verify -v --no-lfs \
847 > --config extensions.x=$TESTTMP/lfsrename.py
848 repository uses revlog format 1
849 checking changesets
850 checking manifests
851 crosschecking files in changesets and manifests
852 checking files
853 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the local lfs store
854 lfs blob sha256:66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e renamed large -> l
855 checking dirstate
856 checked 5 changesets with 10 changes to 4 files
857
858 Verify will not try to download lfs blobs, if told not to by the config option
859
860 $ hg -R fromcorrupt --config lfs.usercache=emptycache verify -v \
861 > --config verify.skipflags=8192 \
862 > --config extensions.x=$TESTTMP/lfsrename.py
863 repository uses revlog format 1
864 checking changesets
865 checking manifests
866 crosschecking files in changesets and manifests
867 checking files
868 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the local lfs store
869 lfs blob sha256:66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e renamed large -> l
870 checking dirstate
871 checked 5 changesets with 10 changes to 4 files
872
873 Verify will copy/link all lfs objects into the local store that aren't already
874 present. Bypass the corrupted usercache to show that verify works when fed by
875 the (uncorrupted) remote store.
876
877 $ hg -R fromcorrupt --config lfs.usercache=emptycache verify -v
878 repository uses revlog format 1
879 checking changesets
880 checking manifests
881 crosschecking files in changesets and manifests
882 checking files
883 lfs: adding 66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e to the usercache
884 lfs: found 66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e in the local lfs store
885 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the local lfs store
886 lfs: found 66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e in the local lfs store
887 lfs: adding 89b6070915a3d573ff3599d1cda305bc5e38549b15c4847ab034169da66e1ca8 to the usercache
888 lfs: found 89b6070915a3d573ff3599d1cda305bc5e38549b15c4847ab034169da66e1ca8 in the local lfs store
889 lfs: adding b1a6ea88da0017a0e77db139a54618986e9a2489bee24af9fe596de9daac498c to the usercache
890 lfs: found b1a6ea88da0017a0e77db139a54618986e9a2489bee24af9fe596de9daac498c in the local lfs store
891 checking dirstate
892 checked 5 changesets with 10 changes to 4 files
893
894 Verify will not copy/link a corrupted file from the usercache into the local
895 store, and poison it. (The verify with a good remote now works.)
896
897 $ rm -r fromcorrupt/.hg/store/lfs/objects/66/100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e
898 $ hg -R fromcorrupt verify -v
899 repository uses revlog format 1
900 checking changesets
901 checking manifests
902 crosschecking files in changesets and manifests
903 checking files
904 l@1: unpacking 46a2f24864bc: integrity check failed on l:0
905 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the local lfs store
906 large@0: unpacking 2c531e0992ff: integrity check failed on large:0
907 lfs: found 89b6070915a3d573ff3599d1cda305bc5e38549b15c4847ab034169da66e1ca8 in the local lfs store
908 lfs: found b1a6ea88da0017a0e77db139a54618986e9a2489bee24af9fe596de9daac498c in the local lfs store
909 not checking dirstate because of previous errors
910 checked 5 changesets with 10 changes to 4 files
911 2 integrity errors encountered!
912 (first damaged changeset appears to be 0)
913 [1]
914 $ hg -R fromcorrupt --config lfs.usercache=emptycache verify -v
915 repository uses revlog format 1
916 checking changesets
917 checking manifests
918 crosschecking files in changesets and manifests
919 checking files
920 lfs: found 66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e in the usercache
921 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the local lfs store
922 lfs: found 66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e in the local lfs store
923 lfs: found 89b6070915a3d573ff3599d1cda305bc5e38549b15c4847ab034169da66e1ca8 in the local lfs store
924 lfs: found b1a6ea88da0017a0e77db139a54618986e9a2489bee24af9fe596de9daac498c in the local lfs store
925 checking dirstate
926 checked 5 changesets with 10 changes to 4 files
927
928 Damaging a file required by the update destination fails the update.
929
930 $ echo 'damage' >> $TESTTMP/dummy-remote/22/f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b
931 $ hg --config lfs.usercache=emptycache clone -v repo5 fromcorrupt2
932 updating to branch default
933 resolving manifests
934 abort: corrupt remote lfs object: 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b
935 [255]
936
937 A corrupted lfs blob is not transferred from a file://remotestore to the
938 usercache or local store.
939
940 $ test -f emptycache/22/f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b
941 [1]
942 $ test -f fromcorrupt2/.hg/store/lfs/objects/22/f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b
943 [1]
944
945 $ hg -R fromcorrupt2 verify
946 checking changesets
947 checking manifests
948 crosschecking files in changesets and manifests
949 checking files
950 l@1: unpacking 46a2f24864bc: integrity check failed on l:0
951 large@0: unpacking 2c531e0992ff: integrity check failed on large:0
952 not checking dirstate because of previous errors
953 checked 5 changesets with 10 changes to 4 files
954 2 integrity errors encountered!
955 (first damaged changeset appears to be 0)
956 [1]
957
958 Corrupt local files are not sent upstream. (The alternate dummy remote
959 avoids the corrupt lfs object in the original remote.)
960
961 $ mkdir $TESTTMP/dummy-remote2
962 $ hg init dest
963 $ hg -R fromcorrupt2 --config lfs.url=file:///$TESTTMP/dummy-remote2 push -v dest
964 pushing to dest
965 searching for changes
966 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the local lfs store
967 abort: detected corrupt lfs object: 66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e
968 (run hg verify)
969 [255]
970
971 $ hg -R fromcorrupt2 --config lfs.url=file:///$TESTTMP/dummy-remote2 verify -v
972 repository uses revlog format 1
973 checking changesets
974 checking manifests
975 crosschecking files in changesets and manifests
976 checking files
977 l@1: unpacking 46a2f24864bc: integrity check failed on l:0
978 lfs: found 22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b in the local lfs store
979 large@0: unpacking 2c531e0992ff: integrity check failed on large:0
980 lfs: found 89b6070915a3d573ff3599d1cda305bc5e38549b15c4847ab034169da66e1ca8 in the local lfs store
981 lfs: found b1a6ea88da0017a0e77db139a54618986e9a2489bee24af9fe596de9daac498c in the local lfs store
982 not checking dirstate because of previous errors
983 checked 5 changesets with 10 changes to 4 files
984 2 integrity errors encountered!
985 (first damaged changeset appears to be 0)
986 [1]
987
988 $ cat $TESTTMP/dummy-remote2/22/f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b | $TESTDIR/f --sha256
989 sha256=22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b
990 $ cat fromcorrupt2/.hg/store/lfs/objects/22/f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b | $TESTDIR/f --sha256
991 sha256=22f66a3fc0b9bf3f012c814303995ec07099b3a9ce02a7af84b5970811074a3b
992 $ test -f $TESTTMP/dummy-remote2/66/100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e
993 [1]
994
995 Accessing a corrupt file will complain
996
997 $ hg --cwd fromcorrupt2 cat -r 0 large
998 abort: integrity check failed on large:0
999 [50]
1000
1001 lfs -> normal -> lfs round trip conversions are possible. The 'none()'
1002 predicate on the command line will override whatever is configured globally and
1003 locally, and ensures everything converts to a regular file. For lfs -> normal,
1004 there's no 'lfs' destination repo requirement. For normal -> lfs, there is.
1005
1006 $ hg --config extensions.convert= --config 'lfs.track=none()' \
1007 > convert repo8 convert_normal
1008 initializing destination convert_normal repository
1009 scanning source...
1010 sorting...
1011 converting...
1012 2 a
1013 1 b
1014 0 meta
1015 $ hg debugrequires -R convert_normal | grep 'lfs'
1016 [1]
1017 $ hg --cwd convert_normal cat a1 -r 0 -T '{rawdata}'
1018 THIS-IS-LFS-BECAUSE-10-BYTES
1019
1020 $ hg --config extensions.convert= --config lfs.threshold=10B \
1021 > convert convert_normal convert_lfs
1022 initializing destination convert_lfs repository
1023 scanning source...
1024 sorting...
1025 converting...
1026 2 a
1027 1 b
1028 0 meta
1029
1030 $ hg --cwd convert_lfs cat -r 0 a1 -T '{rawdata}'
1031 version https://git-lfs.github.com/spec/v1
1032 oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
1033 size 29
1034 x-is-binary 0
1035 $ hg --cwd convert_lfs debugdata a1 0
1036 version https://git-lfs.github.com/spec/v1
1037 oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
1038 size 29
1039 x-is-binary 0
1040 $ hg --cwd convert_lfs log -r 0 -T "{lfs_files % '{lfspointer % '{key}={value}\n'}'}"
1041 version=https://git-lfs.github.com/spec/v1
1042 oid=sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
1043 size=29
1044 x-is-binary=0
1045 $ hg --cwd convert_lfs log -r 0 \
1046 > -T '{lfs_files % "{get(lfspointer, "oid")}\n"}{lfs_files % "{lfspointer.oid}\n"}'
1047 sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
1048 sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
1049 $ hg --cwd convert_lfs log -r 0 -T '{lfs_files % "{lfspointer}\n"}'
1050 version=https://git-lfs.github.com/spec/v1 oid=sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024 size=29 x-is-binary=0
1051 $ hg --cwd convert_lfs \
1052 > log -r 'all()' -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}'
1053 0: a1: 5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
1054 1: a2: 5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
1055 2: a2: 876dadc86a8542f9798048f2c47f51dbf8e4359aed883e8ec80c5db825f0d943
1056
1057 $ hg debugrequires -R convert_lfs | grep 'lfs'
1058 lfs
1059
1060 The hashes in all stages of the conversion are unchanged.
1061
1062 $ hg -R repo8 log -T '{node|short}\n'
1063 0fae949de7fa
1064 9cd6bdffdac0
1065 7f96794915f7
1066 $ hg -R convert_normal log -T '{node|short}\n'
1067 0fae949de7fa
1068 9cd6bdffdac0
1069 7f96794915f7
1070 $ hg -R convert_lfs log -T '{node|short}\n'
1071 0fae949de7fa
1072 9cd6bdffdac0
1073 7f96794915f7
1074
1075 This convert is trickier, because it contains deleted files (via `hg mv`)
1076
1077 $ hg --config extensions.convert= --config lfs.threshold=1000M \
1078 > convert repo3 convert_normal2
1079 initializing destination convert_normal2 repository
1080 scanning source...
1081 sorting...
1082 converting...
1083 4 commit with lfs content
1084 3 renames
1085 2 large to small, small to large
1086 1 random modifications
1087 0 switch large and small again
1088 $ hg debugrequires -R convert_normal2 | grep 'lfs'
1089 [1]
1090 $ hg --cwd convert_normal2 debugdata large 0
1091 LONGER-THAN-TEN-BYTES-WILL-TRIGGER-LFS
1092
1093 $ hg --config extensions.convert= --config lfs.threshold=10B \
1094 > convert convert_normal2 convert_lfs2
1095 initializing destination convert_lfs2 repository
1096 scanning source...
1097 sorting...
1098 converting...
1099 4 commit with lfs content
1100 3 renames
1101 2 large to small, small to large
1102 1 random modifications
1103 0 switch large and small again
1104 $ hg debugrequires -R convert_lfs2 | grep 'lfs'
1105 lfs
1106 $ hg --cwd convert_lfs2 debugdata large 0
1107 version https://git-lfs.github.com/spec/v1
1108 oid sha256:66100b384bf761271b407d79fc30cdd0554f3b2c5d944836e936d584b88ce88e
1109 size 39
1110 x-is-binary 0
1111
1112 Committing deleted files works:
1113
1114 $ hg init $TESTTMP/repo-del
1115 $ cd $TESTTMP/repo-del
1116 $ echo 1 > A
1117 $ hg commit -m 'add A' -A A
1118 $ hg rm A
1119 $ hg commit -m 'rm A'
1120
1121 Bad .hglfs files will block the commit with a useful message
1122
1123 $ cat > .hglfs << EOF
1124 > [track]
1125 > **.test = size(">5B")
1126 > bad file ... no commit
1127 > EOF
1128
1129 $ echo x > file.txt
1130 $ hg ci -Aqm 'should fail'
1131 config error at .hglfs:3: bad file ... no commit
1132 [30]
1133
1134 $ cat > .hglfs << EOF
1135 > [track]
1136 > **.test = size(">5B")
1137 > ** = nonexistent()
1138 > EOF
1139
1140 $ hg ci -Aqm 'should fail'
1141 abort: parse error in .hglfs: unknown identifier: nonexistent
1142 [255]
1143
1144 '**' works out to mean all files.
1145
1146 $ cat > .hglfs << EOF
1147 > [track]
1148 > path:.hglfs = none()
1149 > **.test = size(">5B")
1150 > **.exclude = none()
1151 > ** = size(">10B")
1152 > EOF
1153
1154 The LFS policy takes effect without tracking the .hglfs file
1155
1156 $ echo 'largefile' > lfs.test
1157 $ echo '012345678901234567890' > nolfs.exclude
1158 $ echo '01234567890123456' > lfs.catchall
1159 $ hg add *
1160 $ hg ci -qm 'before add .hglfs'
1161 $ hg log -r . -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}\n'
1162 2: lfs.catchall: d4ec46c2869ba22eceb42a729377432052d9dd75d82fc40390ebaadecee87ee9
1163 lfs.test: 5489e6ced8c36a7b267292bde9fd5242a5f80a7482e8f23fa0477393dfaa4d6c
1164
1165 The .hglfs file works when tracked
1166
1167 $ echo 'largefile2' > lfs.test
1168 $ echo '012345678901234567890a' > nolfs.exclude
1169 $ echo '01234567890123456a' > lfs.catchall
1170 $ hg ci -Aqm 'after adding .hglfs'
1171 $ hg log -r . -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}\n'
1172 3: lfs.catchall: 31f43b9c62b540126b0ad5884dc013d21a61c9329b77de1fceeae2fc58511573
1173 lfs.test: 8acd23467967bc7b8cc5a280056589b0ba0b17ff21dbd88a7b6474d6290378a6
1174
1175 The LFS policy stops when the .hglfs is gone
1176
1177 $ mv .hglfs .hglfs_
1178 $ echo 'largefile3' > lfs.test
1179 $ echo '012345678901234567890abc' > nolfs.exclude
1180 $ echo '01234567890123456abc' > lfs.catchall
1181 $ hg ci -qm 'file test' -X .hglfs
1182 $ hg log -r . -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}\n'
1183 4:
1184
1185 $ mv .hglfs_ .hglfs
1186 $ echo '012345678901234567890abc' > lfs.test
1187 $ hg ci -m 'back to lfs'
1188 $ hg rm lfs.test
1189 $ hg ci -qm 'remove lfs'
1190
1191 {lfs_files} will list deleted files too
1192
1193 $ hg log -T "{lfs_files % '{rev} {file}: {lfspointer.oid}\n'}"
1194 6 lfs.test:
1195 5 lfs.test: sha256:43f8f41171b6f62a6b61ba4ce98a8a6c1649240a47ebafd43120aa215ac9e7f6
1196 3 lfs.catchall: sha256:31f43b9c62b540126b0ad5884dc013d21a61c9329b77de1fceeae2fc58511573
1197 3 lfs.test: sha256:8acd23467967bc7b8cc5a280056589b0ba0b17ff21dbd88a7b6474d6290378a6
1198 2 lfs.catchall: sha256:d4ec46c2869ba22eceb42a729377432052d9dd75d82fc40390ebaadecee87ee9
1199 2 lfs.test: sha256:5489e6ced8c36a7b267292bde9fd5242a5f80a7482e8f23fa0477393dfaa4d6c
1200
1201 $ hg log -r 'file("set:lfs()")' -T '{rev} {join(lfs_files, ", ")}\n'
1202 2 lfs.catchall, lfs.test
1203 3 lfs.catchall, lfs.test
1204 5 lfs.test
1205 6 lfs.test
1206
1207 $ cd ..
1208
1209 Unbundling adds a requirement to a non-lfs repo, if necessary.
1210
1211 $ hg bundle -R $TESTTMP/repo-del -qr 0 --base null nolfs.hg
1212 $ hg bundle -R convert_lfs2 -qr tip --base null lfs.hg
1213 $ hg init unbundle
1214 $ hg pull -R unbundle -q nolfs.hg
1215 $ hg debugrequires -R unbundle | grep lfs
1216 [1]
1217 $ hg pull -R unbundle -q lfs.hg
1218 $ hg debugrequires -R unbundle | grep lfs
1219 lfs
1220
1221 $ hg init no_lfs
1222 $ cat >> no_lfs/.hg/hgrc <<EOF
1223 > [extensions]
1224 > lfs=!
1225 > EOF
1226 $ cp -R no_lfs no_lfs2
1227
1228 Pushing from a local lfs repo to a local repo without an lfs requirement and
1229 with lfs disabled, fails.
1230
1231 $ hg push -R convert_lfs2 no_lfs
1232 pushing to no_lfs
1233 abort: required features are not supported in the destination: lfs
1234 [255]
1235 $ hg debugrequires -R no_lfs/ | grep lfs
1236 [1]
1237
1238 Pulling from a local lfs repo to a local repo without an lfs requirement and
1239 with lfs disabled, fails.
1240
1241 $ hg pull -R no_lfs2 convert_lfs2
1242 pulling from convert_lfs2
1243 abort: required features are not supported in the destination: lfs
1244 [255]
1245 $ hg debugrequires -R no_lfs2/ | grep lfs
1246 [1]