mirror of
https://github.com/atom/atom.git
synced 2026-01-26 07:19:06 -05:00
Incomplete implementation of checkoutHeadForEditor
This commit is contained in:
@@ -215,12 +215,12 @@ describe "GitRepositoryAsync", ->
|
||||
runs ->
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
|
||||
xdescribe ".checkoutHeadForEditor(editor)", ->
|
||||
fdescribe ".checkoutHeadForEditor(editor)", ->
|
||||
[filePath, editor] = []
|
||||
|
||||
beforeEach ->
|
||||
workingDirPath = copyRepository()
|
||||
repo = new GitRepository(workingDirPath)
|
||||
repo = repo = GitRepositoryAsync.open(workingDirPath)
|
||||
filePath = path.join(workingDirPath, 'a.txt')
|
||||
fs.writeFileSync(filePath, 'ch ch changes')
|
||||
|
||||
@@ -242,10 +242,11 @@ describe "GitRepositoryAsync", ->
|
||||
spyOn(atom, 'confirm')
|
||||
atom.config.set('editor.confirmCheckoutHeadRevision', false)
|
||||
|
||||
repo.checkoutHeadForEditor(editor)
|
||||
|
||||
expect(fs.readFileSync(filePath, 'utf8')).toBe ''
|
||||
expect(atom.confirm).not.toHaveBeenCalled()
|
||||
waitsForPromise ->
|
||||
repo.checkoutHeadForEditor(editor)
|
||||
runs ->
|
||||
expect(fs.readFileSync(filePath, 'utf8')).toBe ''
|
||||
expect(atom.confirm).not.toHaveBeenCalled()
|
||||
|
||||
xdescribe ".destroy()", ->
|
||||
it "throws an exception when any method is called after it is called", ->
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
'use babel'
|
||||
const atom = window.atom
|
||||
|
||||
const Git = require('nodegit')
|
||||
const path = require('path')
|
||||
@@ -89,6 +90,39 @@ module.exports = class GitRepositoryAsync {
|
||||
})
|
||||
}
|
||||
|
||||
checkoutHeadForEditor (editor) {
|
||||
var filePath = editor.getPath()
|
||||
if (!filePath) {
|
||||
return Promise.reject('editor.filePath() is empty')
|
||||
}
|
||||
|
||||
var fileName = path.basename(filePath)
|
||||
var checkoutHead = () => {
|
||||
if (editor.buffer.isModified()) {
|
||||
editor.buffer.reload()
|
||||
}
|
||||
return this.checkoutHead(filePath)
|
||||
}
|
||||
|
||||
var confirmCheckout = function () {
|
||||
// This is bad tho
|
||||
return Promise.resolve(atom.confirm({
|
||||
message: 'Confirm Checkout HEAD Revision',
|
||||
detailedMessage: `Are you sure you want to discard all changes to "${fileName}" since the last Git commit?`,
|
||||
buttons: {
|
||||
OK: checkoutHead,
|
||||
Cancel: null
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
if (atom.config.get('editor.confirmCheckoutHeadRevision')) {
|
||||
return confirmCheckout()
|
||||
} else {
|
||||
return checkoutHead()
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a Promise that resolves to the status bit of a given path if it has
|
||||
// one, otherwise 'current'.
|
||||
getPathStatus (_path) {
|
||||
|
||||
Reference in New Issue
Block a user