Pass project to Git.open in the options hash

Previously the project global was unavailable in the Git constructor
since it had not been set as a global yet and so the Git instance was never
configured to watch the project's buffers for save/reload events.  This caused
the status to be out of sync in places like the gutter and status bar.
This commit is contained in:
Kevin Sawicki
2013-09-02 11:26:34 -07:00
parent d9b2b3e565
commit 63a3d9de94
3 changed files with 51 additions and 8 deletions

View File

@@ -52,6 +52,8 @@ class Git
# * options:
# + refreshOnWindowFocus: If `true`, {#refreshIndex} and {#refreshStatus}
# are called on focus
# + project: A project that supplies buffers that will be monitored for
# save and reload events to trigger status refreshes.
constructor: (path, options={}) ->
@repo = GitUtils.open(path)
unless @repo?
@@ -59,20 +61,25 @@ class Git
@statuses = {}
@upstream = {ahead: 0, behind: 0}
{project, refreshOnWindowFocus} = options
refreshOnWindowFocus = options.refreshOnWindowFocus ? true
refreshOnWindowFocus ?= true
if refreshOnWindowFocus
$ = require 'jquery'
@subscribe $(window), 'focus', =>
@refreshIndex()
@refreshStatus()
project?.eachBuffer this, (buffer) =>
bufferStatusHandler = =>
path = buffer.getPath()
@getPathStatus(path) if path
@subscribe buffer, 'saved', bufferStatusHandler
@subscribe buffer, 'reloaded', bufferStatusHandler
if project?
@subscribeToBuffer(buffer) for buffer in project.getBuffers()
@subscribe project, 'buffer-created', (buffer) => @subscribeToBuffer(buffer)
subscribeToBuffer: (buffer) ->
bufferStatusHandler = =>
if path = buffer.getPath()
@getPathStatus(path)
@subscribe buffer, 'saved', bufferStatusHandler
@subscribe buffer, 'reloaded', bufferStatusHandler
# Private:
destroy: ->

View File

@@ -121,7 +121,7 @@ class Project
if projectPath?
directory = if fsUtils.isDirectorySync(projectPath) then projectPath else path.dirname(projectPath)
@rootDirectory = new Directory(directory)
@repo = Git.open(projectPath)
@repo = Git.open(projectPath, project: this)
else
@rootDirectory = null