diff --git a/BaseHandler.php b/BaseHandler.php index b9bfe9bc3e7779cbfb29c72cb574bfbdab406d38..b9289e31b187c987826c7d308a932b6651ba0331 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 da60ee0b103c5b7bc8f1203ea53c500593881f5d..e818168b86c7023340630afd2da3a9f4712bfa06 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 277e6b682ecfd153967729f7f47c41cb76e11c56..34c5d0b94d0e89e59cfc99188f381b3c416da873 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); + } + }