public function writeFile($path, $data, $commitMsg = null, $fileMode = null, $dirMode = null, $recursive = true, $author = null)
{
$file = $this->resolveFullPath($path);
$fileMode = $fileMode ?: $this->getFileCreationMode();
$dirMode = $dirMode ?: $this->getDirectoryCreationMode();
$directory = dirname($file);
if (!file_exists($directory) && !mkdir($directory, (int) $dirMode, $recursive)) {
throw new \RuntimeException(sprintf('Cannot create "%s"', $directory));
} else {
if (!file_exists($file)) {
if (!touch($file)) {
throw new \RuntimeException(sprintf('Cannot create "%s"', $file));
}
if (!chmod($file, (int) $fileMode)) {
throw new \RuntimeException(sprintf('Cannot chmod "%s" to %d', $file, (int) $fileMode));
}
}
}
if (file_put_contents($file, $data) === false) {
throw new \RuntimeException(sprintf('Cannot write to "%s"', $file));
}
$this->add(array($file));
if ($commitMsg === null) {
$commitMsg = sprintf('%s created or changed file "%s"', __CLASS__, $path);
}
$this->commit($commitMsg, null, $author);
return $this->getCurrentCommit();
}