mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Make sure that GitRepositoryProvider.repositoryForDirectorySync() returns null rather than throws.
The UI locks up if this method does not return.
This commit is contained in:
@@ -54,3 +54,33 @@ describe "GitRepositoryProvider", ->
|
||||
directory = new Directory dirPath
|
||||
provider.repositoryForDirectory(directory).then (result) ->
|
||||
expect(result).toBe null
|
||||
|
||||
describe "when specified a Directory that throws an exception when explored", ->
|
||||
it "catches the exception and returns null for the sync implementation", ->
|
||||
provider = new GitRepositoryProvider atom.project
|
||||
|
||||
# Tolerate an implementation of Directory whose sync methods are unsupported.
|
||||
subdirectory = existsSync: ->
|
||||
spyOn(subdirectory, "existsSync").andThrow("sync method not supported")
|
||||
directory = getSubdirectory: ->
|
||||
spyOn(directory, "getSubdirectory").andReturn(subdirectory)
|
||||
|
||||
provider = new GitRepositoryProvider atom.project
|
||||
repo = provider.repositoryForDirectorySync(directory)
|
||||
expect(repo).toBe null
|
||||
expect(directory.getSubdirectory).toHaveBeenCalledWith(".git")
|
||||
|
||||
it "catches the exception and returns a Promise that resolves to null for the async implementation", ->
|
||||
provider = new GitRepositoryProvider atom.project
|
||||
|
||||
# Tolerate an implementation of Directory whose sync methods are unsupported.
|
||||
subdirectory = existsSync: ->
|
||||
spyOn(subdirectory, "existsSync").andThrow("sync method not supported")
|
||||
directory = getSubdirectory: ->
|
||||
spyOn(directory, "getSubdirectory").andReturn(subdirectory)
|
||||
|
||||
waitsForPromise ->
|
||||
provider = new GitRepositoryProvider atom.project
|
||||
provider.repositoryForDirectory(directory).then (repo) ->
|
||||
expect(repo).toBe null
|
||||
expect(directory.getSubdirectory).toHaveBeenCalledWith(".git")
|
||||
|
||||
@@ -51,6 +51,14 @@ class GitRepositoryProvider
|
||||
# * {GitRepository} if the given directory has a Git repository.
|
||||
# * `null` if the given directory does not have a Git repository.
|
||||
repositoryForDirectorySync: (directory) ->
|
||||
# Ensure that this method does not throw.
|
||||
try
|
||||
@repositoryForDirectorySyncInternal(directory)
|
||||
catch e
|
||||
# TODO: Log error.
|
||||
null
|
||||
|
||||
repositoryForDirectorySyncInternal: (directory) ->
|
||||
# Only one GitRepository should be created for each .git folder. Therefore,
|
||||
# we must check directory and its parent directories to find the nearest
|
||||
# .git folder.
|
||||
|
||||
Reference in New Issue
Block a user