mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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: ->
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user