           oid: oid
           path: newPath
           fileSize: buffer.length
-          mode: patch.newFile().mode()
+          mode: fileDiff.getMode()
 
       data.index.removeByPath(oldPath) if oldPath != newPath
       data.index.add(entry)

    patchText = "#{header}#{lines.join("\n")}\n"
    Promise.resolve(patchText)

  stagePatch: (patchText, patch) =>
    data = {}
    oldPath = patch.oldFile().path()
    newPath = patch.newFile().path()
    Git.Repository.open(@repoPath)
    .then (repo) ->
      data.repo = repo
      repo.openIndex()
    .then (index) =>
      data.index = index
      @indexBlob(oldPath) unless patch.isUntracked()
    .then (content) =>
      newContent = JsDiff.applyPatch(content ? '', patchText)
      console.log patchText, newContent
      buffer = new Buffer(newContent)
      oid    = data.repo.createBlobFromBuffer(buffer)

      if patch.isDeleted()
        entry = data.index.getByPath(oldPath)
        entry.id = oid
        entry.fileSize = buffer.length

          oid: oid
          path: newPath
          fileSize: buffer.length
          mode: fileDiff.getMode()
        data.index.add(entry)
        data.index.write()
    .then =>
