function ManageGitIgnore::addToGitIgnore

Same name in other branches
  1. 8.9.x composer/Plugin/Scaffold/ManageGitIgnore.php \Drupal\Composer\Plugin\Scaffold\ManageGitIgnore::addToGitIgnore()
  2. 10 composer/Plugin/Scaffold/ManageGitIgnore.php \Drupal\Composer\Plugin\Scaffold\ManageGitIgnore::addToGitIgnore()
  3. 11.x composer/Plugin/Scaffold/ManageGitIgnore.php \Drupal\Composer\Plugin\Scaffold\ManageGitIgnore::addToGitIgnore()

Adds a set of entries to the specified .gitignore file.

Parameters

string $dir: Path to directory where gitignore should be written.

string[] $entries: Entries to write to .gitignore file.

1 call to ManageGitIgnore::addToGitIgnore()
ManageGitIgnore::manageIgnored in composer/Plugin/Scaffold/ManageGitIgnore.php
Manages gitignore files.

File

composer/Plugin/Scaffold/ManageGitIgnore.php, line 110

Class

ManageGitIgnore
Manage the .gitignore file.

Namespace

Drupal\Composer\Plugin\Scaffold

Code

protected function addToGitIgnore($dir, array $entries) {
    sort($entries);
    $git_ignore_path = $dir . '/.gitignore';
    $contents = '';
    // Appending to existing .gitignore files.
    if (file_exists($git_ignore_path)) {
        $contents = file_get_contents($git_ignore_path);
        if (!empty($contents) && substr($contents, -1) != "\n") {
            $contents .= "\n";
        }
    }
    $contents .= implode("\n", $entries);
    file_put_contents($git_ignore_path, $contents);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.