mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Make :checkout-head-revision command work w/ multiple repos
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
###
|
||||
|
||||
Reference in New Issue
Block a user