Skip to content
Snippets Groups Projects
Commit e805a3e4 authored by jurgenhaas's avatar jurgenhaas
Browse files

composer/plugin/docker4drupal#33 Better handling of git ignore

parent a7e8ba09
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,11 @@ abstract class BaseHandler implements BaseHandlerInterface {
*/
protected $drupalCorePackage;
/**
* @var string[]
*/
protected $ignoredGitPatterns;
/**
* Handler constructor.
*
......@@ -129,4 +134,25 @@ abstract class BaseHandler implements BaseHandlerInterface {
passthru(escapeshellcmd('git -c "user.email=composer@lakedrops.com" ' . $command));
}
/**
* {@inheritdoc}
*/
public function gitIgnore($pattern) {
if ($this->ignoredGitPatterns === NULL) {
if (file_exists('.gitignore')) {
$this->ignoredGitPatterns = explode(PHP_EOL, file_get_contents('.gitignore'));
}
else {
$this->ignoredGitPatterns = [];
}
}
if (\in_array($pattern, $this->ignoredGitPatterns, TRUE)) {
return;
}
$this->ignoredGitPatterns[] = $pattern;
$this->git('ignore ' . $pattern);
}
}
......@@ -66,4 +66,12 @@ interface BaseHandlerInterface {
*/
public function git($command);
/**
* Add the given pattern to gitignore if necessary.
*
* @param string $pattern
* The pattern which should be ignored.
*/
public function gitIgnore($pattern);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment