Incomplete implementation of checkoutHeadForEditor

This commit is contained in:
Daniel Hengeveld
2015-10-20 18:02:47 +02:00
parent 4c0c732766
commit bea002bddb
2 changed files with 41 additions and 6 deletions

View File

@@ -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) {