2013-09-24 02:46:57 +04:00
|
|
|
temp = require 'temp'
|
2014-09-22 22:07:41 +04:00
|
|
|
GitRepository = require '../src/git-repository'
|
2014-02-24 05:19:00 +04:00
|
|
|
fs = require 'fs-plus'
|
2013-06-13 03:20:40 +04:00
|
|
|
path = require 'path'
|
2013-09-18 05:58:41 +04:00
|
|
|
Task = require '../src/task'
|
2015-09-22 20:57:12 +03:00
|
|
|
Project = require '../src/project'
|
2012-10-26 01:52:25 +04:00
|
|
|
|
2014-05-31 02:06:59 +04:00
|
|
|
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
|
|
|
|
|
2014-09-22 22:07:53 +04:00
|
|
|
describe "GitRepository", ->
|
2013-02-15 21:40:32 +04:00
|
|
|
repo = null
|
2012-10-26 01:52:25 +04:00
|
|
|
|
2012-10-27 20:37:28 +04:00
|
|
|
beforeEach ->
|
2013-10-21 17:20:19 +04:00
|
|
|
gitPath = path.join(temp.dir, '.git')
|
2013-11-01 00:43:44 +04:00
|
|
|
fs.removeSync(gitPath) if fs.isDirectorySync(gitPath)
|
2012-10-27 20:37:28 +04:00
|
|
|
|
2013-02-15 21:40:32 +04:00
|
|
|
afterEach ->
|
|
|
|
repo.destroy() if repo?.repo?
|
|
|
|
|
2013-01-09 09:15:19 +04:00
|
|
|
describe "@open(path)", ->
|
|
|
|
it "returns null when no repository is found", ->
|
2014-09-22 22:07:41 +04:00
|
|
|
expect(GitRepository.open(path.join(temp.dir, 'nogit.txt'))).toBeNull()
|
2013-01-09 09:15:19 +04:00
|
|
|
|
2014-09-22 22:07:41 +04:00
|
|
|
describe "new GitRepository(path)", ->
|
2013-01-09 06:28:09 +04:00
|
|
|
it "throws an exception when no repository is found", ->
|
2014-09-22 22:07:41 +04:00
|
|
|
expect(-> new GitRepository(path.join(temp.dir, 'nogit.txt'))).toThrow()
|
2013-01-09 06:28:09 +04:00
|
|
|
|
2012-11-03 00:24:38 +04:00
|
|
|
describe ".getPath()", ->
|
2012-10-27 03:03:11 +04:00
|
|
|
it "returns the repository path for a .git directory path", ->
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(path.join(__dirname, 'fixtures', 'git', 'master.git', 'HEAD'))
|
2013-09-18 02:58:08 +04:00
|
|
|
expect(repo.getPath()).toBe path.join(__dirname, 'fixtures', 'git', 'master.git')
|
2012-10-26 02:20:12 +04:00
|
|
|
|
|
|
|
it "returns the repository path for a repository path", ->
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(path.join(__dirname, 'fixtures', 'git', 'master.git'))
|
2013-09-18 02:58:08 +04:00
|
|
|
expect(repo.getPath()).toBe path.join(__dirname, 'fixtures', 'git', 'master.git')
|
2012-10-26 02:20:12 +04:00
|
|
|
|
2012-11-03 01:54:12 +04:00
|
|
|
describe ".isPathIgnored(path)", ->
|
2012-10-27 03:24:47 +04:00
|
|
|
it "returns true for an ignored path", ->
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(path.join(__dirname, 'fixtures', 'git', 'ignore.git'))
|
2012-11-03 01:54:12 +04:00
|
|
|
expect(repo.isPathIgnored('a.txt')).toBeTruthy()
|
2012-10-27 03:24:47 +04:00
|
|
|
|
|
|
|
it "returns false for a non-ignored path", ->
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(path.join(__dirname, 'fixtures', 'git', 'ignore.git'))
|
2012-11-03 01:54:12 +04:00
|
|
|
expect(repo.isPathIgnored('b.txt')).toBeFalsy()
|
2012-11-03 00:24:38 +04:00
|
|
|
|
2012-11-03 01:54:12 +04:00
|
|
|
describe ".isPathModified(path)", ->
|
2014-05-31 02:01:16 +04:00
|
|
|
[repo, filePath, newPath] = []
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2014-05-31 02:06:59 +04:00
|
|
|
workingDirPath = copyRepository()
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(workingDirPath)
|
2014-05-31 02:01:16 +04:00
|
|
|
filePath = path.join(workingDirPath, 'a.txt')
|
|
|
|
newPath = path.join(workingDirPath, 'new-path.txt')
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
describe "when the path is unstaged", ->
|
|
|
|
it "returns false if the path has not been modified", ->
|
2013-06-13 03:20:40 +04:00
|
|
|
expect(repo.isPathModified(filePath)).toBeFalsy()
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
it "returns true if the path is modified", ->
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(filePath, "change")
|
2013-06-13 03:20:40 +04:00
|
|
|
expect(repo.isPathModified(filePath)).toBeTruthy()
|
2012-11-03 00:24:38 +04:00
|
|
|
|
|
|
|
it "returns true if the path is deleted", ->
|
2013-11-01 00:43:44 +04:00
|
|
|
fs.removeSync(filePath)
|
2013-06-13 03:20:40 +04:00
|
|
|
expect(repo.isPathModified(filePath)).toBeTruthy()
|
2012-11-03 01:54:12 +04:00
|
|
|
|
|
|
|
it "returns false if the path is new", ->
|
|
|
|
expect(repo.isPathModified(newPath)).toBeFalsy()
|
|
|
|
|
|
|
|
describe ".isPathNew(path)", ->
|
2013-06-13 03:20:40 +04:00
|
|
|
[filePath, newPath] = []
|
2012-11-03 01:54:12 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2014-05-31 02:06:59 +04:00
|
|
|
workingDirPath = copyRepository()
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(workingDirPath)
|
2014-05-31 02:01:16 +04:00
|
|
|
filePath = path.join(workingDirPath, 'a.txt')
|
|
|
|
newPath = path.join(workingDirPath, 'new-path.txt')
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(newPath, "i'm new here")
|
2012-11-03 01:54:12 +04:00
|
|
|
|
|
|
|
describe "when the path is unstaged", ->
|
|
|
|
it "returns true if the path is new", ->
|
|
|
|
expect(repo.isPathNew(newPath)).toBeTruthy()
|
|
|
|
|
|
|
|
it "returns false if the path isn't new", ->
|
2013-06-13 03:20:40 +04:00
|
|
|
expect(repo.isPathNew(filePath)).toBeFalsy()
|
2012-11-04 02:09:43 +04:00
|
|
|
|
|
|
|
describe ".checkoutHead(path)", ->
|
2014-05-31 02:06:59 +04:00
|
|
|
[filePath] = []
|
2012-11-04 02:09:43 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2014-05-31 02:06:59 +04:00
|
|
|
workingDirPath = copyRepository()
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(workingDirPath)
|
2014-05-31 01:57:01 +04:00
|
|
|
filePath = path.join(workingDirPath, 'a.txt')
|
2012-11-04 02:09:43 +04:00
|
|
|
|
|
|
|
it "no longer reports a path as modified after checkout", ->
|
2014-05-31 01:57:01 +04:00
|
|
|
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()
|
2012-11-04 02:09:43 +04:00
|
|
|
|
|
|
|
it "restores the contents of the path to the original text", ->
|
2014-05-31 01:57:01 +04:00
|
|
|
fs.writeFileSync(filePath, 'ch ch changes')
|
|
|
|
expect(repo.checkoutHead(filePath)).toBeTruthy()
|
|
|
|
expect(fs.readFileSync(filePath, 'utf8')).toBe ''
|
2013-01-10 05:12:15 +04:00
|
|
|
|
2013-02-28 08:16:20 +04:00
|
|
|
it "fires a status-changed event if the checkout completes successfully", ->
|
2014-05-31 01:57:01 +04:00
|
|
|
fs.writeFileSync(filePath, 'ch ch changes')
|
|
|
|
repo.getPathStatus(filePath)
|
2013-02-28 08:16:20 +04:00
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
2014-09-10 01:28:30 +04:00
|
|
|
repo.onDidChangeStatus statusHandler
|
2014-05-31 01:57:01 +04:00
|
|
|
repo.checkoutHead(filePath)
|
2013-02-28 08:16:20 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
2014-09-10 01:28:30 +04:00
|
|
|
expect(statusHandler.argsForCall[0][0]).toEqual {path: filePath, pathStatus: 0}
|
2013-02-28 08:16:20 +04:00
|
|
|
|
2014-05-31 01:57:01 +04:00
|
|
|
repo.checkoutHead(filePath)
|
2013-02-28 08:16:20 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
|
|
|
|
2014-08-14 02:55:38 +04:00
|
|
|
describe ".checkoutHeadForEditor(editor)", ->
|
|
|
|
[filePath, editor] = []
|
|
|
|
|
|
|
|
beforeEach ->
|
2015-10-06 22:13:57 +03:00
|
|
|
spyOn(atom, "confirm")
|
|
|
|
|
2014-08-14 02:55:38 +04:00
|
|
|
workingDirPath = copyRepository()
|
2015-10-06 22:13:57 +03:00
|
|
|
repo = new GitRepository(workingDirPath, {project: atom.project, config: atom.config, confirm: atom.confirm})
|
2014-08-14 02:55:38 +04:00
|
|
|
filePath = path.join(workingDirPath, 'a.txt')
|
|
|
|
fs.writeFileSync(filePath, 'ch ch changes')
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open(filePath)
|
|
|
|
|
|
|
|
runs ->
|
2014-12-03 22:02:47 +03:00
|
|
|
editor = atom.workspace.getActiveTextEditor()
|
2014-08-14 02:55:38 +04:00
|
|
|
|
|
|
|
it "displays a confirmation dialog by default", ->
|
2015-10-06 22:13:57 +03:00
|
|
|
atom.confirm.andCallFake ({buttons}) -> buttons.OK()
|
2014-08-14 05:46:16 +04:00
|
|
|
atom.config.set('editor.confirmCheckoutHeadRevision', true)
|
2014-08-14 02:55:38 +04:00
|
|
|
|
|
|
|
repo.checkoutHeadForEditor(editor)
|
|
|
|
|
|
|
|
expect(fs.readFileSync(filePath, 'utf8')).toBe ''
|
|
|
|
|
|
|
|
it "does not display a dialog when confirmation is disabled", ->
|
2014-08-14 05:46:16 +04:00
|
|
|
atom.config.set('editor.confirmCheckoutHeadRevision', false)
|
2014-08-14 02:55:38 +04:00
|
|
|
|
|
|
|
repo.checkoutHeadForEditor(editor)
|
|
|
|
|
|
|
|
expect(fs.readFileSync(filePath, 'utf8')).toBe ''
|
|
|
|
expect(atom.confirm).not.toHaveBeenCalled()
|
|
|
|
|
2013-01-10 05:12:15 +04:00
|
|
|
describe ".destroy()", ->
|
|
|
|
it "throws an exception when any method is called after it is called", ->
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(require.resolve('./fixtures/git/master.git/HEAD'))
|
2013-01-10 05:12:15 +04:00
|
|
|
repo.destroy()
|
2013-06-13 20:55:42 +04:00
|
|
|
expect(-> repo.getShortHead()).toThrow()
|
2013-02-15 21:08:22 +04:00
|
|
|
|
2013-02-28 03:36:08 +04:00
|
|
|
describe ".getPathStatus(path)", ->
|
2014-05-31 02:20:57 +04:00
|
|
|
[filePath] = []
|
2013-02-28 03:36:08 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2014-05-31 02:20:57 +04:00
|
|
|
workingDirectory = copyRepository()
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(workingDirectory)
|
2014-05-31 02:20:57 +04:00
|
|
|
filePath = path.join(workingDirectory, 'file.txt')
|
2013-02-28 03:36:08 +04:00
|
|
|
|
|
|
|
it "trigger a status-changed event when the new status differs from the last cached one", ->
|
|
|
|
statusHandler = jasmine.createSpy("statusHandler")
|
2014-09-10 01:28:30 +04:00
|
|
|
repo.onDidChangeStatus statusHandler
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(filePath, '')
|
2013-06-13 03:20:40 +04:00
|
|
|
status = repo.getPathStatus(filePath)
|
2013-02-28 03:36:08 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
2014-09-10 01:28:30 +04:00
|
|
|
expect(statusHandler.argsForCall[0][0]).toEqual {path: filePath, pathStatus: status}
|
2013-02-28 03:36:08 +04:00
|
|
|
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(filePath, 'abc')
|
2013-06-13 03:20:40 +04:00
|
|
|
status = repo.getPathStatus(filePath)
|
2013-03-02 06:42:41 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
2013-02-28 03:36:08 +04:00
|
|
|
|
2014-03-29 01:01:21 +04:00
|
|
|
describe ".getDirectoryStatus(path)", ->
|
2014-05-31 02:20:57 +04:00
|
|
|
[directoryPath, filePath] = []
|
2014-03-29 01:01:21 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2014-05-31 02:20:57 +04:00
|
|
|
workingDirectory = copyRepository()
|
2014-09-22 22:07:41 +04:00
|
|
|
repo = new GitRepository(workingDirectory)
|
2014-05-31 02:20:57 +04:00
|
|
|
directoryPath = path.join(workingDirectory, 'dir')
|
|
|
|
filePath = path.join(directoryPath, 'b.txt')
|
2014-03-29 01:01:21 +04:00
|
|
|
|
|
|
|
it "gets the status based on the files inside the directory", ->
|
|
|
|
expect(repo.isStatusModified(repo.getDirectoryStatus(directoryPath))).toBe false
|
|
|
|
fs.writeFileSync(filePath, 'abc')
|
|
|
|
repo.getPathStatus(filePath)
|
|
|
|
expect(repo.isStatusModified(repo.getDirectoryStatus(directoryPath))).toBe true
|
|
|
|
|
2013-02-28 02:48:41 +04:00
|
|
|
describe ".refreshStatus()", ->
|
2016-02-10 18:59:46 +03:00
|
|
|
[newPath, modifiedPath, cleanPath, originalModifiedPathText, workingDirectory] = []
|
2013-02-28 01:07:57 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2014-05-31 02:20:57 +04:00
|
|
|
workingDirectory = copyRepository()
|
2016-08-06 15:44:59 +03:00
|
|
|
repo = new GitRepository(workingDirectory, {project: atom.project, config: atom.config})
|
2014-05-31 02:20:57 +04:00
|
|
|
modifiedPath = path.join(workingDirectory, 'file.txt')
|
|
|
|
newPath = path.join(workingDirectory, 'untracked.txt')
|
|
|
|
cleanPath = path.join(workingDirectory, 'other.txt')
|
|
|
|
fs.writeFileSync(cleanPath, 'Full of text')
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(newPath, '')
|
2014-01-13 13:31:03 +04:00
|
|
|
newPath = fs.absolute newPath # specs could be running under symbol path.
|
2013-02-28 01:07:57 +04:00
|
|
|
|
|
|
|
it "returns status information for all new and modified files", ->
|
2013-11-01 04:11:54 +04:00
|
|
|
fs.writeFileSync(modifiedPath, 'making this path modified')
|
2013-02-28 02:28:30 +04:00
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
2014-09-10 01:45:31 +04:00
|
|
|
repo.onDidChangeStatuses statusHandler
|
2013-02-28 02:48:41 +04:00
|
|
|
repo.refreshStatus()
|
2013-02-28 02:28:30 +04:00
|
|
|
|
|
|
|
waitsFor ->
|
|
|
|
statusHandler.callCount > 0
|
|
|
|
|
|
|
|
runs ->
|
2014-03-29 00:34:21 +04:00
|
|
|
expect(repo.getCachedPathStatus(cleanPath)).toBeUndefined()
|
|
|
|
expect(repo.isStatusNew(repo.getCachedPathStatus(newPath))).toBeTruthy()
|
|
|
|
expect(repo.isStatusModified(repo.getCachedPathStatus(modifiedPath))).toBeTruthy()
|
2013-09-02 22:26:34 +04:00
|
|
|
|
2016-02-10 18:59:46 +03:00
|
|
|
it 'caches the proper statuses when a subdir is open', ->
|
|
|
|
subDir = path.join(workingDirectory, 'dir')
|
|
|
|
fs.mkdirSync(subDir)
|
|
|
|
|
|
|
|
filePath = path.join(subDir, 'b.txt')
|
|
|
|
fs.writeFileSync(filePath, '')
|
|
|
|
|
|
|
|
atom.project.setPaths([subDir])
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('b.txt')
|
|
|
|
|
|
|
|
statusHandler = null
|
|
|
|
runs ->
|
|
|
|
repo = atom.project.getRepositories()[0]
|
|
|
|
|
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
|
|
|
repo.onDidChangeStatuses statusHandler
|
|
|
|
repo.refreshStatus()
|
|
|
|
|
|
|
|
waitsFor ->
|
|
|
|
statusHandler.callCount > 0
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
status = repo.getCachedPathStatus(filePath)
|
|
|
|
expect(repo.isStatusModified(status)).toBe false
|
|
|
|
expect(repo.isStatusNew(status)).toBe false
|
|
|
|
|
2016-08-06 15:44:59 +03:00
|
|
|
it "works correctly when the project has multiple folders (regression)", ->
|
|
|
|
atom.project.addPath(workingDirectory)
|
|
|
|
atom.project.addPath(path.join(__dirname, 'fixtures', 'dir'))
|
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
|
|
|
repo.onDidChangeStatuses statusHandler
|
|
|
|
|
|
|
|
repo.refreshStatus()
|
|
|
|
|
|
|
|
waitsFor ->
|
|
|
|
statusHandler.callCount > 0
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(repo.getCachedPathStatus(cleanPath)).toBeUndefined()
|
|
|
|
expect(repo.isStatusNew(repo.getCachedPathStatus(newPath))).toBeTruthy()
|
|
|
|
expect(repo.isStatusModified(repo.getCachedPathStatus(modifiedPath))).toBeTruthy()
|
|
|
|
|
2016-04-27 19:50:13 +03:00
|
|
|
it 'caches statuses that were looked up synchronously', ->
|
|
|
|
originalContent = 'undefined'
|
|
|
|
fs.writeFileSync(modifiedPath, 'making this path modified')
|
|
|
|
repo.getPathStatus('file.txt')
|
|
|
|
|
|
|
|
fs.writeFileSync(modifiedPath, originalContent)
|
2016-04-28 00:06:37 +03:00
|
|
|
waitsForPromise -> repo.refreshStatus()
|
2016-04-27 19:50:13 +03:00
|
|
|
runs ->
|
|
|
|
expect(repo.isStatusModified(repo.getCachedPathStatus(modifiedPath))).toBeFalsy()
|
|
|
|
|
2013-10-31 01:15:52 +04:00
|
|
|
describe "buffer events", ->
|
2014-05-31 02:24:24 +04:00
|
|
|
[editor] = []
|
2013-09-02 22:26:34 +04:00
|
|
|
|
2013-10-31 01:15:52 +04:00
|
|
|
beforeEach ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([copyRepository()])
|
2013-10-31 01:15:52 +04:00
|
|
|
|
2014-05-31 02:24:24 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
atom.workspace.open('other.txt').then (o) -> editor = o
|
2013-09-02 22:26:34 +04:00
|
|
|
|
2013-10-31 01:15:52 +04:00
|
|
|
it "emits a status-changed event when a buffer is saved", ->
|
2013-11-20 03:22:47 +04:00
|
|
|
editor.insertNewline()
|
2013-09-02 22:26:34 +04:00
|
|
|
|
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.getRepositories()[0].onDidChangeStatus statusHandler
|
2013-11-20 03:22:47 +04:00
|
|
|
editor.save()
|
2013-09-02 22:26:34 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
2014-09-10 01:28:30 +04:00
|
|
|
expect(statusHandler).toHaveBeenCalledWith {path: editor.getPath(), pathStatus: 256}
|
2013-09-02 22:26:34 +04:00
|
|
|
|
2013-10-31 01:15:52 +04:00
|
|
|
it "emits a status-changed event when a buffer is reloaded", ->
|
2013-11-20 03:22:47 +04:00
|
|
|
fs.writeFileSync(editor.getPath(), 'changed')
|
2013-09-02 22:26:34 +04:00
|
|
|
|
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.getRepositories()[0].onDidChangeStatus statusHandler
|
2013-11-20 03:22:47 +04:00
|
|
|
editor.getBuffer().reload()
|
2013-09-02 22:26:34 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
2014-09-10 01:28:30 +04:00
|
|
|
expect(statusHandler).toHaveBeenCalledWith {path: editor.getPath(), pathStatus: 256}
|
2013-11-20 03:22:47 +04:00
|
|
|
editor.getBuffer().reload()
|
2013-09-02 22:26:34 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
2013-09-02 22:46:32 +04:00
|
|
|
|
2013-10-31 01:15:52 +04:00
|
|
|
it "emits a status-changed event when a buffer's path changes", ->
|
2013-11-20 03:22:47 +04:00
|
|
|
fs.writeFileSync(editor.getPath(), 'changed')
|
2013-10-31 01:15:52 +04:00
|
|
|
|
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.getRepositories()[0].onDidChangeStatus statusHandler
|
2014-09-04 22:44:53 +04:00
|
|
|
editor.getBuffer().emitter.emit 'did-change-path'
|
2013-10-31 01:15:52 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
2014-09-10 01:28:30 +04:00
|
|
|
expect(statusHandler).toHaveBeenCalledWith {path: editor.getPath(), pathStatus: 256}
|
2014-09-04 22:44:53 +04:00
|
|
|
editor.getBuffer().emitter.emit 'did-change-path'
|
2013-10-31 01:15:52 +04:00
|
|
|
expect(statusHandler.callCount).toBe 1
|
|
|
|
|
2014-12-12 23:26:09 +03:00
|
|
|
it "stops listening to the buffer when the repository is destroyed (regression)", ->
|
|
|
|
atom.project.getRepositories()[0].destroy()
|
|
|
|
expect(-> editor.save()).not.toThrow()
|
|
|
|
|
2013-09-02 22:46:32 +04:00
|
|
|
describe "when a project is deserialized", ->
|
2014-05-31 02:24:24 +04:00
|
|
|
[buffer, project2] = []
|
2013-09-02 22:46:32 +04:00
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
project2?.destroy()
|
|
|
|
|
|
|
|
it "subscribes to all the serialized buffers in the project", ->
|
2014-10-01 20:37:27 +04:00
|
|
|
atom.project.setPaths([copyRepository()])
|
2014-05-31 02:24:24 +04:00
|
|
|
|
2014-04-24 03:22:44 +04:00
|
|
|
waitsForPromise ->
|
2014-05-31 02:24:24 +04:00
|
|
|
atom.workspace.open('file.txt')
|
2014-04-24 03:22:44 +04:00
|
|
|
|
|
|
|
runs ->
|
2016-05-24 09:10:48 +03:00
|
|
|
project2 = new Project({notificationManager: atom.notifications, packageManager: atom.packages, confirm: atom.confirm, applicationDelegate: atom.applicationDelegate})
|
2016-03-07 12:52:16 +03:00
|
|
|
project2.deserialize(atom.project.serialize({isUnloading: false}))
|
2014-04-24 03:22:44 +04:00
|
|
|
buffer = project2.getBuffers()[0]
|
2013-09-02 22:46:32 +04:00
|
|
|
|
2013-10-17 22:48:22 +04:00
|
|
|
waitsFor ->
|
|
|
|
buffer.loaded
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
originalContent = buffer.getText()
|
|
|
|
buffer.append('changes')
|
|
|
|
|
|
|
|
statusHandler = jasmine.createSpy('statusHandler')
|
2014-10-01 20:37:27 +04:00
|
|
|
project2.getRepositories()[0].onDidChangeStatus statusHandler
|
2013-10-17 22:48:22 +04:00
|
|
|
buffer.save()
|
|
|
|
expect(statusHandler.callCount).toBe 1
|
2014-09-10 01:28:30 +04:00
|
|
|
expect(statusHandler).toHaveBeenCalledWith {path: buffer.getPath(), pathStatus: 256}
|