Passed
Push — develop ( cce1b7...1a4157 )
by Jace
49s
created

tests.test_api.describe_keep_location()   A

Complexity

Conditions 1

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nop 0
dl 0
loc 30
rs 9.4
c 0
b 0
f 0
1
# pylint: disable=redefined-outer-name,unused-argument,unused-variable,singleton-comparison,expression-not-assigned,no-member
2
3
import inspect
4
import os
5
import shutil
6
from contextlib import suppress
7
8
import log
9
import pytest
10
from expecter import expect
11
from freezegun import freeze_time
12
13
import gitman
14
from gitman import shell
15
from gitman.exceptions import InvalidConfig, InvalidRepository, UncommittedChanges
16
from gitman.models import Config
17
18
from .utilities import strip
19
20
21
ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)))
22
TMP = os.path.join(ROOT, 'tmp')
23
24
CONFIG = """
25
location: deps
26
sources:
27
- name: gitman_1
28
  type: git
29
  repo: https://github.com/jacebrowning/gitman-demo
30
  sparse_paths:
31
  -
32
  rev: example-branch
33
  link:
34
  scripts:
35
  -
36
- name: gitman_2
37
  type: git
38
  repo: https://github.com/jacebrowning/gitman-demo
39
  sparse_paths:
40
  -
41
  rev: example-tag
42
  link:
43
  scripts:
44
  -
45
- name: gitman_3
46
  type: git
47
  repo: https://github.com/jacebrowning/gitman-demo
48
  sparse_paths:
49
  -
50
  rev: 9bf18e16b956041f0267c21baad555a23237b52e
51
  link:
52
  scripts:
53
  -
54
sources_locked:
55
-
56
groups:
57
-
58
""".lstrip()
59
60
61
@pytest.yield_fixture
62
def config():
63
    log.info("Temporary directory: %s", TMP)
64
65
    with suppress(FileNotFoundError, PermissionError):
66
        shutil.rmtree(TMP)
67
    with suppress(FileExistsError):
68
        os.makedirs(TMP)
69
    os.chdir(TMP)
70
71
    os.system("touch .git")
72
    config = Config(root=TMP)
73
    config.datafile.text = CONFIG
74
    config.datafile.load()
75
76
    log.debug("File listing: %s", os.listdir(TMP))
77
78
    yield config
79
80
    os.chdir(ROOT)
81
82
83
def describe_init():
84
    def it_creates_a_new_config_file(tmpdir):
85
        tmpdir.chdir()
86
87
        expect(gitman.init()) == True
88
89
        expect(Config().datafile.text) == strip(
90
            """
91
        location: gitman_sources
92
        sources:
93
        - name: sample_dependency
94
          type: git
95
          repo: https://github.com/githubtraining/hellogitworld
96
          sparse_paths:
97
          -
98
          rev: master
99
          link:
100
          scripts:
101
          -
102
        sources_locked:
103
        - name: sample_dependency
104
          type: git
105
          repo: https://github.com/githubtraining/hellogitworld
106
          sparse_paths:
107
          -
108
          rev: ebbbf773431ba07510251bb03f9525c7bab2b13a
109
          link:
110
          scripts:
111
          -
112
        groups:
113
        -
114
        """
115
        )
116
117
    def it_does_not_modify_existing_config_file(config):
118
        expect(gitman.init()) == False
119
120
        expect(config.datafile.text) == CONFIG
121
122
123
def describe_install():
124
    def it_creates_missing_directories(config):
125
        shell.rm(config.location)
126
127
        expect(gitman.install('gitman_1', depth=1)) == True
128
129
        expect(os.listdir(config.location)) == ['gitman_1']
130
131
    def it_should_not_modify_config(config):
132
        expect(gitman.install('gitman_1', depth=1)) == True
133
134
        expect(config.datafile.text) == CONFIG
135
136
    def it_merges_sources(config):
137
        config.datafile.text = strip(
138
            """
139
        location: deps
140
        sources:
141
        - name: gitman_1
142
          type: git
143
          repo: https://github.com/jacebrowning/gitman-demo
144
          rev: example-branch
145
          link:
146
          scripts:
147
          -
148
        sources_locked:
149
        - name: gitman_2
150
          type: git
151
          repo: https://github.com/jacebrowning/gitman-demo
152
          rev: example-branch
153
          link:
154
          scripts:
155
          -
156
        - name: gitman_3
157
          type: git
158
          repo: https://github.com/jacebrowning/gitman-demo
159
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
160
          link:
161
          scripts:
162
          -
163
        """
164
        )
165
        config.datafile.load()
166
167
        expect(gitman.install(depth=1)) == True
168
169
        expect(len(os.listdir(config.location))) == 3
170
171
    def it_can_handle_missing_locked_sources(config):
172
        config.datafile.text = strip(
173
            """
174
        location: deps
175
        sources:
176
        - name: gitman_1
177
          repo: https://github.com/jacebrowning/gitman-demo
178
          rev: example-branch
179
          link:
180
          scripts:
181
          -
182
        sources_locked:
183
        - name: gitman_2
184
          type: git
185
          repo: https://github.com/jacebrowning/gitman-demo
186
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
187
          link:
188
          scripts:
189
          -
190
        """
191
        )
192
        config.datafile.load()
193
194
        expect(gitman.install('gitman_1', depth=1)) == True
195
196
        expect(os.listdir(config.location)) == ['gitman_1']
197
198
    def it_detects_invalid_repositories(config):
199
        shell.rm(os.path.join("deps", "gitman_1", ".git"))
200
        shell.mkdir(os.path.join("deps", "gitman_1", ".git"))
201
202
        try:
203
            with pytest.raises(InvalidRepository):
204
                expect(gitman.install('gitman_1', depth=1)) == False
205
206
        finally:
207
            shell.rm(os.path.join("deps", "gitman_1"))
208
209
    def describe_links():
210
        @pytest.fixture
211
        def config_with_link(config):
212
            config.datafile.text = strip(
213
                """
214
            location: deps
215
            sources:
216
            - name: gitman_1
217
              repo: https://github.com/jacebrowning/gitman-demo
218
              rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
219
              link: my_link
220
              scripts:
221
              -
222
            """
223
            )
224
            config.datafile.load()
225
226
            return config
227
228
        def it_should_create_links(config_with_link):
229
            expect(gitman.install(depth=1)) == True
230
231
            expect(os.listdir()).contains('my_link')
232
233
        def it_should_not_overwrite_files(config_with_link):
234
            os.system("touch my_link")
235
236
            with pytest.raises(RuntimeError):
237
                gitman.install(depth=1)
238
239
        def it_overwrites_files_with_force(config_with_link):
240
            os.system("touch my_link")
241
242
            expect(gitman.install(depth=1, force=True)) == True
243
244
    def describe_scripts():
245
        @pytest.fixture
246
        def config_with_scripts(config):
247
            config.datafile.text = strip(
248
                """
249
            location: deps
250
            sources:
251
            - name: gitman_1
252
              type: git
253
              repo: https://github.com/jacebrowning/gitman-demo
254
              rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
255
              link:
256
              scripts:
257
              - make foobar
258
            """
259
            )
260
            config.datafile.load()
261
262
            return config
263
264
        def it_detects_failures_in_scripts(config_with_scripts):
265
            with pytest.raises(RuntimeError):
266
                expect(gitman.install())
267
268
        def script_failures_can_be_ignored(config_with_scripts):
269
            expect(gitman.install(force=True)) == True
270
271
    def describe_sparse_paths():
272
        @pytest.fixture
273
        def config_with_scripts(config):
274
            config.datafile.text = strip(
275
                """
276
                    location: deps
277
                    sources:
278
                    - name: gitman_1
279
                      type: git
280
                      repo: https://github.com/jacebrowning/gitman-demo
281
                      sparse_paths:
282
                      - src/*
283
                      rev: ddbe17ef173538d1fda29bd99a14bab3c5d86e78
284
                      link:
285
                      scripts:
286
                      -
287
                    """
288
            )
289
            config.datafile.load()
290
291
            return config
292
293
        def it_successfully_materializes_the_repo(config):
294
            expect(gitman.install(depth=1, force=True)) == True
295
            dir_listing = os.listdir(os.path.join(config.location, "gitman_1"))
296
            expect(dir_listing).contains('src')
297
298
        def it_contains_only_the_sparse_paths(config):
299
            expect(gitman.install(depth=1, force=True)) == True
300
            dir_listing = os.listdir(os.path.join(config.location, "gitman_1"))
301
            expect(dir_listing).contains('src')
302
            expect(len(dir_listing) == 1)
303
304
305
def describe_uninstall():
306
    def it_deletes_dependencies_when_they_exist(config):
307
        gitman.install('gitman_1', depth=1)
308
        expect(os.path.isdir(config.location)) == True
309
310
        expect(gitman.uninstall()) == True
311
312
        expect(os.path.exists(config.location)) == False
313
314
    def it_should_not_fail_when_no_dependencies_exist(config):
315
        expect(os.path.isdir(config.location)) == False
316
317
        expect(gitman.uninstall()) == True
318
319
    def it_deletes_the_log_file(config):
320
        gitman.install('gitman_1', depth=1)
321
        gitman.list()
322
        expect(os.path.exists(config.log_path)) == True
323
324
        gitman.uninstall()
325
        expect(os.path.exists(config.log_path)) == False
326
327
    def describe_keep_location():
328
        def it_deletes_dependencies_when_they_exist(config):
329
            gitman.install('gitman_1', depth=1)
330
            expect(os.path.isdir(config.location)) == True
331
332
            expect(gitman.uninstall(keep_location=True)) == True
333
334
            path = os.path.join(config.location, 'gitman_1')
335
            expect(os.path.exists(path)) == False
336
337
            expect(os.path.exists(config.location)) == True
338
339
            gitman.uninstall()
340
341
        def it_should_not_fail_when_no_dependencies_exist(config):
342
            expect(os.path.isdir(config.location)) == False
343
344
            expect(gitman.uninstall(keep_location=True)) == True
345
346
            gitman.uninstall()
347
348
        def it_deletes_the_log_file(config):
349
            gitman.install('gitman_1', depth=1)
350
            gitman.list()
351
            expect(os.path.exists(config.log_path)) == True
352
353
            gitman.uninstall(keep_location=True)
354
            expect(os.path.exists(config.log_path)) == False
355
356
            gitman.uninstall()
357
358
359
def describe_update():
360
    def it_should_not_modify_config(config):
361
        gitman.update('gitman_1', depth=1)
362
363
        expect(config.datafile.text) == CONFIG
364
365
    def it_locks_previously_unlocked_dependencies(config):
366
        config.datafile.text = strip(
367
            """
368
        location: deps
369
        sources:
370
        - name: gitman_1
371
          type: git
372
          repo: https://github.com/jacebrowning/gitman-demo
373
          sparse_paths:
374
          -
375
          rev: example-branch
376
          link:
377
          scripts:
378
          -
379
        - name: gitman_2
380
          type: git
381
          repo: https://github.com/jacebrowning/gitman-demo
382
          sparse_paths:
383
          -
384
          rev: example-tag
385
          link:
386
          scripts:
387
          -
388
        sources_locked:
389
        - name: gitman_2
390
          type: git
391
          repo: https://github.com/jacebrowning/gitman-demo
392
          sparse_paths:
393
          -
394
          rev: (old revision)
395
          link:
396
          scripts:
397
          -
398
        groups:
399
        -
400
        """
401
        )
402
        config.datafile.load()
403
404
        gitman.update(depth=1)
405
406
        config.datafile.load()
407
        expect(config.datafile.text) == strip(
408
            """
409
        location: deps
410
        sources:
411
        - name: gitman_1
412
          type: git
413
          repo: https://github.com/jacebrowning/gitman-demo
414
          sparse_paths:
415
          -
416
          rev: example-branch
417
          link:
418
          scripts:
419
          -
420
        - name: gitman_2
421
          type: git
422
          repo: https://github.com/jacebrowning/gitman-demo
423
          sparse_paths:
424
          -
425
          rev: example-tag
426
          link:
427
          scripts:
428
          -
429
        sources_locked:
430
        - name: gitman_2
431
          type: git
432
          repo: https://github.com/jacebrowning/gitman-demo
433
          sparse_paths:
434
          -
435
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
436
          link:
437
          scripts:
438
          -
439
        groups:
440
        -
441
        """
442
        )
443
444
    def it_should_not_lock_dependencies_when_disabled(config):
445
        config.datafile.text = strip(
446
            """
447
        location: deps
448
        sources:
449
        - name: gitman_1
450
          type: git
451
          repo: https://github.com/jacebrowning/gitman-demo
452
          sparse_paths:
453
          -
454
          rev: example-branch
455
          link:
456
          scripts:
457
          -
458
        - name: gitman_2
459
          type: git
460
          repo: https://github.com/jacebrowning/gitman-demo
461
          sparse_paths:
462
          -
463
          rev: example-tag
464
          link:
465
          scripts:
466
          -
467
        sources_locked:
468
        - name: gitman_2
469
          type: git
470
          repo: https://github.com/jacebrowning/gitman-demo
471
          sparse_paths:
472
          -
473
          rev: (old revision)
474
          link:
475
          scripts:
476
          -
477
        groups:
478
        -
479
        """
480
        )
481
        config.datafile.load()
482
483
        gitman.update(depth=1, lock=False)
484
485
        expect(config.datafile.text) == strip(
486
            """
487
        location: deps
488
        sources:
489
        - name: gitman_1
490
          type: git
491
          repo: https://github.com/jacebrowning/gitman-demo
492
          sparse_paths:
493
          -
494
          rev: example-branch
495
          link:
496
          scripts:
497
          -
498
        - name: gitman_2
499
          type: git
500
          repo: https://github.com/jacebrowning/gitman-demo
501
          sparse_paths:
502
          -
503
          rev: example-tag
504
          link:
505
          scripts:
506
          -
507
        sources_locked:
508
        - name: gitman_2
509
          type: git
510
          repo: https://github.com/jacebrowning/gitman-demo
511
          sparse_paths:
512
          -
513
          rev: (old revision)
514
          link:
515
          scripts:
516
          -
517
        groups:
518
        -
519
        """
520
        )
521
522
    def it_should_not_allow_source_and_group_name_conflicts(config):
523
        config.datafile.text = strip(
524
            """
525
                location: deps
526
                sources:
527
                - name: gitman_1
528
                  type: git
529
                  repo: https://github.com/jacebrowning/gitman-demo
530
                  rev: example-branch
531
                - name: gitman_2
532
                  type: git
533
                  repo: https://github.com/jacebrowning/gitman-demo
534
                  rev: example-branch
535
                groups:
536
                - name: gitman_1
537
                  members:
538
                  - gitman_1
539
                  - gitman_2
540
            """
541
        )
542
        config.datafile.load()
543
544
        with pytest.raises(InvalidConfig):
545
            gitman.update(depth=1, lock=True)
546
547
    def it_locks_previously_locked_dependencies_by_group_name(config):
548
        config.datafile.text = strip(
549
            """
550
        location: deps
551
        sources:
552
        - name: gitman_1
553
          type: git
554
          repo: https://github.com/jacebrowning/gitman-demo
555
          sparse_paths:
556
          -
557
          rev: example-branch
558
          link:
559
          scripts:
560
          -
561
        - name: gitman_2
562
          type: git
563
          repo: https://github.com/jacebrowning/gitman-demo
564
          sparse_paths:
565
          -
566
          rev: example-tag
567
          link:
568
          scripts:
569
          -
570
        - name: gitman_3
571
          type: git
572
          repo: https://github.com/jacebrowning/gitman-demo
573
          sparse_paths:
574
          -
575
          rev: example-tag
576
          link:
577
          scripts:
578
          -
579
        sources_locked:
580
        - name: gitman_1
581
          type: git
582
          repo: https://github.com/jacebrowning/gitman-demo
583
          sparse_paths:
584
          -
585
          rev: (old revision)
586
          link:
587
          scripts:
588
          -
589
        - name: gitman_2
590
          type: git
591
          repo: https://github.com/jacebrowning/gitman-demo
592
          sparse_paths:
593
          -
594
          rev: (old revision)
595
          link:
596
          scripts:
597
          -
598
        groups:
599
        - name: group_a
600
          members:
601
          - gitman_1
602
          - gitman_2
603
        """
604
        )
605
        config.datafile.load()
606
607
        gitman.update('group_a', depth=1)
608
609
        config.datafile.load()
610
        expect(config.datafile.text) == strip(
611
            """
612
        location: deps
613
        sources:
614
        - name: gitman_1
615
          type: git
616
          repo: https://github.com/jacebrowning/gitman-demo
617
          sparse_paths:
618
          -
619
          rev: example-branch
620
          link:
621
          scripts:
622
          -
623
        - name: gitman_2
624
          type: git
625
          repo: https://github.com/jacebrowning/gitman-demo
626
          sparse_paths:
627
          -
628
          rev: example-tag
629
          link:
630
          scripts:
631
          -
632
        - name: gitman_3
633
          type: git
634
          repo: https://github.com/jacebrowning/gitman-demo
635
          sparse_paths:
636
          -
637
          rev: example-tag
638
          link:
639
          scripts:
640
          -
641
        sources_locked:
642
        - name: gitman_1
643
          type: git
644
          repo: https://github.com/jacebrowning/gitman-demo
645
          sparse_paths:
646
          -
647
          rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd
648
          link:
649
          scripts:
650
          -
651
        - name: gitman_2
652
          type: git
653
          repo: https://github.com/jacebrowning/gitman-demo
654
          sparse_paths:
655
          -
656
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
657
          link:
658
          scripts:
659
          -
660
        groups:
661
        - name: group_a
662
          members:
663
          - gitman_1
664
          - gitman_2
665
        """
666
        )
667
668
    def it_should_not_lock_dependencies_changes_force_interactive_no(
669
        config, monkeypatch
670
    ):
671
        def git_changes(
672
            type, include_untracked=False, display_status=True, _show=False
673
        ):
674
            # always return True because changes won't be overwriten
675
            return True
676
677
        # patch the git.changes function to stimulate the
678
        # force-interactive question (without changes no question)
679
        monkeypatch.setattr('gitman.git.changes', git_changes)
680
        # patch standard input function to return "n" for each call
681
        # this is necessary to answer the force-interactive question
682
        # with no to skip the force process
683
        monkeypatch.setattr('builtins.input', lambda x: "n")
684
685
        config.datafile.text = strip(
686
            """
687
        location: deps
688
        sources:
689
        - name: gitman_2
690
          type: git
691
          repo: https://github.com/jacebrowning/gitman-demo
692
          sparse_paths:
693
          -
694
          rev: example-tag
695
          link:
696
          scripts:
697
          -
698
        sources_locked:
699
        - name: gitman_2
700
          type: git
701
          repo: https://github.com/jacebrowning/gitman-demo
702
          sparse_paths:
703
          -
704
          rev: (old revision)
705
          link:
706
          scripts:
707
          -
708
        groups:
709
        -
710
        """
711
        )
712
        config.datafile.load()
713
714
        gitman.update(depth=1, force_interactive=True)
715
716
        expect(config.datafile.text) == strip(
717
            """
718
        location: deps
719
        sources:
720
        - name: gitman_2
721
          type: git
722
          repo: https://github.com/jacebrowning/gitman-demo
723
          sparse_paths:
724
          -
725
          rev: example-tag
726
          link:
727
          scripts:
728
          -
729
        sources_locked:
730
        - name: gitman_2
731
          type: git
732
          repo: https://github.com/jacebrowning/gitman-demo
733
          sparse_paths:
734
          -
735
          rev: (old revision)
736
          link:
737
          scripts:
738
          -
739
        groups:
740
        -
741
        """
742
        )
743
744
    def it_locks_dependencies_changes_force_interactive_yes(config, monkeypatch):
745
        def git_changes(
746
            type, include_untracked=False, display_status=True, _show=False
747
        ):
748
749
            # get caller function name
750
            caller = inspect.stack()[1].function
751
            # if caller is update_files then we return True
752
            # to simulate local changes
753
            if caller == "update_files":
754
                return True
755
756
            # all other functions get False because after
757
            # the force process there are logically no changes anymore
758
            return False
759
760
        # patch the git.changes function to stimulate the
761
        # force-interactive question (without changes no question)
762
        monkeypatch.setattr('gitman.git.changes', git_changes)
763
        # patch standard input function to return "y" for each call
764
        # this is necessary to answer the force-interactive question
765
        # with yes to invoke the force process
766
        monkeypatch.setattr('builtins.input', lambda x: "y")
767
768
        config.datafile.text = strip(
769
            """
770
        location: deps
771
        sources:
772
        - name: gitman_2
773
          type: git
774
          repo: https://github.com/jacebrowning/gitman-demo
775
          sparse_paths:
776
          -
777
          rev: example-tag
778
          link:
779
          scripts:
780
          -
781
        sources_locked:
782
        - name: gitman_2
783
          type: git
784
          repo: https://github.com/jacebrowning/gitman-demo
785
          sparse_paths:
786
          -
787
          rev: (old revision)
788
          link:
789
          scripts:
790
          -
791
        groups:
792
        -
793
        """
794
        )
795
        config.datafile.load()
796
797
        gitman.update(depth=1, force_interactive=True)
798
799
        config.datafile.load()
800
        expect(config.datafile.text) == strip(
801
            """
802
        location: deps
803
        sources:
804
        - name: gitman_2
805
          type: git
806
          repo: https://github.com/jacebrowning/gitman-demo
807
          sparse_paths:
808
          -
809
          rev: example-tag
810
          link:
811
          scripts:
812
          -
813
        sources_locked:
814
        - name: gitman_2
815
          type: git
816
          repo: https://github.com/jacebrowning/gitman-demo
817
          sparse_paths:
818
          -
819
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
820
          link:
821
          scripts:
822
          -
823
        groups:
824
        -
825
        """
826
        )
827
828
    def it_merges_sources(config):
829
        config.datafile.text = strip(
830
            """
831
        location: deps
832
        sources:
833
        - name: gitman_1
834
          type: git
835
          repo: https://github.com/jacebrowning/gitman-demo
836
          rev: example-branch
837
          link:
838
          scripts:
839
          -
840
        sources_locked:
841
        - name: gitman_2
842
          type: git
843
          repo: https://github.com/jacebrowning/gitman-demo
844
          rev: example-branch
845
          link:
846
          scripts:
847
          -
848
        - name: gitman_3
849
          type: git
850
          repo: https://github.com/jacebrowning/gitman-demo
851
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
852
          link:
853
          scripts:
854
          -
855
        """
856
        )
857
        config.datafile.load()
858
859
        expect(gitman.install(depth=1)) == True
860
861
        expect(len(os.listdir(config.location))) == 3
862
863
864
def describe_list():
865
    @freeze_time("2012-01-14 12:00:01")
866
    def it_updates_the_log(config):
867
        gitman.install()
868
        gitman.list()
869
870
        with open(config.log_path) as stream:
871
            contents = stream.read().replace(TMP, "tmp").replace('\\', '/')
872
        expect(contents) == strip(
873
            """
874
        2012-01-14 12:00:01
875
        tmp/deps/gitman_1: https://github.com/jacebrowning/gitman-demo @ 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd
876
        tmp/deps/gitman_1/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ 050290bca3f14e13fd616604202b579853e7bfb0
877
        tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_3: https://github.com/jacebrowning/gdm-demo @ fb693447579235391a45ca170959b5583c5042d8
878
        tmp/deps/gitman_1/gitman_sources/gdm_3/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5
879
        tmp/deps/gitman_1/gitman_sources/gdm_4: https://github.com/jacebrowning/gdm-demo @ 63ddfd82d308ddae72d31b61cb8942c898fa05b5
880
        tmp/deps/gitman_2: https://github.com/jacebrowning/gitman-demo @ 7bd138fe7359561a8c2ff9d195dff238794ccc04
881
        tmp/deps/gitman_3: https://github.com/jacebrowning/gitman-demo @ 9bf18e16b956041f0267c21baad555a23237b52e
882
        """,
883
            end='\n\n',
884
        )
885
886
887
def describe_lock():
888
    def it_records_all_versions_when_no_arguments(config):
889
        expect(gitman.update(depth=1, lock=False)) == True
890
        expect(gitman.lock()) == True
891
892
        config.datafile.load()
893
        expect(config.datafile.text).contains(
894
            strip(
895
                """
896
        sources_locked:
897
        - name: gitman_1
898
          type: git
899
          repo: https://github.com/jacebrowning/gitman-demo
900
          sparse_paths:
901
          -
902
          rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd
903
          link:
904
          scripts:
905
          -
906
        - name: gitman_2
907
          type: git
908
          repo: https://github.com/jacebrowning/gitman-demo
909
          sparse_paths:
910
          -
911
          rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04
912
          link:
913
          scripts:
914
          -
915
        - name: gitman_3
916
          type: git
917
          repo: https://github.com/jacebrowning/gitman-demo
918
          sparse_paths:
919
          -
920
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
921
          link:
922
          scripts:
923
          -
924
        """
925
            )
926
        )
927
928
    def it_records_specified_dependencies(config):
929
        expect(gitman.update(depth=1, lock=False)) == True
930
        expect(gitman.lock('gitman_1', 'gitman_3')) == True
931
932
        config.datafile.load()
933
        expect(config.datafile.text).contains(
934
            strip(
935
                """
936
        sources_locked:
937
        - name: gitman_1
938
          type: git
939
          repo: https://github.com/jacebrowning/gitman-demo
940
          sparse_paths:
941
          -
942
          rev: 1de84ca1d315f81b035cd7b0ecf87ca2025cdacd
943
          link:
944
          scripts:
945
          -
946
        - name: gitman_3
947
          type: git
948
          repo: https://github.com/jacebrowning/gitman-demo
949
          sparse_paths:
950
          -
951
          rev: 9bf18e16b956041f0267c21baad555a23237b52e
952
          link:
953
          scripts:
954
          -
955
        """
956
            )
957
        )
958
959
    def it_should_fail_on_dirty_repositories(config):
960
        expect(gitman.update(depth=1, lock=False)) == True
961
        shell.rm(os.path.join("deps", "gitman_1", ".project"))
962
963
        try:
964
            with pytest.raises(UncommittedChanges):
965
                gitman.lock()
966
967
            expect(config.datafile.text).does_not_contain("<dirty>")
968
969
        finally:
970
            shell.rm(os.path.join("deps", "gitman_1"))
971
972
    def it_should_fail_on_missing_repositories(config):
973
        shell.mkdir("deps")
974
        shell.rm(os.path.join("deps", "gitman_1"))
975
976
        with pytest.raises(InvalidRepository):
977
            gitman.lock()
978
979
        expect(config.datafile.text).does_not_contain("<unknown>")
980
981
    def it_should_fail_on_invalid_repositories(config):
982
        shell.mkdir("deps")
983
        shell.rm(os.path.join("deps", "gitman_1", ".git"))
984
        shell.mkdir(os.path.join("deps", "gitman_1", ".git"))
985
986
        try:
987
            with pytest.raises(InvalidRepository):
988
                gitman.lock()
989
990
            expect(config.datafile.text).does_not_contain("<unknown>")
991
992
        finally:
993
            shell.rm(os.path.join("deps", "gitman_1"))
994