   # initialText - A {String} setting the starting text
   constructor: (optionsOrState={}, params={}) ->
     if optionsOrState instanceof telepath.Document
+      {@project} = params
       @state = optionsOrState
       @text = @state.get('text')
       filePath = @state.get('relativePath')
       @id = @state.get('id')
     else
-      {filePath, initialText} = optionsOrState
+      {@project, filePath, initialText} = optionsOrState
       @text = site.createDocument(initialText, shareStrings: true) if initialText
       @id = guid.create().toString()
       @state = site.createDocument

        version: @constructor.version

    if filePath
      @setPath(project.resolve(filePath))
      if @text
        @updateCachedDiskContents()
      else

  checkoutHead: ->
    path = @getPath()
    return unless path
    @project.getRepo()?.checkoutHead(path)

  # Checks to see if a file exists.
  #
