From 6857146aab806c346c44c95b8b7ebfe5c6e1f52e Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Sat, 22 Dec 2018 22:30:55 +0100 Subject: [PATCH] composer/plugin/docker4drupal#33 Better handling of git lfs as well --- BaseHandler.php | 7 +++++++ BaseHandlerInterface.php | 8 ++++++++ Utils.php | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/BaseHandler.php b/BaseHandler.php index b9bfe9b..b9289e3 100644 --- a/BaseHandler.php +++ b/BaseHandler.php @@ -136,4 +136,11 @@ abstract class BaseHandler implements BaseHandlerInterface { Utils::gitIgnore($pattern); } + /** + * {@inheritdoc} + */ + public function gitLFS($pattern) { + Utils::gitLFS($pattern); + } + } diff --git a/BaseHandlerInterface.php b/BaseHandlerInterface.php index da60ee0..e818168 100644 --- a/BaseHandlerInterface.php +++ b/BaseHandlerInterface.php @@ -74,4 +74,12 @@ interface BaseHandlerInterface { */ public function gitIgnore($pattern); + /** + * Add the given pattern to git lfs if necessary. + * + * @param string $pattern + * The pattern which should be added. + */ + public function gitLFS($pattern); + } diff --git a/Utils.php b/Utils.php index 277e6b6..34c5d0b 100644 --- a/Utils.php +++ b/Utils.php @@ -43,6 +43,11 @@ final class Utils { */ private static $ignoredGitPatterns; + /** + * @var string + */ + private static $lfsGitPatterns; + /** * Utils constructor. * @@ -202,4 +207,22 @@ final class Utils { self::git('ignore ' . $pattern); } + /** + * @param string $pattern + */ + public static function gitLFS($pattern) { + if (self::$lfsGitPatterns === NULL) { + $output = []; + exec('git lfs track', $output); + self::$lfsGitPatterns = implode(PHP_EOL, $output); + } + + if (strpos(self::$lfsGitPatterns, $pattern)) { + return; + } + + self::$lfsGitPatterns = $pattern . PHP_EOL; + self::git('lfs track ' . $pattern); + } + } -- GitLab