mirror of
https://github.com/atom/atom.git
synced 2026-01-28 00:08:13 -05:00
Incomplete implementation of checkoutHeadForEditor
This commit is contained in:
@@ -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