mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -8,6 +8,7 @@ $ = require 'jquery'
|
||||
{$$} = require 'space-pen'
|
||||
_ = require 'underscore'
|
||||
fs = require 'fs'
|
||||
Git = require 'git'
|
||||
|
||||
describe "Editor", ->
|
||||
[buffer, editor, cachedLineHeight] = []
|
||||
|
||||
@@ -14,6 +14,7 @@ Editor = require 'editor'
|
||||
TokenizedBuffer = require 'tokenized-buffer'
|
||||
fs = require 'fs'
|
||||
RootView = require 'root-view'
|
||||
Git = require 'git'
|
||||
requireStylesheet "jasmine.css"
|
||||
fixturePackagesPath = require.resolve('fixtures/packages')
|
||||
require.paths.unshift(fixturePackagesPath)
|
||||
@@ -31,6 +32,11 @@ beforeEach ->
|
||||
jQuery.fx.off = true
|
||||
window.fixturesProject = new Project(require.resolve('fixtures'))
|
||||
window.project = fixturesProject
|
||||
window.git = Git.open(fixturesProject.getPath())
|
||||
window.project.on 'path-changed', ->
|
||||
window.git?.destroy()
|
||||
window.git = Git.open(window.project.getPath())
|
||||
|
||||
window.resetTimeouts()
|
||||
atom.atomPackageStates = {}
|
||||
atom.loadedPackages = []
|
||||
@@ -72,6 +78,9 @@ afterEach ->
|
||||
if project?
|
||||
project.destroy()
|
||||
window.project = null
|
||||
if git?
|
||||
git.destroy()
|
||||
window.git = null
|
||||
$('#jasmine-content').empty()
|
||||
ensureNoPathSubscriptions()
|
||||
waits(0) # yield to ui thread to make screen update more frequently
|
||||
|
||||
@@ -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: ->
|
||||
|
||||
@@ -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] == '/'
|
||||
|
||||
@@ -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}']")
|
||||
|
||||
|
||||
@@ -40,12 +40,11 @@ class FuzzyFinderView extends SelectList
|
||||
$$ ->
|
||||
@li =>
|
||||
typeClass = null
|
||||
repo = project.repo
|
||||
if repo?
|
||||
status = project.repo?.statuses[project.resolve(path)]
|
||||
if repo.isStatusNew(status)
|
||||
if git?
|
||||
status = git.statuses[project.resolve(path)]
|
||||
if git.isStatusNew(status)
|
||||
typeClass = 'new'
|
||||
else if repo.isStatusModified(status)
|
||||
else if git.isStatusModified(status)
|
||||
typeClass = 'modified'
|
||||
|
||||
unless typeClass
|
||||
|
||||
@@ -443,7 +443,7 @@ describe 'FuzzyFinder', ->
|
||||
it "displays the modified icon", ->
|
||||
editor.setText('modified')
|
||||
editor.save()
|
||||
project.repo?.getPathStatus(editor.getPath())
|
||||
git.getPathStatus(editor.getPath())
|
||||
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
expect(finderView.find('.file.modified').length).toBe 1
|
||||
@@ -453,7 +453,7 @@ describe 'FuzzyFinder', ->
|
||||
describe "when a new file is shown in the list", ->
|
||||
it "displays the new icon", ->
|
||||
rootView.open('newsample.js')
|
||||
project.repo?.getPathStatus(editor.getPath())
|
||||
git.getPathStatus(editor.getPath())
|
||||
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
expect(finderView.find('.file.new').length).toBe 1
|
||||
|
||||
@@ -68,7 +68,7 @@ class StatusBarView extends View
|
||||
@branchArea.hide()
|
||||
return unless path
|
||||
|
||||
head = @buffer.getRepo()?.getShortHead() or ''
|
||||
head = git?.getShortHead() or ''
|
||||
@branchLabel.text(head)
|
||||
@branchArea.show() if head
|
||||
|
||||
@@ -78,8 +78,7 @@ class StatusBarView extends View
|
||||
return unless path
|
||||
|
||||
@gitStatusIcon.addClass('git-status octicons')
|
||||
git = @buffer.getRepo()
|
||||
return unless git
|
||||
return unless git?
|
||||
|
||||
status = git.getPathStatus(path)
|
||||
if git.isStatusModified(status)
|
||||
|
||||
@@ -22,22 +22,21 @@ class DirectoryView extends View
|
||||
@expand() if isExpanded
|
||||
@disclosureArrow.on 'click', => @toggleExpansion()
|
||||
|
||||
repo = @project.repo
|
||||
iconClass = 'directory-icon'
|
||||
if repo?
|
||||
if git?
|
||||
path = @directory.getPath()
|
||||
if parent
|
||||
@directoryName.addClass('ignored') if repo.isPathIgnored(path)
|
||||
iconClass = 'submodule-icon' if repo.isSubmodule(path)
|
||||
@directoryName.addClass('ignored') if git.isPathIgnored(path)
|
||||
iconClass = 'submodule-icon' if git.isSubmodule(path)
|
||||
else
|
||||
iconClass = 'repository-icon' if path is repo.getWorkingDirectory()
|
||||
iconClass = 'repository-icon' if path is git.getWorkingDirectory()
|
||||
@directoryName.addClass(iconClass)
|
||||
|
||||
getPath: ->
|
||||
@directory.path
|
||||
|
||||
isPathIgnored: (path) ->
|
||||
config.get("core.hideGitIgnoredFiles") and @project.repo?.isPathIgnored(path)
|
||||
config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(path)
|
||||
|
||||
buildEntries: ->
|
||||
@unwatchDescendantEntries()
|
||||
|
||||
@@ -34,17 +34,16 @@ class FileView extends View
|
||||
|
||||
updateStatus: ->
|
||||
@removeClass('ignored modified new')
|
||||
repo = @project.repo
|
||||
return unless repo?
|
||||
return unless git?
|
||||
|
||||
path = @getPath()
|
||||
if repo.isPathIgnored(path)
|
||||
if git.isPathIgnored(path)
|
||||
@addClass('ignored')
|
||||
else
|
||||
status = repo.getPathStatus(path)
|
||||
if repo.isStatusModified(status)
|
||||
status = git.getPathStatus(path)
|
||||
if git.isStatusModified(status)
|
||||
@addClass('modified')
|
||||
else if repo.isStatusNew(status)
|
||||
else if git.isStatusNew(status)
|
||||
@addClass('new')
|
||||
|
||||
getPath: ->
|
||||
|
||||
Reference in New Issue
Block a user