@@ -21,6 +21,7 @@ import (
21
21
"gopkg.in/src-d/go-git.v4/plumbing/cache"
22
22
"gopkg.in/src-d/go-git.v4/plumbing/object"
23
23
"gopkg.in/src-d/go-git.v4/plumbing/storer"
24
+ "gopkg.in/src-d/go-git.v4/plumbing/transport"
24
25
"gopkg.in/src-d/go-git.v4/storage"
25
26
"gopkg.in/src-d/go-git.v4/storage/filesystem"
26
27
"gopkg.in/src-d/go-git.v4/storage/memory"
@@ -177,11 +178,12 @@ func (s *RepositorySuite) TestCloneContext(c *C) {
177
178
ctx , cancel := context .WithCancel (context .Background ())
178
179
cancel ()
179
180
180
- _ , err := CloneContext (ctx , memory .NewStorage (), nil , & CloneOptions {
181
+ r , err := CloneContext (ctx , memory .NewStorage (), nil , & CloneOptions {
181
182
URL : s .GetBasicLocalRepositoryURL (),
182
183
})
183
184
184
- c .Assert (err , NotNil )
185
+ c .Assert (r , NotNil )
186
+ c .Assert (err , ErrorMatches , ".* context canceled" )
185
187
}
186
188
187
189
func (s * RepositorySuite ) TestCloneWithTags (c * C ) {
@@ -581,7 +583,20 @@ func (s *RepositorySuite) TestPlainCloneWithRemoteName(c *C) {
581
583
c .Assert (remote , NotNil )
582
584
}
583
585
584
- func (s * RepositorySuite ) TestPlainCloneContextWithProperParameters (c * C ) {
586
+ func (s * RepositorySuite ) TestPlainCloneOverExistingGitDirectory (c * C ) {
587
+ tmpDir := c .MkDir ()
588
+ r , err := PlainInit (tmpDir , false )
589
+ c .Assert (r , NotNil )
590
+ c .Assert (err , IsNil )
591
+
592
+ r , err = PlainClone (tmpDir , false , & CloneOptions {
593
+ URL : s .GetBasicLocalRepositoryURL (),
594
+ })
595
+ c .Assert (r , IsNil )
596
+ c .Assert (err , Equals , ErrRepositoryAlreadyExists )
597
+ }
598
+
599
+ func (s * RepositorySuite ) TestPlainCloneContextCancel (c * C ) {
585
600
ctx , cancel := context .WithCancel (context .Background ())
586
601
cancel ()
587
602
@@ -590,7 +605,7 @@ func (s *RepositorySuite) TestPlainCloneContextWithProperParameters(c *C) {
590
605
})
591
606
592
607
c .Assert (r , NotNil )
593
- c .Assert (err , NotNil )
608
+ c .Assert (err , ErrorMatches , ".* context canceled" )
594
609
}
595
610
596
611
func (s * RepositorySuite ) TestPlainCloneContextNonExistentWithExistentDir (c * C ) {
@@ -604,7 +619,7 @@ func (s *RepositorySuite) TestPlainCloneContextNonExistentWithExistentDir(c *C)
604
619
URL : "incorrectOnPurpose" ,
605
620
})
606
621
c .Assert (r , NotNil )
607
- c .Assert (err , NotNil )
622
+ c .Assert (err , Equals , transport . ErrRepositoryNotFound )
608
623
609
624
_ , err = os .Stat (repoDir )
610
625
c .Assert (os .IsNotExist (err ), Equals , false )
@@ -625,7 +640,7 @@ func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNonExistentDir(c *
625
640
URL : "incorrectOnPurpose" ,
626
641
})
627
642
c .Assert (r , NotNil )
628
- c .Assert (err , NotNil )
643
+ c .Assert (err , Equals , transport . ErrRepositoryNotFound )
629
644
630
645
_ , err = os .Stat (repoDir )
631
646
c .Assert (os .IsNotExist (err ), Equals , true )
@@ -645,7 +660,7 @@ func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNotDir(c *C) {
645
660
URL : "incorrectOnPurpose" ,
646
661
})
647
662
c .Assert (r , IsNil )
648
- c .Assert (err , NotNil )
663
+ c .Assert (err , ErrorMatches , ".*not a directory.*" )
649
664
650
665
fi , err := os .Stat (repoDir )
651
666
c .Assert (err , IsNil )
@@ -668,8 +683,28 @@ func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNotEmptyDir(c *C)
668
683
r , err := PlainCloneContext (ctx , repoDirPath , false , & CloneOptions {
669
684
URL : "incorrectOnPurpose" ,
670
685
})
686
+ c .Assert (r , NotNil )
687
+ c .Assert (err , Equals , transport .ErrRepositoryNotFound )
688
+
689
+ _ , err = os .Stat (dummyFile )
690
+ c .Assert (err , IsNil )
691
+
692
+ }
693
+
694
+ func (s * RepositorySuite ) TestPlainCloneContextNonExistingOverExistingGitDirectory (c * C ) {
695
+ ctx , cancel := context .WithCancel (context .Background ())
696
+ cancel ()
697
+
698
+ tmpDir := c .MkDir ()
699
+ r , err := PlainInit (tmpDir , false )
700
+ c .Assert (r , NotNil )
701
+ c .Assert (err , IsNil )
702
+
703
+ r , err = PlainCloneContext (ctx , tmpDir , false , & CloneOptions {
704
+ URL : "incorrectOnPurpose" ,
705
+ })
671
706
c .Assert (r , IsNil )
672
- c .Assert (err , NotNil )
707
+ c .Assert (err , Equals , ErrRepositoryAlreadyExists )
673
708
}
674
709
675
710
func (s * RepositorySuite ) TestPlainCloneWithRecurseSubmodules (c * C ) {
0 commit comments