Newer
Older
namespace LakeDrops\Component\Composer;
/**
* Manages composer.json files.
*/
final class Utils {
/**
* @var string[]
*/
* @var string
*/
/**
* Make sure that git init was called.
*/
protected static function gitInit(): void {
if (!file_exists('.git')) {
passthru(escapeshellcmd('git init --initial-branch=develop'));
/**
* @param string $command
*/
public static function git(string $command, ?string $path = NULL): void {
$prefix = $path === NULL ? '' : 'cd ' . $path . ' && ';
passthru($prefix . escapeshellcmd('git -c "user.email=composer@lakedrops.com" ' . $command));
}
/**
* Helper function to add a new pattern to .gitignore.
*
* @param string $pattern
*/
public static function gitIgnore(string $pattern): void {
if (!isset(self::$ignoredGitPatterns)) {
if (file_exists('.gitignore')) {
self::$ignoredGitPatterns = explode(PHP_EOL, file_get_contents('.gitignore'));
}
else {
self::$ignoredGitPatterns = [];
}
}
if (in_array($pattern, self::$ignoredGitPatterns, TRUE)) {
return;
}
self::$ignoredGitPatterns[] = $pattern;
self::git('ignore ' . $pattern);
}
* @param string $pattern
$output = [];
exec('git lfs track', $output);
self::$lfsGitPatterns = implode(PHP_EOL, $output);
}
if (strpos(self::$lfsGitPatterns, $pattern)) {
return;
}
self::$lfsGitPatterns = $pattern . PHP_EOL;
self::git('lfs track ' . $pattern);
}