diff --git a/spec/app/git-spec.coffee b/spec/app/git-spec.coffee index 36df69cdd..20edab6bb 100644 --- a/spec/app/git-spec.coffee +++ b/spec/app/git-spec.coffee @@ -121,3 +121,9 @@ describe "Git", -> expect(repo.checkoutHead(path1)).toBeTruthy() expect(fs.read(path2)).toBe('path 2 is edited') expect(repo.isPathModified(path2)).toBeTruthy() + + describe ".destroy()", -> + it "throws an exception when any method is called after it is called", -> + repo = new Git(require.resolve('fixtures/git/master.git/HEAD')) + repo.destroy() + expect(-> repo.getHead()).toThrow() diff --git a/src/app/git.coffee b/src/app/git.coffee index e2142385f..a08595ffb 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -27,12 +27,17 @@ class Git @repo = new GitRepository(path) @subscribe $(window), 'focus', => @refreshIndex() - refreshIndex: -> @repo.refreshIndex() + getRepo: -> + unless @repo? + throw new Error("Repository has been destroyed") + @repo - getPath: -> @repo.getPath() + refreshIndex: -> @getRepo().refreshIndex() + + getPath: -> @getRepo().getPath() destroy: -> - @repo.destroy() + @getRepo().destroy() @repo = null @unsubscribe() @@ -41,13 +46,13 @@ class Git repoPath?.substring(0, repoPath.length - 6) getHead: -> - @repo.getHead() or '' + @getRepo().getHead() or '' getPathStatus: (path) -> - pathStatus = @repo.getStatus(@relativize(path)) + pathStatus = @getRepo().getStatus(@relativize(path)) isPathIgnored: (path) -> - @repo.isIgnored(@relativize(path)) + @getRepo().isIgnored(@relativize(path)) isStatusModified: (status) -> modifiedFlags = @statusFlags.working_dir_modified | @@ -85,12 +90,12 @@ class Git return head checkoutHead: (path) -> - @repo.checkoutHead(@relativize(path)) + @getRepo().checkoutHead(@relativize(path)) getDiffStats: (path) -> - @repo.getDiffStats(@relativize(path)) or added: 0, deleted: 0 + @getRepo().getDiffStats(@relativize(path)) or added: 0, deleted: 0 isSubmodule: (path) -> - @repo.isSubmodule(@relativize(path)) + @getRepo().isSubmodule(@relativize(path)) _.extend Git.prototype, Subscriber