class_docstr: File-based Code Driver handles source control management for the project with files
      
class_docstr_tok: ["File-based","Code","Driver","handles","source","control","management","for","the","project","with","files"]
docstr: Add all files except for those in .datmoignore, and make a commit
  
  If the commit_id is given, it will return the same commit_id or error
  
  Parameters
  ----------
  commit_id : str, optional
      if commit_id is given, it will ensure this commit_id exists and not create a new one
  
  Returns
  -------
  commit_id : str, optional
      if commit_id is given, it will not add files and will not create a commit
  
  Raises
  ------
  CodeNotInitialized
      error if not initialized (must initialize first)
  CommitDoesNotExist
      commit id specified does not match a valid commit
  CommitFailed
      commit could not be created
docstr_tok: ["Add","all","files","except","for","those","in",".datmoignore",",","and","make","a","commit","If","the","commit_id","is","given",",","it","will","return","the","same","commit_id","or","error","Parameters","--","--","--","--","--","commit_id",":","str",",","optional","if","commit_id","is","given",",","it","will","ensure","this","commit_id","exists","and","not","create","a","new","one","Returns","--","--","--","-","commit_id",":","str",",","optional","if","commit_id","is","given",",","it","will","not","add","files","and","will","not","create","a","commit","Raises","--","--","--","CodeNotInitialized","error","if","not","initialized","(","must","initialize","first",")","CommitDoesNotExist","commit","id","specified","does","not","match","a","valid","commit","CommitFailed","commit","could","not","be","created"]
code: def create_ref(self, commit_id=None):
      """Add all files except for those in .datmoignore, and make a commit
  
      If the commit_id is given, it will return the same commit_id or error
  
      Parameters
      ----------
      commit_id : str, optional
          if commit_id is given, it will ensure this commit_id exists and not create a new one
  
      Returns
      -------
      commit_id : str, optional
          if commit_id is given, it will not add files and will not create a commit
  
      Raises
      ------
      CodeNotInitialized
          error if not initialized (must initialize first)
      CommitDoesNotExist
          commit id specified does not match a valid commit
      CommitFailed
          commit could not be created
      """
      if not self.is_initialized:
          raise CodeNotInitialized()
      # If commit is given and it exists then just return it back
      if commit_id:
          if not self.exists_ref(commit_id):
              raise CommitDoesNotExist(
                  __(
                      "error",
                      "controller.code.driver.file.create_ref.no_commit",
                      commit_id,
                  )
              )
          return commit_id
      # Find all tracked files (_get_tracked_files)
      tracked_filepaths = self._get_tracked_files()
      # Create the hash of the files (_calculate_commit_hash)
      commit_hash = self._calculate_commit_hash(tracked_filepaths)
      # Check if the hash already exists with exists_ref
      if self.exists_ref(commit_hash):
          return commit_hash
      # Create a new file with the commit hash if it is new, else ERROR (no changes)
      commit_filepath = os.path.join(self._code_filepath, commit_hash)
      with open(commit_filepath, "a+") as f:
          # Loop through the tracked files
          for tracked_filepath in tracked_filepaths:
              absolute_filepath = os.path.join(
                  self.root, tracked_filepath
              )
              absolute_dirpath = os.path.join(
                  self._code_filepath, tracked_filepath
              )
              # 1) create dir for file (use path name from tracked files list) -- if already exists skip
              if not os.path.isdir(absolute_dirpath):
                  os.makedirs(absolute_dirpath)
              # 2) hash the file
              filehash = self._get_filehash(absolute_filepath)
              # 3) add file with file hash as name to folder for the file (if already exists, will overwrite file -- new ts)
              new_absolute_filepath = os.path.join(
                  absolute_dirpath, filehash
              )
              shutil.copy2(absolute_filepath, new_absolute_filepath)
              # 4) append a line into the new file for the commit hash with the following "filepath, filehash"
              f.write(tracked_filepath + "," + filehash + "\n")
      # Return commit hash if success else ERROR
      return commit_hash
  
imports: import os
  import shutil
  import errno
  import pathspec
  import tempfile
  import hashlib
  import checksumdir
  from datmo.core.util.misc_functions import list_all_filepaths
  from datmo.core.util.i18n import get
  from datmo.core.util.exceptions import PathDoesNotExist, FileIOError, UnstagedChanges, CodeNotInitialized, CommitDoesNotExist
  from datmo.core.controller.code.driver import CodeDriver
label_desc: Use image node_id 10 for calling the FileCodeDriver obj's underlying member method code with example usage: obj.create_ref(commit_id) and returns: commit_hash, commit_id, commit_hash