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:
@@ -204,3 +204,39 @@ describe "Git", ->
|
||||
expect(statuses[cleanPath]).toBeUndefined()
|
||||
expect(repo.isStatusNew(statuses[newPath])).toBeTruthy()
|
||||
expect(repo.isStatusModified(statuses[modifiedPath])).toBeTruthy()
|
||||
|
||||
describe "when a buffer is changed and then saved", ->
|
||||
[originalContent, editSession] = []
|
||||
|
||||
afterEach ->
|
||||
fsUtils.writeSync(editSession.getPath(), originalContent)
|
||||
|
||||
it "emits a status-changed event", ->
|
||||
editSession = project.open('sample.js')
|
||||
originalContent = editSession.getText()
|
||||
editSession.insertNewline()
|
||||
|
||||
statusHandler = jasmine.createSpy('statusHandler')
|
||||
project.getRepo().on 'status-changed', statusHandler
|
||||
editSession.save()
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
expect(statusHandler).toHaveBeenCalledWith editSession.getPath(), 256
|
||||
|
||||
describe "when a buffer is reloaded and has been changed", ->
|
||||
[originalContent, editSession] = []
|
||||
|
||||
afterEach ->
|
||||
fsUtils.writeSync(editSession.getPath(), originalContent)
|
||||
|
||||
it "emits a status-changed event", ->
|
||||
editSession = project.open('sample.js')
|
||||
originalContent = editSession.getText()
|
||||
fsUtils.writeSync(editSession.getPath(), 'changed')
|
||||
|
||||
statusHandler = jasmine.createSpy('statusHandler')
|
||||
project.getRepo().on 'status-changed', statusHandler
|
||||
editSession.getBuffer().reload()
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
expect(statusHandler).toHaveBeenCalledWith editSession.getPath(), 256
|
||||
editSession.getBuffer().reload()
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
|
||||
@@ -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