@@ -561,11 +561,134 @@ class RepositoryManagerTests: XCTestCase {
561
561
fatalError ( " should not be called " )
562
562
}
563
563
564
+ public func isValidDirectory( _ directory: AbsolutePath , for repository: RepositorySpecifier ) throws -> Bool {
565
+ fatalError ( " should not be called " )
566
+ }
567
+
564
568
func cancel( deadline: DispatchTime ) throws {
565
569
print ( " cancel " )
566
570
}
567
571
}
568
572
}
573
+
574
+ func testInvalidRepositoryOnDisk( ) throws {
575
+ let fileSystem = localFileSystem
576
+ let observability = ObservabilitySystem . makeForTesting ( )
577
+
578
+ try testWithTemporaryDirectory { path in
579
+ let repositoriesDirectory = path. appending ( " repositories " )
580
+ try fileSystem. createDirectory ( repositoriesDirectory, recursive: true )
581
+
582
+ let testRepository = RepositorySpecifier ( url: . init( " test- \( UUID ( ) . uuidString) " ) )
583
+ let provider = MockRepositoryProvider ( repository: testRepository)
584
+
585
+ let manager = RepositoryManager (
586
+ fileSystem: fileSystem,
587
+ path: repositoriesDirectory,
588
+ provider: provider,
589
+ delegate: nil
590
+ )
591
+
592
+ _ = try manager. lookup ( repository: testRepository, observabilityScope: observability. topScope)
593
+ testDiagnostics ( observability. diagnostics) { result in
594
+ result. check (
595
+ diagnostic: . contains( " is not valid git repository for ' \( testRepository) ', will fetch again " ) ,
596
+ severity: . warning
597
+ )
598
+ }
599
+ }
600
+
601
+ class MockRepositoryProvider : RepositoryProvider {
602
+ let repository : RepositorySpecifier
603
+ var fetch : Int = 0
604
+
605
+ init ( repository: RepositorySpecifier ) {
606
+ self . repository = repository
607
+ }
608
+
609
+ func fetch( repository: RepositorySpecifier , to path: AbsolutePath , progressHandler: ( ( FetchProgress ) -> Void ) ? ) throws {
610
+ assert ( repository == self . repository)
611
+ self . fetch += 1
612
+ }
613
+
614
+ func repositoryExists( at path: AbsolutePath ) throws -> Bool {
615
+ // the directory exists
616
+ return true
617
+ }
618
+
619
+ func open( repository: RepositorySpecifier , at path: AbsolutePath ) throws -> Repository {
620
+ return MockRepository ( )
621
+ }
622
+
623
+ func createWorkingCopy( repository: RepositorySpecifier , sourcePath: AbsolutePath , at destinationPath: AbsolutePath , editable: Bool ) throws -> WorkingCheckout {
624
+ fatalError ( " should not be called " )
625
+ }
626
+
627
+ func workingCopyExists( at path: AbsolutePath ) throws -> Bool {
628
+ fatalError ( " should not be called " )
629
+ }
630
+
631
+ func openWorkingCopy( at path: AbsolutePath ) throws -> WorkingCheckout {
632
+ fatalError ( " should not be called " )
633
+ }
634
+
635
+ func copy( from sourcePath: AbsolutePath , to destinationPath: AbsolutePath ) throws {
636
+ fatalError ( " should not be called " )
637
+ }
638
+
639
+ func isValidDirectory( _ directory: AbsolutePath ) throws -> Bool {
640
+ fatalError ( " should not be called " )
641
+ }
642
+
643
+ public func isValidDirectory( _ directory: AbsolutePath , for repository: RepositorySpecifier ) throws -> Bool {
644
+ assert ( repository == self . repository)
645
+ // the directory is not valid
646
+ return false
647
+ }
648
+
649
+ func cancel( deadline: DispatchTime ) throws {
650
+ fatalError ( " should not be called " )
651
+ }
652
+ }
653
+
654
+ class MockRepository : Repository {
655
+ func getTags( ) throws -> [ String ] {
656
+ fatalError ( " unexpected API call " )
657
+ }
658
+
659
+ func resolveRevision( tag: String ) throws -> Revision {
660
+ fatalError ( " unexpected API call " )
661
+ }
662
+
663
+ func resolveRevision( identifier: String ) throws -> Revision {
664
+ fatalError ( " unexpected API call " )
665
+ }
666
+
667
+ func exists( revision: Revision ) -> Bool {
668
+ fatalError ( " unexpected API call " )
669
+ }
670
+
671
+ func isValidDirectory( _ directory: AbsolutePath ) throws -> Bool {
672
+ fatalError ( " unexpected API call " )
673
+ }
674
+
675
+ public func isValidDirectory( _ directory: AbsolutePath , for repository: RepositorySpecifier ) throws -> Bool {
676
+ fatalError ( " unexpected API call " )
677
+ }
678
+
679
+ func fetch( ) throws {
680
+ // noop
681
+ }
682
+
683
+ func openFileView( revision: Revision ) throws -> FileSystem {
684
+ fatalError ( " unexpected API call " )
685
+ }
686
+
687
+ public func openFileView( tag: String ) throws -> FileSystem {
688
+ fatalError ( " unexpected API call " )
689
+ }
690
+ }
691
+ }
569
692
}
570
693
571
694
extension RepositoryManager {
@@ -613,46 +736,6 @@ private enum DummyError: Swift.Error {
613
736
case invalidRepository
614
737
}
615
738
616
- private class DummyRepository : Repository {
617
- unowned let provider : DummyRepositoryProvider
618
-
619
- init ( provider: DummyRepositoryProvider ) {
620
- self . provider = provider
621
- }
622
-
623
- func getTags( ) throws -> [ String ] {
624
- [ " 1.0.0 " ]
625
- }
626
-
627
- func resolveRevision( tag: String ) throws -> Revision {
628
- fatalError ( " unexpected API call " )
629
- }
630
-
631
- func resolveRevision( identifier: String ) throws -> Revision {
632
- fatalError ( " unexpected API call " )
633
- }
634
-
635
- func exists( revision: Revision ) -> Bool {
636
- fatalError ( " unexpected API call " )
637
- }
638
-
639
- func isValidDirectory( _ directory: AbsolutePath ) throws -> Bool {
640
- fatalError ( " unexpected API call " )
641
- }
642
-
643
- func fetch( ) throws {
644
- self . provider. increaseFetchCount ( )
645
- }
646
-
647
- func openFileView( revision: Revision ) throws -> FileSystem {
648
- fatalError ( " unexpected API call " )
649
- }
650
-
651
- public func openFileView( tag: String ) throws -> FileSystem {
652
- fatalError ( " unexpected API call " )
653
- }
654
- }
655
-
656
739
private class DummyRepositoryProvider : RepositoryProvider {
657
740
private let fileSystem : FileSystem
658
741
@@ -720,6 +803,10 @@ private class DummyRepositoryProvider: RepositoryProvider {
720
803
return true
721
804
}
722
805
806
+ func isValidDirectory( _ directory: AbsolutePath , for repository: RepositorySpecifier ) throws -> Bool {
807
+ return true
808
+ }
809
+
723
810
func cancel( deadline: DispatchTime ) throws {
724
811
// noop
725
812
}
@@ -795,7 +882,7 @@ private class DummyRepositoryProvider: RepositoryProvider {
795
882
}
796
883
}
797
884
798
- private class DummyRepositoryManagerDelegate : RepositoryManager . Delegate {
885
+ fileprivate class DummyRepositoryManagerDelegate : RepositoryManager . Delegate {
799
886
private var _willFetch = ThreadSafeArrayStore < ( repository: RepositorySpecifier , details: RepositoryManager . FetchDetails ) > ( )
800
887
private var _didFetch = ThreadSafeArrayStore < ( repository: RepositorySpecifier , result: Result < RepositoryManager . FetchDetails , Error > ) > ( )
801
888
private var _willUpdate = ThreadSafeArrayStore < RepositorySpecifier > ( )
@@ -870,3 +957,47 @@ private class DummyRepositoryManagerDelegate: RepositoryManager.Delegate {
870
957
self . group. leave ( )
871
958
}
872
959
}
960
+
961
+ fileprivate class DummyRepository : Repository {
962
+ unowned let provider : DummyRepositoryProvider
963
+
964
+ init ( provider: DummyRepositoryProvider ) {
965
+ self . provider = provider
966
+ }
967
+
968
+ func getTags( ) throws -> [ String ] {
969
+ [ " 1.0.0 " ]
970
+ }
971
+
972
+ func resolveRevision( tag: String ) throws -> Revision {
973
+ fatalError ( " unexpected API call " )
974
+ }
975
+
976
+ func resolveRevision( identifier: String ) throws -> Revision {
977
+ fatalError ( " unexpected API call " )
978
+ }
979
+
980
+ func exists( revision: Revision ) -> Bool {
981
+ fatalError ( " unexpected API call " )
982
+ }
983
+
984
+ func isValidDirectory( _ directory: AbsolutePath ) throws -> Bool {
985
+ fatalError ( " unexpected API call " )
986
+ }
987
+
988
+ public func isValidDirectory( _ directory: AbsolutePath , for repository: RepositorySpecifier ) throws -> Bool {
989
+ fatalError ( " unexpected API call " )
990
+ }
991
+
992
+ func fetch( ) throws {
993
+ self . provider. increaseFetchCount ( )
994
+ }
995
+
996
+ func openFileView( revision: Revision ) throws -> FileSystem {
997
+ fatalError ( " unexpected API call " )
998
+ }
999
+
1000
+ public func openFileView( tag: String ) throws -> FileSystem {
1001
+ fatalError ( " unexpected API call " )
1002
+ }
1003
+ }
0 commit comments