Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ManageGitIgnore.php

function 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) && !str_ends_with($contents, "\n")) {
            $contents .= "\n";
        }
    }
    $contents .= implode("\n", $entries);
    file_put_contents($git_ignore_path, $contents);
}
RSS feed
Powered by Drupal