Merge pull request #1524 from atom/ks-clear-conflict-on-save

Clear conflict on save
This commit is contained in:
Kevin Sawicki
2014-02-11 08:52:48 -08:00
2 changed files with 31 additions and 10 deletions

View File

@@ -571,6 +571,23 @@ describe 'TextBuffer', ->
saveBuffer.reload()
expect(events).toEqual ['will-reload', 'reloaded']
it "no longer reports being in conflict", ->
saveBuffer.setText('a')
saveBuffer.save()
saveBuffer.setText('ab')
fs.writeFileSync(saveBuffer.getPath(), 'c')
conflictHandler = jasmine.createSpy('conflictHandler')
saveBuffer.on 'contents-conflicted', conflictHandler
waitsFor ->
conflictHandler.callCount > 0
runs ->
expect(saveBuffer.isInConflict()).toBe true
saveBuffer.save()
expect(saveBuffer.isInConflict()).toBe false
describe "when the buffer has no path", ->
it "throws an exception", ->
saveBuffer = atom.project.bufferForPathSync(null)

View File

@@ -165,14 +165,14 @@ class TextBuffer extends TextBufferCore
# Sets the path for the file.
#
# path - A {String} representing the new file path
setPath: (path) ->
return if path == @getPath()
# filePath - A {String} representing the new file path
setPath: (filePath) ->
return if filePath == @getPath()
@file?.off()
if path
@file = new File(path)
if filePath
@file = new File(filePath)
@subscribeToFile()
else
@file = null
@@ -188,14 +188,15 @@ class TextBuffer extends TextBufferCore
# Saves the buffer at a specific path.
#
# path - The path to save at.
saveAs: (path) ->
unless path then throw new Error("Can't save buffer with no file path")
# filePath - The path to save at.
saveAs: (filePath) ->
unless filePath then throw new Error("Can't save buffer with no file path")
@emit 'will-be-saved', this
@setPath(path)
@setPath(filePath)
@cachedDiskContents = @getText()
@file.write(@getText())
@conflict = false
@emitModifiedStatusChanged(false)
@emit 'saved', this
@@ -212,7 +213,10 @@ class TextBuffer extends TextBufferCore
else
not @isEmpty()
# Identifies if a buffer is in a git conflict with `HEAD`.
# Is the buffer's text in conflict with the text on disk?
#
# This occurs when the buffer's file changes on disk while the buffer has
# unsaved changes.
#
# Returns a {Boolean}.
isInConflict: -> @conflict