Skip to content

Commit

Permalink
repository: added cleanup for the PlainCloneContext(). [Fixes src-d#741]
Browse files Browse the repository at this point in the history
Signed-off-by: Bartek Jaroszewski <[email protected]>
  • Loading branch information
bjaroszewski committed Sep 24, 2018
1 parent 520ddb5 commit a607a44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
ErrIsBareRepository = errors.New("worktree not available in a bare repository")
ErrUnableToResolveCommit = errors.New("unable to resolve commit")
ErrPackedObjectsNotSupported = errors.New("Packed objects not supported")
ErrDirNotEmpty = errors.New("directory is not empty")
)

// Repository represents a git repository
Expand Down Expand Up @@ -352,9 +353,8 @@ func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOp
dirExist := false

file, err := os.Stat(path)
pathNotExist := os.IsNotExist(err)

if !pathNotExist {
if !os.IsNotExist(err) {
dirExist = file.IsDir()
}

Expand All @@ -365,13 +365,13 @@ func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOp
}
defer fh.Close()

names, err := fh.Readdirnames(1)
_, err = fh.Readdirnames(1)

if err == io.EOF && len(names) == 0 {
dirEmpty = true
} else {
if err != nil && err == io.EOF {
return nil, ErrDirNotEmpty

}
dirEmpty = true
}

r, err := PlainInit(path, isBare)
Expand Down
2 changes: 1 addition & 1 deletion repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func (s *RepositorySuite) TestPlainCloneContextWithIncorrectRepo(c *C) {
cancel()

tmpDir := c.MkDir()
repoDir := filepath.Join(tmpDir, "repoDir") //path.Join(path.Dir(tmpDir), "repoDir")
repoDir := filepath.Join(tmpDir, "repoDir")
r, err := PlainCloneContext(ctx, repoDir, false, &CloneOptions{
URL: "incorrectOnPurpose",
})
Expand Down

0 comments on commit a607a44

Please sign in to comment.