Merge pull request #5660 from atom/bf-git-repository-provider-should-not-throw

Make sure that GitRepositoryProvider.repositoryForDirectorySync() return...
This commit is contained in:
Max Brunsfeld 2015-02-23 17:21:48 -08:00
commit 0be34a892f
2 changed files with 25 additions and 1 deletions

View File

@ -54,3 +54,27 @@ describe "GitRepositoryProvider", ->
directory = new Directory dirPath directory = new Directory dirPath
provider.repositoryForDirectory(directory).then (result) -> provider.repositoryForDirectory(directory).then (result) ->
expect(result).toBe null expect(result).toBe null
describe "when specified a Directory without existsSync()", ->
directory = null
provider = null
beforeEach ->
provider = new GitRepositoryProvider atom.project
# An implementation of Directory that does not implement existsSync().
subdirectory = {}
directory =
getSubdirectory: ->
isRoot: -> true
spyOn(directory, "getSubdirectory").andReturn(subdirectory)
it "returns null", ->
repo = provider.repositoryForDirectorySync(directory)
expect(repo).toBe null
expect(directory.getSubdirectory).toHaveBeenCalledWith(".git")
it "returns a Promise that resolves to null for the async implementation", ->
waitsForPromise ->
provider.repositoryForDirectory(directory).then (repo) ->
expect(repo).toBe null
expect(directory.getSubdirectory).toHaveBeenCalledWith(".git")

View File

@ -11,7 +11,7 @@ findGitDirectorySync = (directory) ->
# can return cached values rather than always returning new objects: # can return cached values rather than always returning new objects:
# getParent(), getFile(), getSubdirectory(). # getParent(), getFile(), getSubdirectory().
gitDir = directory.getSubdirectory('.git') gitDir = directory.getSubdirectory('.git')
if gitDir.existsSync() and isValidGitDirectorySync gitDir if gitDir.existsSync?() and isValidGitDirectorySync gitDir
gitDir gitDir
else if directory.isRoot() else if directory.isRoot()
return null return null