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

Commit 7a491e8

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

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,20 @@ 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+
dir, err := ioutil.TempDir("", "plain-clone-context-failure")
584+
c.Assert(err, IsNil)
585+
586+
_, err = PlainCloneContext(ctx, dir, false, &CloneOptions{
587+
URL: "incorrectOnPurpose",
588+
})
589+
_, err = os.Stat(dir)
590+
591+
c.Assert(err, NotNil)
592+
}
593+
580594
func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) {
581595
if testing.Short() {
582596
c.Skip("skipping test in short mode.")

0 commit comments

Comments
 (0)