mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add task to refresh status of repository
By default this will occur when the window gains focus and the Git class can now be subscribed to so listeners can become notified when the status of a repository changes.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
_ = require 'underscore'
|
||||
fs = require 'fs'
|
||||
Subscriber = require 'subscriber'
|
||||
EventEmitter = require 'event-emitter'
|
||||
GitRepository = require 'git-repository'
|
||||
RepositoryStatusTask = require 'repository-status-task'
|
||||
|
||||
module.exports =
|
||||
class Git
|
||||
@@ -23,12 +25,16 @@ class Git
|
||||
working_dir_typechange: 1 << 10
|
||||
ignore: 1 << 14
|
||||
|
||||
statuses: {}
|
||||
|
||||
constructor: (path, options={}) ->
|
||||
@repo = GitRepository.open(path)
|
||||
refreshIndexOnFocus = options.refreshIndexOnFocus ? true
|
||||
if refreshIndexOnFocus
|
||||
refreshOnWindowFocus = options.refreshOnWindowFocus ? true
|
||||
if refreshOnWindowFocus
|
||||
$ = require 'jquery'
|
||||
@subscribe $(window), 'focus', => @refreshIndex()
|
||||
@subscribe $(window), 'focus', =>
|
||||
@refreshIndex()
|
||||
@refreshStatuses()
|
||||
|
||||
getRepo: ->
|
||||
unless @repo?
|
||||
@@ -54,9 +60,6 @@ class Git
|
||||
getPathStatus: (path) ->
|
||||
pathStatus = @getRepo().getStatus(@relativize(path))
|
||||
|
||||
getAllStatuses: (path) ->
|
||||
@getRepo().getStatuses()
|
||||
|
||||
isPathIgnored: (path) ->
|
||||
@getRepo().isIgnored(@relativize(path))
|
||||
|
||||
@@ -104,4 +107,8 @@ class Git
|
||||
isSubmodule: (path) ->
|
||||
@getRepo().isSubmodule(@relativize(path))
|
||||
|
||||
refreshStatuses: ->
|
||||
new RepositoryStatusTask(this).start()
|
||||
|
||||
_.extend Git.prototype, Subscriber
|
||||
_.extend Git.prototype, EventEmitter
|
||||
|
||||
16
src/app/repository-status-handler.coffee
Normal file
16
src/app/repository-status-handler.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
Git = require 'git'
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
loadStatuses: (path) ->
|
||||
repo = Git.open(path)
|
||||
if repo?
|
||||
workingDirectoryPath = repo.getWorkingDirectory()
|
||||
statuses = {}
|
||||
for path, status of repo.getRepo().getStatuses()
|
||||
statuses[fs.join(workingDirectoryPath, path)] = status
|
||||
repo.destroy()
|
||||
else
|
||||
statuses = {}
|
||||
|
||||
callTaskMethod('statusesLoaded', statuses)
|
||||
17
src/app/repository-status-task.coffee
Normal file
17
src/app/repository-status-task.coffee
Normal file
@@ -0,0 +1,17 @@
|
||||
Task = require 'task'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class RepositoryStatusTask extends Task
|
||||
|
||||
constructor: (@repo) ->
|
||||
super('repository-status-handler')
|
||||
|
||||
started: ->
|
||||
@callWorkerMethod('loadStatuses', @repo.getPath())
|
||||
|
||||
statusesLoaded: (statuses) ->
|
||||
@done()
|
||||
unless _.isEqual(statuses, @repo.statuses)
|
||||
@repo.statuses = statuses
|
||||
@repo.trigger 'statuses-changed'
|
||||
Reference in New Issue
Block a user