module EacLauncher module Stereotypes class GitSubrepo class Warp < ::EacLauncher::Path include ::Eac::SimpleCache attr_reader :instance def initialize(instance) @instance = instance check_parent init_aux fetch push reset assert_target_remote super(cache_git) end private def check_parent return if parent_cache_git.rev_parse(subrepo_parent_hash) && parent_cache_git.descendant?('HEAD', subrepo_parent_hash) raise EacLauncher::Instances::Error, "Subrepo parent hash \"#{subrepo_parent_hash}\""\ " not found in \"#{parent_cache_git}\"" end def subrepo_parent_hash h = parent_cache_git.subrepo_status(instance.to_parent_path)['Pull Parent'] return h if h.present? raise 'Subrepo parent hash is blank' end def init_aux ::EacLauncher::Git::Base.new(aux_path).init_bare end def parent_instance instance.parent end def parent_git_uncached ::EacLauncher::Git::Base.new(instance.parent) end def parent_cache_git_uncached ::EacLauncher::Git::Base.new(parent_instance.current_cache) end def aux_path instance.cache_path('subrepo_aux_git_repository') end def cache_git_uncached ::EacLauncher::Git::Base.new(instance.cache_path('git_repository')) end def fetch parent_cache_git.execute!('subrepo', 'clean', subrepo_subdir) parent_cache_git.execute!('subrepo', 'fetch', subrepo_subdir) end def push parent_cache_git.execute!('subrepo', 'push', subrepo_subdir, '-r', aux_path, '-f') end def subrepo_subdir instance.to_parent_path.gsub(%r{\A/+}, '') end def reset ::EacLauncher::Git::MirrorUpdate.new(cache_git, aux_path, 'master') end def assert_target_remote cache_git.assert_remote_url(::EacLauncher::Git::WarpBase::TARGET_REMOTE, target_remote_url) end def target_remote_url ::EacLauncher::Vendor::Github.to_ssh_url( parent_git.git.remote("subrepo/#{subrepo_subdir}").url ) end end end end end