diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 21116ecb7..5403a486c 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -16,7 +16,6 @@ TokenizedBuffer = require 'tokenized-buffer' fsUtils = require 'fs-utils' pathwatcher = require 'pathwatcher' RootView = require 'root-view' -Git = require 'git' clipboard = require 'clipboard' requireStylesheet "jasmine" fixturePackagesPath = fsUtils.resolveOnLoadPath('fixtures/packages') @@ -36,10 +35,6 @@ jasmine.getEnv().defaultTimeoutInterval = 5000 beforeEach -> jQuery.fx.off = true window.project = new Project(fsUtils.resolveOnLoadPath('fixtures')) - window.git = Git.open(project.getPath()) - window.project.on 'path-changed', -> - window.git?.destroy() - window.git = Git.open(window.project.getPath()) window.resetTimeouts() atom.windowMode = 'editor' @@ -89,9 +84,6 @@ afterEach -> if project? project.destroy() window.project = null - if git? - git.destroy() - window.git = null $('#jasmine-content').empty() unless window.debugContent delete atom.windowState jasmine.unspy(atom, 'saveWindowState') diff --git a/src/app/project.coffee b/src/app/project.coffee index 8e37c942f..20cc3199a 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -51,8 +51,9 @@ class Project destroy: -> editSession.destroy() for editSession in @getEditSessions() buffer.release() for buffer in @getBuffers() - window.git?.destroy() - delete window.git + if @repo? + @repo.destroy() + @repo = null ### Public ### @@ -93,6 +94,8 @@ class Project getState: -> @state + getRepo: -> @repo + # Retrieves the project path. # # Returns a {String}. @@ -108,13 +111,14 @@ class Project if projectPath? directory = if fsUtils.isDirectorySync(projectPath) then projectPath else path.dirname(projectPath) @rootDirectory = new Directory(directory) - window.git = Git.open(projectPath) + @repo = Git.open(projectPath) else @rootDirectory = null - window.git?.destroy() - delete window.git + if @repo? + @repo.destroy() + @repo = null - if originUrl = window.git?.getOriginUrl() + if originUrl = @repo?.getOriginUrl() @state.set('repoUrl', originUrl) @trigger "path-changed" @@ -155,7 +159,7 @@ class Project # # Returns a {Boolean}. ignoreRepositoryPath: (repositoryPath) -> - config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(path.join(@getPath(), repositoryPath)) + config.get("core.hideGitIgnoredFiles") and @repo?.isPathIgnored(path.join(@getPath(), repositoryPath)) # Given a uri, this resolves it relative to the project directory. If the path # is already absolute or if it is prefixed with a scheme, it is returned unchanged. diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index d968b4736..6cda6dc10 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -596,7 +596,7 @@ class TextBuffer checkoutHead: -> path = @getPath() return unless path - git?.checkoutHead(path) + project.getRepo()?.checkoutHead(path) # Checks to see if a file exists. # diff --git a/src/app/window.coffee b/src/app/window.coffee index 3d9901f17..1c99e267b 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -86,11 +86,9 @@ window.unloadEditorWindow = -> atom.saveWindowState() rootView.remove() project.destroy() - git?.destroy() windowEventHandler?.unsubscribe() window.rootView = null window.project = null - window.git = null window.installAtomCommand = (callback) -> commandPath = path.join(window.resourcePath, 'atom.sh') @@ -116,7 +114,6 @@ window.onDrop = (e) -> window.deserializeEditorWindow = -> RootView = require 'root-view' Project = require 'project' - Git = require 'git' windowState = atom.getWindowState() diff --git a/src/packages/collaboration/lib/guest-session.coffee b/src/packages/collaboration/lib/guest-session.coffee index 06ff88bf1..199068c53 100644 --- a/src/packages/collaboration/lib/guest-session.coffee +++ b/src/packages/collaboration/lib/guest-session.coffee @@ -64,5 +64,5 @@ class GuestSession @trigger 'started' id = @getId() - email = git.getConfigValue('user.email') + email = project.getRepo().getConfigValue('user.email') @participants.push {id, email} diff --git a/src/packages/collaboration/lib/host-session.coffee b/src/packages/collaboration/lib/host-session.coffee index 50b7cb973..ee4b8bd6a 100644 --- a/src/packages/collaboration/lib/host-session.coffee +++ b/src/packages/collaboration/lib/host-session.coffee @@ -24,8 +24,8 @@ class HostSession host: {description: '', candidate: ''} participants: [] repositoryState: - url: git.getConfigValue('remote.origin.url') - branch: git.getShortHead() + url: project.getRepo().getConfigValue('remote.origin.url') + branch: project.getRepo().getShortHead() host = @doc.get('collaborationState.host') guest = @doc.get('collaborationState.guest') @@ -43,7 +43,7 @@ class HostSession @participants = @doc.get('collaborationState.participants') @participants.push id: @getId() - email: git.getConfigValue('user.email') + email: project.getRepo().getConfigValue('user.email') @participants.on 'changed', => @trigger 'participants-changed', @participants.toObject() diff --git a/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee b/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee index 0421cf9e9..6d908f364 100644 --- a/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee +++ b/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee @@ -45,11 +45,12 @@ class FuzzyFinderView extends SelectList itemForElement: ({filePath, projectRelativePath}) -> $$ -> @li class: 'two-lines', => - if git? - status = git.statuses[filePath] - if git.isStatusNew(status) + repo = project.getRepo() + if repo? + status = repo.statuses[filePath] + if repo.isStatusNew(status) @div class: 'status new' - else if git.isStatusModified(status) + else if repo.isStatusModified(status) @div class: 'status modified' ext = path.extname(filePath) @@ -130,7 +131,7 @@ class FuzzyFinderView extends SelectList if @hasParent() @cancel() else - return unless project.getPath()? and git? + return unless project.getPath()? and project.getRepo() @allowActiveEditorChange = false @populateGitStatusPaths() @attach() @@ -197,7 +198,7 @@ class FuzzyFinderView extends SelectList populateGitStatusPaths: -> paths = [] - paths.push(filePath) for filePath, status of git.statuses when fsUtils.isFileSync(filePath) + paths.push(filePath) for filePath, status of project.getRepo().statuses when fsUtils.isFileSync(filePath) @setArray(paths) diff --git a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee index c918bc3d2..71e6968b2 100644 --- a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee +++ b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee @@ -242,11 +242,11 @@ describe 'FuzzyFinder', -> originalText = editor.getText() originalPath = editor.getPath() fsUtils.writeSync(originalPath, 'making a change for the better') - git.getPathStatus(originalPath) + project.getRepo().getPathStatus(originalPath) newPath = project.resolve('newsample.js') fsUtils.writeSync(newPath, '') - git.getPathStatus(newPath) + project.getRepo().getPathStatus(newPath) afterEach -> fsUtils.writeSync(originalPath, originalText) @@ -515,7 +515,7 @@ describe 'FuzzyFinder', -> it "displays the modified icon", -> editor.setText('modified') editor.activeEditSession.save() - git.getPathStatus(editor.getPath()) + project.getRepo().getPathStatus(editor.getPath()) rootView.trigger 'fuzzy-finder:toggle-buffer-finder' expect(finderView.find('.status.modified').length).toBe 1 @@ -525,7 +525,7 @@ describe 'FuzzyFinder', -> describe "when a new file is shown in the list", -> it "displays the new icon", -> rootView.open('newsample.js') - git.getPathStatus(editor.getPath()) + project.getRepo().getPathStatus(editor.getPath()) rootView.trigger 'fuzzy-finder:toggle-buffer-finder' expect(finderView.find('.status.new').length).toBe 1 diff --git a/src/packages/git-diff/lib/git-diff-view.coffee b/src/packages/git-diff/lib/git-diff-view.coffee index f4fe50089..9c99cd98a 100644 --- a/src/packages/git-diff/lib/git-diff-view.coffee +++ b/src/packages/git-diff/lib/git-diff-view.coffee @@ -3,27 +3,24 @@ Subscriber = require 'subscriber' module.exports = class GitDiffView - diffs: null - editor: null - constructor: (@editor) -> @gutter = @editor.gutter @diffs = {} @subscribe @editor, 'editor:path-changed', @subscribeToBuffer @subscribe @editor, 'editor:display-updated', @renderDiffs - @subscribe git, 'statuses-changed', => + @subscribe project.getRepo(), 'statuses-changed', => @diffs = {} @scheduleUpdate() - @subscribe git, 'status-changed', (path) => + @subscribe project.getRepo(), 'status-changed', (path) => delete @diffs[path] @scheduleUpdate() if path is @editor.getPath() @subscribeToBuffer() - beforeRemove: -> - @unsubscribe() - @unsubscribeFromBuffer() + @subscribe @editor, 'editor:will-be-removed', => + @unsubscribe() + @unsubscribeFromBuffer() unsubscribeFromBuffer: -> if @buffer? @@ -43,12 +40,13 @@ class GitDiffView _.nextTick(@updateDiffs) updateDiffs: => + return unless @buffer? @generateDiffs() @renderDiffs() generateDiffs: -> if path = @buffer.getPath() - @diffs[path] = git?.getLineDiffs(path, @buffer.getText()) + @diffs[path] = project.getRepo()?.getLineDiffs(path, @buffer.getText()) removeDiffs: => if @gutter.hasGitLineDiffs diff --git a/src/packages/git-diff/lib/git-diff.coffee b/src/packages/git-diff/lib/git-diff.coffee index ce1372a46..c63619481 100644 --- a/src/packages/git-diff/lib/git-diff.coffee +++ b/src/packages/git-diff/lib/git-diff.coffee @@ -2,7 +2,5 @@ GitDiffView = require './git-diff-view' module.exports = activate: -> - return unless git? - rootView.eachEditor (editor) => - new GitDiffView(editor) if git? and editor.attached and editor.getPane()? + new GitDiffView(editor) if project.getRepo()? and editor.attached and editor.getPane()? diff --git a/src/packages/status-bar/lib/status-bar-view.coffee b/src/packages/status-bar/lib/status-bar-view.coffee index d9b38da02..458bf60f6 100644 --- a/src/packages/status-bar/lib/status-bar-view.coffee +++ b/src/packages/status-bar/lib/status-bar-view.coffee @@ -34,10 +34,11 @@ class StatusBarView extends View @subscribe @grammarName, 'click', => @pane.activeView.trigger 'grammar-selector:show' @subscribe @pane, 'editor:grammar-changed', => @updateGrammarText() - if git? - @subscribe git, 'status-changed', (path, status) => + repo = project.getRepo() + if repo? + @subscribe repo, 'status-changed', (path, status) => @updateStatusBar() if path is @getActiveItemPath() - @subscribe git, 'statuses-changed', @updateStatusBar + @subscribe repo, 'statuses-changed', @updateStatusBar @subscribeToBuffer() @@ -87,7 +88,7 @@ class StatusBarView extends View @branchArea.hide() return unless project.contains(@getActiveItemPath()) - head = git?.getShortHead() or '' + head = project.getRepo()?.getShortHead() or '' @branchLabel.text(head) @branchArea.show() if head @@ -97,22 +98,23 @@ class StatusBarView extends View return unless project.contains(itemPath) @gitStatusIcon.addClass('git-status octicons') - return unless git? + repo = project.getRepo() + return unless repo? - if git.upstream.ahead > 0 - @commitsAhead.text(git.upstream.ahead).show() + if repo.upstream.ahead > 0 + @commitsAhead.text(repo.upstream.ahead).show() else @commitsAhead.hide() - if git.upstream.behind > 0 - @commitsBehind.text(git.upstream.behind).show() + if repo.upstream.behind > 0 + @commitsBehind.text(repo.upstream.behind).show() else @commitsBehind.hide() - status = git.statuses[itemPath] - if git.isStatusModified(status) + status = repo.statuses[itemPath] + if repo.isStatusModified(status) @gitStatusIcon.addClass('modified-status-icon') - stats = git.getDiffStats(itemPath) + stats = repo.getDiffStats(itemPath) if stats.added and stats.deleted @gitStatusIcon.text("+#{stats.added},-#{stats.deleted}") else if stats.added @@ -121,13 +123,13 @@ class StatusBarView extends View @gitStatusIcon.text("-#{stats.deleted}") else @gitStatusIcon.text('') - else if git.isStatusNew(status) + else if repo.isStatusNew(status) @gitStatusIcon.addClass('new-status-icon') if @buffer? @gitStatusIcon.text("+#{@buffer.getLineCount()}") else @gitStatusIcon.text('') - else if git.isPathIgnored(itemPath) + else if repo.isPathIgnored(itemPath) @gitStatusIcon.addClass('ignored-status-icon') @gitStatusIcon.text('') diff --git a/src/packages/status-bar/spec/status-bar-spec.coffee b/src/packages/status-bar/spec/status-bar-spec.coffee index 0cf8ec25a..f09bd0812 100644 --- a/src/packages/status-bar/spec/status-bar-spec.coffee +++ b/src/packages/status-bar/spec/status-bar-spec.coffee @@ -138,8 +138,8 @@ describe "StatusBar", -> fsUtils.writeSync(newPath, "I'm new here") ignoredPath = path.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'ignored.txt') fsUtils.writeSync(ignoredPath, 'ignored.txt') - git.getPathStatus(filePath) - git.getPathStatus(newPath) + project.getRepo().getPathStatus(filePath) + project.getRepo().getPathStatus(newPath) originalPathText = fsUtils.read(filePath) rootView.attachToDom() @@ -150,7 +150,7 @@ describe "StatusBar", -> it "displays the modified icon for a changed file", -> fsUtils.writeSync(filePath, "i've changed for the worse") - git.getPathStatus(filePath) + project.getRepo().getPathStatus(filePath) rootView.open(filePath) expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon') @@ -168,16 +168,16 @@ describe "StatusBar", -> it "updates when a status-changed event occurs", -> fsUtils.writeSync(filePath, "i've changed for the worse") - git.getPathStatus(filePath) + project.getRepo().getPathStatus(filePath) rootView.open(filePath) expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon') fsUtils.writeSync(filePath, originalPathText) - git.getPathStatus(filePath) + project.getRepo().getPathStatus(filePath) expect(statusBar.gitStatusIcon).not.toHaveClass('modified-status-icon') it "displays the diff stat for modified files", -> fsUtils.writeSync(filePath, "i've changed for the worse") - git.getPathStatus(filePath) + project.getRepo().getPathStatus(filePath) rootView.open(filePath) expect(statusBar.gitStatusIcon).toHaveText('+1,-1') diff --git a/src/packages/tree-view/lib/directory-view.coffee b/src/packages/tree-view/lib/directory-view.coffee index b5bc7f1b9..f3184afaf 100644 --- a/src/packages/tree-view/lib/directory-view.coffee +++ b/src/packages/tree-view/lib/directory-view.coffee @@ -23,15 +23,16 @@ class DirectoryView extends View @disclosureArrow.on 'click', => @toggleExpansion() iconClass = 'directory-icon' - if git? + repo = project.getRepo() + if repo? path = @directory.getPath() if parent - if git.isSubmodule(path) + if repo.isSubmodule(path) iconClass = 'submodule-icon' else - @subscribe git, 'status-changed', (path, status) => + @subscribe repo, 'status-changed', (path, status) => @updateStatus() if path.indexOf("#{@getPath()}/") is 0 - @subscribe git, 'statuses-changed', => + @subscribe repo, 'statuses-changed', => @updateStatus() @updateStatus() else @@ -42,13 +43,14 @@ class DirectoryView extends View updateStatus: -> @removeClass('ignored modified new') path = @directory.getPath() - if git.isPathIgnored(path) + repo = project.getRepo() + if repo.isPathIgnored(path) @addClass('ignored') else - status = git.getDirectoryStatus(path) - if git.isStatusModified(status) + status = repo.getDirectoryStatus(path) + if repo.isStatusModified(status) @addClass('modified') - else if git.isStatusNew(status) + else if repo.isStatusNew(status) @addClass('new') getPath: -> @@ -56,12 +58,13 @@ class DirectoryView extends View isRepositoryRoot: -> try - git? and git.getWorkingDirectory() is fs.realpathSync(@getPath()) + repo = project.getRepo() + repo? and repo.getWorkingDirectory() is fs.realpathSync(@getPath()) catch e false isPathIgnored: (path) -> - config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(path) + config.get("core.hideGitIgnoredFiles") and project.getRepo()?.isPathIgnored(path) buildEntries: -> @unwatchDescendantEntries() diff --git a/src/packages/tree-view/lib/file-view.coffee b/src/packages/tree-view/lib/file-view.coffee index 4be9320a7..37443457b 100644 --- a/src/packages/tree-view/lib/file-view.coffee +++ b/src/packages/tree-view/lib/file-view.coffee @@ -31,26 +31,28 @@ class FileView extends View else @fileName.addClass('text-icon') - if git? - @subscribe git, 'status-changed', (changedPath, status) => + repo = project.getRepo() + if repo? + @subscribe repo, 'status-changed', (changedPath, status) => @updateStatus() if changedPath is @getPath() - @subscribe git, 'statuses-changed', => + @subscribe repo, 'statuses-changed', => @updateStatus() @updateStatus() updateStatus: -> @removeClass('ignored modified new') - return unless git? + repo = project.getRepo() + return unless repo? filePath = @getPath() - if git.isPathIgnored(filePath) + if repo.isPathIgnored(filePath) @addClass('ignored') else - status = git.statuses[filePath] - if git.isStatusModified(status) + status = repo.statuses[filePath] + if repo.isStatusModified(status) @addClass('modified') - else if git.isStatusNew(status) + else if repo.isStatusNew(status) @addClass('new') getPath: -> diff --git a/src/packages/tree-view/spec/tree-view-spec.coffee b/src/packages/tree-view/spec/tree-view-spec.coffee index c5d64ace0..e22b58206 100644 --- a/src/packages/tree-view/spec/tree-view-spec.coffee +++ b/src/packages/tree-view/spec/tree-view-spec.coffee @@ -935,16 +935,16 @@ describe "TreeView", -> config.set "core.hideGitIgnoredFiles", false ignoreFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore') fsUtils.writeSync(ignoreFile, 'tree-view.js') - git.getPathStatus(ignoreFile) + project.getRepo().getPathStatus(ignoreFile) newFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2') fsUtils.writeSync(newFile, '') - git.getPathStatus(newFile) + project.getRepo().getPathStatus(newFile) modifiedFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1') originalFileContent = fsUtils.read(modifiedFile) fsUtils.writeSync modifiedFile, 'ch ch changes' - git.getPathStatus(modifiedFile) + project.getRepo().getPathStatus(modifiedFile) treeView.updateRoot() treeView.root.entries.find('.directory:contains(dir2)').view().expand()