function ManageGitIgnore::manageIgnored

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

Manages gitignore files.

Parameters

\Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult[] $files: A list of scaffold results, each of which holds a path and whether or not that file is managed.

\Drupal\Composer\Plugin\Scaffold\ScaffoldOptions $options: Configuration options from the composer.json extras section.

File

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

Class

ManageGitIgnore
Manage the .gitignore file.

Namespace

Drupal\Composer\Plugin\Scaffold

Code

public function manageIgnored(array $files, ScaffoldOptions $options) {
    if (!$this->managementOfGitIgnoreEnabled($options)) {
        return;
    }
    // Accumulate entries to add to .gitignore, sorted into buckets based on the
    // location of the .gitignore file the entry should be added to.
    $add_to_git_ignore = [];
    foreach ($files as $scaffoldResult) {
        $path = $scaffoldResult->destination()
            ->fullPath();
        $is_ignored = Git::checkIgnore($this->io, $path, $this->dir);
        if (!$is_ignored) {
            $is_tracked = Git::checkTracked($this->io, $path, $this->dir);
            if (!$is_tracked && $scaffoldResult->isManaged()) {
                $dir = realpath(dirname($path));
                $name = basename($path);
                $add_to_git_ignore[$dir][] = '/' . $name;
            }
        }
    }
    // Write out the .gitignore files one at a time.
    foreach ($add_to_git_ignore as $dir => $entries) {
        $this->addToGitIgnore($dir, $entries);
    }
}

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