Make project's Git repository a window global

This allows it to operate independently of the
project and mirror the availability of the root view
and project.
This commit is contained in:
Kevin Sawicki
2013-02-27 17:50:37 -08:00
parent 219a8581fd
commit 2ec4d558ba
10 changed files with 36 additions and 31 deletions

View File

@@ -419,12 +419,10 @@ class Buffer
return match[0][0] != '\t'
undefined
getRepo: -> @project?.repo
checkoutHead: ->
path = @getPath()
return unless path
if @getRepo()?.checkoutHead(path)
if git?.checkoutHead(path)
@trigger 'git-status-changed'
scheduleStoppedChangingEvent: ->

View File

@@ -7,7 +7,6 @@ EditSession = require 'edit-session'
EventEmitter = require 'event-emitter'
Directory = require 'directory'
ChildProcess = require 'child-process'
Git = require 'git'
module.exports =
class Project
@@ -35,8 +34,6 @@ class Project
grammarOverridesByPath: @grammarOverridesByPath
destroy: ->
@repo?.destroy()
@repo = null
editSession.destroy() for editSession in @getEditSessions()
addGrammarOverrideForPath: (path, grammar) ->
@@ -60,10 +57,8 @@ class Project
if path?
directory = if fs.isDirectory(path) then path else fs.directory(path)
@rootDirectory = new Directory(directory)
@repo = Git.open(path)
else
@rootDirectory = null
@repo = null
@trigger "path-changed"
@@ -85,7 +80,7 @@ class Project
@ignoreRepositoryPath(path)
ignoreRepositoryPath: (path) ->
config.get("core.hideGitIgnoredFiles") and @repo?.isPathIgnored(fs.join(@getPath(), path))
config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fs.join(@getPath(), path))
resolve: (filePath) ->
filePath = fs.join(@getPath(), filePath) unless filePath[0] == '/'

View File

@@ -91,6 +91,7 @@ window.handleWindowEvents = ->
window.buildProjectAndRootView = ->
RootView = require 'root-view'
Project = require 'project'
Git = require 'git'
pathToOpen = atom.getPathToOpen()
windowState = atom.getRootViewStateForPath(pathToOpen) ? {}
@@ -102,6 +103,11 @@ window.buildProjectAndRootView = ->
$(rootViewParentSelector).append(rootView)
window.git = Git.open(project.getPath())
project.on 'path-changed', ->
window.git?.destroy()
window.git = Git.open(project.getPath())
window.stylesheetElementForId = (id) ->
$("head style[id='#{id}']")