From e805a3e49917bd8521a8a25af81b2f00c6012f22 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Sat, 22 Dec 2018 21:26:34 +0100
Subject: [PATCH] composer/plugin/docker4drupal#33 Better handling of git
 ignore

---
 BaseHandler.php          | 26 ++++++++++++++++++++++++++
 BaseHandlerInterface.php |  8 ++++++++
 2 files changed, 34 insertions(+)

diff --git a/BaseHandler.php b/BaseHandler.php
index d490a59..dfcee3d 100644
--- a/BaseHandler.php
+++ b/BaseHandler.php
@@ -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);
+  }
+
 }
diff --git a/BaseHandlerInterface.php b/BaseHandlerInterface.php
index 7f485bb..da60ee0 100644
--- a/BaseHandlerInterface.php
+++ b/BaseHandlerInterface.php
@@ -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);
+
 }
-- 
GitLab