Merge pull request #12008 from atom/as-ns-recreate-destroyed-repo

Recreate Repository if the same project is added after being removed
This commit is contained in:
Antonio Scandurra 2016-06-21 11:40:49 +02:00 committed by GitHub
commit a5fdf3e18a
3 changed files with 23 additions and 0 deletions

View File

@ -363,6 +363,24 @@ describe "Project", ->
# Verify that the result is cached.
expect(atom.project.repositoryForDirectory(directory)).toBe(promise)
it "creates a new repository if a previous one with the same directory had been destroyed", ->
repository = null
directory = new Directory(path.join(__dirname, '..'))
waitsForPromise ->
atom.project.repositoryForDirectory(directory).then (repo) -> repository = repo
runs ->
expect(repository.isDestroyed()).toBe(false)
repository.destroy()
expect(repository.isDestroyed()).toBe(true)
waitsForPromise ->
atom.project.repositoryForDirectory(directory).then (repo) -> repository = repo
runs ->
expect(repository.isDestroyed()).toBe(false)
describe ".setPaths(paths)", ->
describe "when path is a file", ->
it "sets its path to the files parent directory and updates the root directory", ->

View File

@ -130,6 +130,10 @@ class GitRepository
@async.destroy()
@async = null
# Public: Returns a {Boolean} indicating if this repository has been destroyed.
isDestroyed: ->
not @repo?
# Public: Invoke the given callback when this GitRepository's destroy() method
# is invoked.
#

View File

@ -129,6 +129,7 @@ class Project extends Model
# registered in the future that could supply a Repository for the
# directory.
@repositoryPromisesByPath.delete(pathForDirectory) unless repo?
repo?.onDidDestroy?(=> @repositoryPromisesByPath.delete(pathForDirectory))
repo
@repositoryPromisesByPath.set(pathForDirectory, promise)
promise