diff --git a/package.json b/package.json index fc8c30f95..8ed414332 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "coffeestack": "0.7.0", "delegato": "^1", "emissary": "^1.2.1", - "first-mate": "^1.6", + "first-mate": "^1.6.1", "fs-plus": "^2.2.3", "fstream": "0.1.24", "fuzzaldrin": "^1.1", diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index d2e6392af..8617edef6 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -380,8 +380,8 @@ describe "the `atom` global", -> runs -> atom.packages.deactivatePackage('package-with-keymaps') - expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:$$ -> @div class: 'test-1'[0])).toHaveLength 0 - expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:$$ -> @div class: 'test-2'[0])).toHaveLength 0 + expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target: ($$ -> @div class: 'test-1')[0])).toHaveLength 0 + expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target: ($$ -> @div class: 'test-2')[0])).toHaveLength 0 it "removes the package's stylesheets", -> waitsForPromise -> diff --git a/spec/context-menu-manager-spec.coffee b/spec/context-menu-manager-spec.coffee index 42c833bda..c136591eb 100644 --- a/spec/context-menu-manager-spec.coffee +++ b/spec/context-menu-manager-spec.coffee @@ -105,7 +105,7 @@ describe "ContextMenuManager", -> expect(menu[2].command).toEqual 'dev-command' expect(menu[3]).toBeUndefined() - describe "#executeBuildHandlers", -> + describe "executeBuildHandlers", -> menuTemplate = [ label: 'label' executeAtBuild: -> @@ -119,4 +119,3 @@ describe "ContextMenuManager", -> expect(buildFn).toHaveBeenCalled() expect(buildFn.mostRecentCall.args[0]).toBe event - diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index a6ef64cd4..990ca47a7 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -2413,20 +2413,21 @@ describe "EditorView", -> expect(editorView.getFirstVisibleScreenRow()).toBe(0) describe ".checkoutHead()", -> - [filePath, originalPathText] = [] + [filePath] = [] beforeEach -> - filePath = atom.project.resolve('git/working-dir/file.txt') - originalPathText = fs.readFileSync(filePath, 'utf8') + workingDirPath = temp.mkdirSync('atom-working-dir') + fs.copySync(path.join(__dirname, 'fixtures', 'git', 'working-dir'), workingDirPath) + fs.renameSync(path.join(workingDirPath, 'git.git'), path.join(workingDirPath, '.git')) + atom.project.setPath(workingDirPath) + filePath = atom.project.resolve('file.txt') + waitsForPromise -> atom.workspace.open(filePath).then (o) -> editor = o runs -> editorView.edit(editor) - afterEach -> - fs.writeFileSync(filePath, originalPathText) - it "restores the contents of the editor view to the HEAD revision", -> editor.setText('') editor.save() @@ -2440,7 +2441,7 @@ describe "EditorView", -> fileChangeHandler.callCount > 0 runs -> - expect(editor.getText()).toBe(originalPathText) + expect(editor.getText()).toBe('undefined') describe ".pixelPositionForBufferPosition(position)", -> describe "when the editor view is detached", -> diff --git a/spec/fixtures/git/working-dir/dir/b.txt b/spec/fixtures/git/working-dir/dir/b.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/spec/fixtures/git/working-dir/file.txt b/spec/fixtures/git/working-dir/file.txt deleted file mode 100644 index 66dc9051d..000000000 --- a/spec/fixtures/git/working-dir/file.txt +++ /dev/null @@ -1 +0,0 @@ -undefined \ No newline at end of file diff --git a/spec/fixtures/git/working-dir/git.git/index b/spec/fixtures/git/working-dir/git.git/index index bf35b18cd..e49f052cd 100644 Binary files a/spec/fixtures/git/working-dir/git.git/index and b/spec/fixtures/git/working-dir/git.git/index differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/06/15f9a45968b3515e0a202530ef9f61aba26b6c b/spec/fixtures/git/working-dir/git.git/objects/06/15f9a45968b3515e0a202530ef9f61aba26b6c new file mode 100644 index 000000000..8a3a49f46 Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/06/15f9a45968b3515e0a202530ef9f61aba26b6c differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/16/735fb793d7b038818219c4b8c6295346e20eef b/spec/fixtures/git/working-dir/git.git/objects/16/735fb793d7b038818219c4b8c6295346e20eef new file mode 100644 index 000000000..e5d8eb93c Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/16/735fb793d7b038818219c4b8c6295346e20eef differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/52/f56457b6fca045ce41bb9d32e6ca79d23192af b/spec/fixtures/git/working-dir/git.git/objects/52/f56457b6fca045ce41bb9d32e6ca79d23192af new file mode 100644 index 000000000..03280f17f Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/52/f56457b6fca045ce41bb9d32e6ca79d23192af differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/5b/24ab4c3baadf534242b1acc220c8fa051b9b20 b/spec/fixtures/git/working-dir/git.git/objects/5b/24ab4c3baadf534242b1acc220c8fa051b9b20 new file mode 100644 index 000000000..27cfeb8f2 Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/5b/24ab4c3baadf534242b1acc220c8fa051b9b20 differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/66/dc9051da651c15d98d017a88658263cab28f02 b/spec/fixtures/git/working-dir/git.git/objects/66/dc9051da651c15d98d017a88658263cab28f02 new file mode 100644 index 000000000..8e13deb38 Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/66/dc9051da651c15d98d017a88658263cab28f02 differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/8a/9c86f1cb1f14b8f436eb91f4b052c8802ca99e b/spec/fixtures/git/working-dir/git.git/objects/8a/9c86f1cb1f14b8f436eb91f4b052c8802ca99e new file mode 100644 index 000000000..62c86e47f --- /dev/null +++ b/spec/fixtures/git/working-dir/git.git/objects/8a/9c86f1cb1f14b8f436eb91f4b052c8802ca99e @@ -0,0 +1 @@ +xInB1)σf vbcQne=, ķ9r&V!quH.)i6Ί|tu޺}-(+lUΉf_pUQIcxˀxo`wz}~ulmY(+QJ vN1iHL \ No newline at end of file diff --git a/spec/fixtures/git/working-dir/git.git/objects/ec/5e386905ff2d36e291086a1207f2585aaa8920 b/spec/fixtures/git/working-dir/git.git/objects/ec/5e386905ff2d36e291086a1207f2585aaa8920 new file mode 100644 index 000000000..4010ee8c2 Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/ec/5e386905ff2d36e291086a1207f2585aaa8920 differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/fe/bde178cdf35e9df6279d87aa27590c6d92e354 b/spec/fixtures/git/working-dir/git.git/objects/fe/bde178cdf35e9df6279d87aa27590c6d92e354 new file mode 100644 index 000000000..fde11bec7 Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/fe/bde178cdf35e9df6279d87aa27590c6d92e354 differ diff --git a/spec/fixtures/git/working-dir/git.git/objects/ff/c8218bd2240a0cb92f6f02548d45784428349b b/spec/fixtures/git/working-dir/git.git/objects/ff/c8218bd2240a0cb92f6f02548d45784428349b new file mode 100644 index 000000000..919f08db8 Binary files /dev/null and b/spec/fixtures/git/working-dir/git.git/objects/ff/c8218bd2240a0cb92f6f02548d45784428349b differ diff --git a/spec/fixtures/git/working-dir/git.git/refs/heads/master b/spec/fixtures/git/working-dir/git.git/refs/heads/master index 6134b5707..85900d526 100644 --- a/spec/fixtures/git/working-dir/git.git/refs/heads/master +++ b/spec/fixtures/git/working-dir/git.git/refs/heads/master @@ -1 +1 @@ -ef046e9eecaa5255ea5e9817132d4001724d6ae1 +8a9c86f1cb1f14b8f436eb91f4b052c8802ca99e diff --git a/spec/fixtures/git/working-dir/other.txt b/spec/fixtures/git/working-dir/other.txt deleted file mode 100644 index ffc8218bd..000000000 --- a/spec/fixtures/git/working-dir/other.txt +++ /dev/null @@ -1 +0,0 @@ -Full of text \ No newline at end of file diff --git a/spec/git-spec.coffee b/spec/git-spec.coffee index a412cc7d4..46263c8ff 100644 --- a/spec/git-spec.coffee +++ b/spec/git-spec.coffee @@ -4,6 +4,12 @@ fs = require 'fs-plus' path = require 'path' Task = require '../src/task' +copyRepository = -> + workingDirPath = temp.mkdirSync('atom-working-dir') + fs.copySync(path.join(__dirname, 'fixtures', 'git', 'working-dir'), workingDirPath) + fs.renameSync(path.join(workingDirPath, 'git.git'), path.join(workingDirPath, '.git')) + workingDirPath + describe "Git", -> repo = null @@ -41,17 +47,13 @@ describe "Git", -> expect(repo.isPathIgnored('b.txt')).toBeFalsy() describe ".isPathModified(path)", -> - [repo, filePath, newPath, originalPathText] = [] + [repo, filePath, newPath] = [] beforeEach -> - repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir')) - filePath = require.resolve('./fixtures/git/working-dir/file.txt') - newPath = path.join(__dirname, 'fixtures', 'git', 'working-dir', 'new-path.txt') - originalPathText = fs.readFileSync(filePath, 'utf8') - - afterEach -> - fs.writeFileSync(filePath, originalPathText) - fs.removeSync(newPath) if fs.existsSync(newPath) + workingDirPath = copyRepository() + repo = new Git(workingDirPath) + filePath = path.join(workingDirPath, 'a.txt') + newPath = path.join(workingDirPath, 'new-path.txt') describe "when the path is unstaged", -> it "returns false if the path has not been modified", -> @@ -72,14 +74,12 @@ describe "Git", -> [filePath, newPath] = [] beforeEach -> - repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir')) - filePath = require.resolve('./fixtures/git/working-dir/file.txt') - newPath = path.join(__dirname, 'fixtures', 'git', 'working-dir', 'new-path.txt') + workingDirPath = copyRepository() + repo = new Git(workingDirPath) + filePath = path.join(workingDirPath, 'a.txt') + newPath = path.join(workingDirPath, 'new-path.txt') fs.writeFileSync(newPath, "i'm new here") - afterEach -> - fs.removeSync(newPath) if fs.existsSync(newPath) - describe "when the path is unstaged", -> it "returns true if the path is new", -> expect(repo.isPathNew(newPath)).toBeTruthy() @@ -88,48 +88,35 @@ describe "Git", -> expect(repo.isPathNew(filePath)).toBeFalsy() describe ".checkoutHead(path)", -> - [path1, path2, originalPath1Text, originalPath2Text] = [] + [filePath] = [] beforeEach -> - repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir')) - path1 = require.resolve('./fixtures/git/working-dir/file.txt') - originalPath1Text = fs.readFileSync(path1, 'utf8') - path2 = require.resolve('./fixtures/git/working-dir/other.txt') - originalPath2Text = fs.readFileSync(path2, 'utf8') - - afterEach -> - fs.writeFileSync(path1, originalPath1Text) - fs.writeFileSync(path2, originalPath2Text) + workingDirPath = copyRepository() + repo = new Git(workingDirPath) + filePath = path.join(workingDirPath, 'a.txt') it "no longer reports a path as modified after checkout", -> - expect(repo.isPathModified(path1)).toBeFalsy() - fs.writeFileSync(path1, '') - expect(repo.isPathModified(path1)).toBeTruthy() - expect(repo.checkoutHead(path1)).toBeTruthy() - expect(repo.isPathModified(path1)).toBeFalsy() + expect(repo.isPathModified(filePath)).toBeFalsy() + fs.writeFileSync(filePath, 'ch ch changes') + expect(repo.isPathModified(filePath)).toBeTruthy() + expect(repo.checkoutHead(filePath)).toBeTruthy() + expect(repo.isPathModified(filePath)).toBeFalsy() it "restores the contents of the path to the original text", -> - fs.writeFileSync(path1, '') - expect(repo.checkoutHead(path1)).toBeTruthy() - expect(fs.readFileSync(path1, 'utf8')).toBe(originalPath1Text) - - it "only restores the path specified", -> - fs.writeFileSync(path2, 'path 2 is edited') - expect(repo.isPathModified(path2)).toBeTruthy() - expect(repo.checkoutHead(path1)).toBeTruthy() - expect(fs.readFileSync(path2, 'utf8')).toBe('path 2 is edited') - expect(repo.isPathModified(path2)).toBeTruthy() + fs.writeFileSync(filePath, 'ch ch changes') + expect(repo.checkoutHead(filePath)).toBeTruthy() + expect(fs.readFileSync(filePath, 'utf8')).toBe '' it "fires a status-changed event if the checkout completes successfully", -> - fs.writeFileSync(path1, '') - repo.getPathStatus(path1) + fs.writeFileSync(filePath, 'ch ch changes') + repo.getPathStatus(filePath) statusHandler = jasmine.createSpy('statusHandler') repo.on 'status-changed', statusHandler - repo.checkoutHead(path1) + repo.checkoutHead(filePath) expect(statusHandler.callCount).toBe 1 - expect(statusHandler.argsForCall[0][0..1]).toEqual [path1, 0] + expect(statusHandler.argsForCall[0][0..1]).toEqual [filePath, 0] - repo.checkoutHead(path1) + repo.checkoutHead(filePath) expect(statusHandler.callCount).toBe 1 describe ".destroy()", -> @@ -138,32 +125,13 @@ describe "Git", -> repo.destroy() expect(-> repo.getShortHead()).toThrow() - describe ".getDiffStats(path)", -> - [filePath, originalPathText] = [] - - beforeEach -> - repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir')) - filePath = require.resolve('./fixtures/git/working-dir/file.txt') - originalPathText = fs.readFileSync(filePath, 'utf8') - - afterEach -> - fs.writeFileSync(filePath, originalPathText) - - it "returns the number of lines added and deleted", -> - expect(repo.getDiffStats(filePath)).toEqual {added: 0, deleted: 0} - fs.writeFileSync(filePath, "#{originalPathText} edited line") - expect(repo.getDiffStats(filePath)).toEqual {added: 1, deleted: 1} - describe ".getPathStatus(path)", -> - [filePath, originalPathText] = [] + [filePath] = [] beforeEach -> - repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir')) - filePath = require.resolve('./fixtures/git/working-dir/file.txt') - originalPathText = fs.readFileSync(filePath, 'utf8') - - afterEach -> - fs.writeFileSync(filePath, originalPathText) + workingDirectory = copyRepository() + repo = new Git(workingDirectory) + filePath = path.join(workingDirectory, 'file.txt') it "trigger a status-changed event when the new status differs from the last cached one", -> statusHandler = jasmine.createSpy("statusHandler") @@ -178,16 +146,13 @@ describe "Git", -> expect(statusHandler.callCount).toBe 1 describe ".getDirectoryStatus(path)", -> - [directoryPath, filePath, originalPathText] = [] + [directoryPath, filePath] = [] beforeEach -> - repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir')) - directoryPath = path.join(__dirname, 'fixtures', 'git', 'working-dir', 'dir') - filePath = require.resolve('./fixtures/git/working-dir/dir/b.txt') - originalPathText = fs.readFileSync(filePath, 'utf8') - - afterEach -> - fs.writeFileSync(filePath, originalPathText) + workingDirectory = copyRepository() + repo = new Git(workingDirectory) + directoryPath = path.join(workingDirectory, 'dir') + filePath = path.join(directoryPath, 'b.txt') it "gets the status based on the files inside the directory", -> expect(repo.isStatusModified(repo.getDirectoryStatus(directoryPath))).toBe false @@ -199,18 +164,15 @@ describe "Git", -> [newPath, modifiedPath, cleanPath, originalModifiedPathText] = [] beforeEach -> - repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir')) - modifiedPath = atom.project.resolve('git/working-dir/file.txt') - originalModifiedPathText = fs.readFileSync(modifiedPath, 'utf8') - newPath = atom.project.resolve('git/working-dir/untracked.txt') - cleanPath = atom.project.resolve('git/working-dir/other.txt') + workingDirectory = copyRepository() + repo = new Git(workingDirectory) + modifiedPath = path.join(workingDirectory, 'file.txt') + newPath = path.join(workingDirectory, 'untracked.txt') + cleanPath = path.join(workingDirectory, 'other.txt') + fs.writeFileSync(cleanPath, 'Full of text') fs.writeFileSync(newPath, '') newPath = fs.absolute newPath # specs could be running under symbol path. - afterEach -> - fs.writeFileSync(modifiedPath, originalModifiedPathText) - fs.removeSync(newPath) if fs.existsSync(newPath) - it "returns status information for all new and modified files", -> fs.writeFileSync(modifiedPath, 'making this path modified') statusHandler = jasmine.createSpy('statusHandler') @@ -226,17 +188,13 @@ describe "Git", -> expect(repo.isStatusModified(repo.getCachedPathStatus(modifiedPath))).toBeTruthy() describe "buffer events", -> - [originalContent, editor] = [] + [editor] = [] beforeEach -> + atom.project.setPath(copyRepository()) + waitsForPromise -> - atom.workspace.open('sample.js').then (o) -> editor = o - - runs -> - originalContent = editor.getText() - - afterEach -> - fs.writeFileSync(editor.getPath(), originalContent) + atom.workspace.open('other.txt').then (o) -> editor = o it "emits a status-changed event when a buffer is saved", -> editor.insertNewline() @@ -270,15 +228,16 @@ describe "Git", -> expect(statusHandler.callCount).toBe 1 describe "when a project is deserialized", -> - [originalContent, buffer, project2] = [] + [buffer, project2] = [] afterEach -> - fs.writeFileSync(buffer.getPath(), originalContent) project2?.destroy() it "subscribes to all the serialized buffers in the project", -> + atom.project.setPath(copyRepository()) + waitsForPromise -> - atom.workspace.open('sample.js') + atom.workspace.open('file.txt') runs -> project2 = atom.project.testSerialization() diff --git a/spec/pane-view-spec.coffee b/spec/pane-view-spec.coffee index da3105f1a..8d3d3be27 100644 --- a/spec/pane-view-spec.coffee +++ b/spec/pane-view-spec.coffee @@ -166,7 +166,8 @@ describe "PaneView", -> it "removes the pane item", -> editor = null jasmine.unspy(window, 'setTimeout') - filePath = temp.openSync('atom').path + filePath = path.join(temp.mkdirSync(), 'file.txt') + fs.writeFileSync(filePath, '') waitsForPromise -> atom.workspace.open(filePath).then (o) -> editor = o diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee index 568c2132d..acec58aad 100644 --- a/spec/spec-suite.coffee +++ b/spec/spec-suite.coffee @@ -27,11 +27,6 @@ setSpecDirectory = (specDirectory) -> runAllSpecs = -> {resourcePath} = atom.getLoadSettings() - # Only run core specs when resource path is the Atom repository - if Git.exists(resourcePath) - requireSpecs(path.join(resourcePath, 'spec')) - setSpecType('core') - fixturesPackagesPath = path.join(__dirname, 'fixtures', 'packages') packagePaths = atom.packages.getAvailablePackageNames().map (packageName) -> atom.packages.resolvePackagePath(packageName) diff --git a/src/git.coffee b/src/git.coffee index 7e9b22f4b..25c3db9fe 100644 --- a/src/git.coffee +++ b/src/git.coffee @@ -1,4 +1,4 @@ -{join, sep} = require 'path' +{join} = require 'path' _ = require 'underscore-plus' {Emitter, Subscriber} = require 'emissary' @@ -246,7 +246,7 @@ class Git # Returns a {Number} representing the status. This value can be passed to # {::isStatusModified} or {::isStatusNew} to get more information. getDirectoryStatus: (directoryPath) -> - directoryPath = "#{@relativize(directoryPath)}#{sep}" + directoryPath = "#{@relativize(directoryPath)}/" directoryStatus = 0 for path, status of @statuses directoryStatus |= status if path.indexOf(directoryPath) is 0