From a634a66ca7a1b800c7677e1adac93c2c36b7ee56 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 28 Aug 2021 13:28:43 -0300 Subject: [PATCH] =?UTF-8?q?Inicializar=20subm=C3=B3dulos=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/site/repository.rb | 10 ++++++++++ app/services/site_service.rb | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/site/repository.rb b/app/models/site/repository.rb index 74db2549..9f0159d0 100644 --- a/app/models/site/repository.rb +++ b/app/models/site/repository.rb @@ -14,6 +14,16 @@ class Site @rugged = Rugged::Repository.new(path) end + # Obtiene todos los submódulos, clonando los repositorios en las + # ubicaciones que corresponden y haciendo un checkout del OID que + # corresponde. + def submodules_update! + rugged.submodules.each do |submodule| + Rugged::Repository.clone_at submodule.url, File.join(path, submodule.path) + submodule.repository.checkout submodule.index_oid + end + end + # Obtiene la rama por defecto a partir de la referencia actual # # Por ejemplo "refs/heads/no-master" => "no-master" diff --git a/app/services/site_service.rb b/app/services/site_service.rb index 389549c3..3b45134b 100644 --- a/app/services/site_service.rb +++ b/app/services/site_service.rb @@ -61,14 +61,18 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do commit_config(action: :tor) end - # Trae cambios desde la rama remota y reindexa los artículos. + # Trae cambios desde la rama remota, actualiza submódulos (plantillas) + # y reindexa los artículos. # # @return [Boolean] def merge result = site.repository.merge(usuarie) # TODO: Implementar callbacks - site.try(:index_posts!) if result + if result + site.repository.submodules_update! + site.try(:index_posts!) + end result.present? end