       if path = buffer.getPath()
         @getPathStatus(path)
 
-    @subscribe buffer.onDidSave(getBufferPathStatus)
-    @subscribe buffer.onDidReload(getBufferPathStatus)
-    @subscribe buffer.onDidChangePath(getBufferPathStatus)
-    @subscribe buffer.onDidDestroy => @unsubscribe(buffer)
+    bufferSubscriptions = new CompositeDisposable
+    bufferSubscriptions.add buffer.onDidSave(getBufferPathStatus)
+    bufferSubscriptions.add buffer.onDidReload(getBufferPathStatus)
+    bufferSubscriptions.add buffer.onDidChangePath(getBufferPathStatus)
+    bufferSubscriptions.add buffer.onDidDestroy =>
+      bufferSubscriptions.dispose()
+      @subscriptions.remove(bufferSubscriptions)
 
   # Subscribes to editor view event.
   checkoutHeadForEditor: (editor) ->


  constructor: (path, options={}) ->
    @emitter = new Emitter
    @repo = GitUtils.open(path)
    unless @repo?
      throw new Error("No Git repository found searching path: #{path}")


    refreshOnWindowFocus ?= true
    if refreshOnWindowFocus
      onWindowFocus = =>
        @refreshIndex()
        @refreshStatus()

      window.addEventListener 'focus', onWindowFocus
      @subscriptions.add new Disposable(-> window.removeEventListener 'focus', onWindowFocus)

    if @project?
      @subscriptions.add @project.eachBuffer (buffer) => @subscribeToBuffer(buffer)

  # Public: Destroy this {GitRepository} object.
  #
