Make :checkout-head-revision command work w/ multiple repos

This commit is contained in:
Max Brunsfeld
2015-02-24 15:30:04 -08:00
parent cbefdd6c5e
commit 88c2cef91f
3 changed files with 32 additions and 1 deletions

View File

@@ -4018,3 +4018,25 @@ describe "TextEditor", ->
editor.setPlaceholderText('OK')
expect(handler).toHaveBeenCalledWith 'OK'
expect(editor.getPlaceholderText()).toBe 'OK'
describe ".checkoutHeadRevision()", ->
it "reverts to the version of its file checked into the project repository", ->
atom.config.set("editor.confirmCheckoutHeadRevision", false)
editor.setCursorBufferPosition([0, 0])
editor.insertText("---\n")
expect(editor.lineTextForBufferRow(0)).toBe "---"
waitsForPromise ->
editor.checkoutHeadRevision()
runs ->
expect(editor.lineTextForBufferRow(0)).toBe "var quicksort = function () {"
describe "when there's no repository for the editor's file", ->
it "doesn't do anything", ->
editor = new TextEditor({})
editor.setText("stuff")
editor.checkoutHeadRevision()
waitsForPromise -> editor.checkoutHeadRevision()

View File

@@ -337,7 +337,7 @@ atom.commands.add 'atom-text-editor:not([mini])', stopEventPropagationAndGroupUn
'editor:newline-below': -> @insertNewlineBelow()
'editor:newline-above': -> @insertNewlineAbove()
'editor:toggle-line-comments': -> @toggleLineCommentsInSelection()
'editor:checkout-head-revision': -> atom.project.getRepositories()[0]?.checkoutHeadForEditor(this)
'editor:checkout-head-revision': -> @checkoutHeadRevision()
'editor:move-line-up': -> @moveLineUp()
'editor:move-line-down': -> @moveLineDown()
'editor:duplicate-lines': -> @duplicateLines()

View File

@@ -12,6 +12,7 @@ DisplayBuffer = require './display-buffer'
Cursor = require './cursor'
Selection = require './selection'
TextMateScopeSelector = require('first-mate').ScopeSelector
{Directory} = require "pathwatcher"
# Public: This class represents all essential editing state for a single
# {TextBuffer}, including cursor and selection positions, folds, and soft wraps.
@@ -647,6 +648,14 @@ class TextEditor extends Model
else
@isModified() and not @buffer.hasMultipleEditors()
checkoutHeadRevision: ->
if filePath = this.getPath()
atom.project.repositoryForDirectory(new Directory(path.dirname(filePath)))
.then (repository) =>
repository?.checkoutHeadForEditor(this)
else
Promise.resolve(false)
###
Section: Reading Text
###