Exemple #1
0
 /**
  * @param User         $user
  * @param FilePath     $relativeFilePath
  * @param UploadedFile $uploadedFile
  * @param string       $commitMessage
  *
  * @throws FileExistsException
  */
 public function addFile(User $user, FilePath $relativeFilePath, UploadedFile $uploadedFile, $commitMessage)
 {
     $relativeDirectoryPath = $relativeFilePath->getParentPath();
     if ($this->gitRepository->exists($relativeFilePath)) {
         throw new FileExistsException('File ' . $relativeFilePath->toRelativeFileString() . ' already exists');
     }
     if (!$this->gitRepository->exists($relativeDirectoryPath)) {
         $this->gitRepository->mkdir($relativeDirectoryPath);
     }
     $this->createLock($user, $relativeFilePath);
     $uploadedFile->move($this->gitRepository->getAbsolutePath($relativeDirectoryPath), $relativeFilePath->getName());
     $this->gitRepository->addAndCommit($this->getAuthor($user), $commitMessage, $relativeFilePath);
     $this->removeLock($user, $relativeFilePath);
 }