require 'eac_launcher/publish/base' module EacLauncher module Git class PublishBase < ::EacLauncher::Publish::Base include ::Eac::SimpleCache include ::EacRubyUtils::Console::Speaker def initialize(instance) @instance = instance end protected def internal_check if publish_remote_no_exist? ::EacLauncher::Publish::CheckResult.blocked('Remote does not exist') elsif remote_equal_or_following? ::EacLauncher::Publish::CheckResult.updated('Remote equal or following') elsif local_following? ::EacLauncher::Publish::CheckResult.pending('Local following') else divergent_result end end private def divergent_result ::EacLauncher::Publish::CheckResult.blocked( "Divergent (L: #{local_sha}, R: #{remote_sha})" ) end def publish_remote_no_exist? !sgit.remote_exist?(::EacLauncher::Git::WarpBase::TARGET_REMOTE) end def sgit_uncached ::EacLauncher::Git::Base.new(@instance.current_cache) end def publish info 'Pushing...' sgit.push(::EacLauncher::Git::WarpBase::TARGET_REMOTE, 'HEAD:master', dryrun: !::EacLauncher::Context.current.publish_options[:confirm]) info 'Pushed!' end def remote_equal_or_following? return false if remote_sha.blank? remote_sha == local_sha || sgit.descendant?(remote_sha, local_sha) end def local_following? return true if remote_sha.blank? sgit.descendant?(local_sha, remote_sha) end def local_sha sgit.git.object('HEAD').sha end def remote_sha_uncached sgit.fetch(::EacLauncher::Git::WarpBase::TARGET_REMOTE) b = sgit.git.branches["#{::EacLauncher::Git::WarpBase::TARGET_REMOTE}/master"] b ? b.gcommit.sha : nil end end end end