Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 77f738c

Browse files
committed
repository: added cleanup for the PlainCloneContext(). [Fixes #741]
Signed-off-by: Bartek Jaroszewski <[email protected]>
1 parent fcfd239 commit 77f738c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

repository.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,13 @@ func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOp
350350
return nil, err
351351
}
352352

353-
return r, r.clone(ctx, o)
353+
err = r.clone(ctx, o)
354+
if err != nil && err != ErrRepositoryAlreadyExists {
355+
os.RemoveAll(path)
356+
return nil, err
357+
}
358+
359+
return r, err
354360
}
355361

356362
func newRepository(s storage.Storer, worktree billy.Filesystem) *Repository {

repository_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,24 @@ func (s *RepositorySuite) TestPlainCloneContext(c *C) {
577577
c.Assert(err, NotNil)
578578
}
579579

580+
func (s *RepositorySuite) TestPlainCloneContextWithIncorrectRepo(c *C) {
581+
ctx, cancel := context.WithCancel(context.Background())
582+
cancel()
583+
584+
dir, err := ioutil.TempDir("", "plain-clone-context-failure")
585+
c.Assert(err, IsNil)
586+
587+
r, err := PlainCloneContext(ctx, dir, false, &CloneOptions{
588+
URL: "incorrectOnPurpose",
589+
})
590+
c.Assert(r, IsNil)
591+
c.Assert(err, NotNil)
592+
593+
_, err = os.Stat(dir)
594+
dirNotExist := os.IsNotExist(err)
595+
c.Assert(dirNotExist, Equals, true)
596+
}
597+
580598
func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) {
581599
if testing.Short() {
582600
c.Skip("skipping test in short mode.")

0 commit comments

Comments
 (0)