Sha256: a1961f8473beae4e9123e4b5f37d1e6330225eb2547d07b4d27258aeb9b1d780

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

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.warped)
      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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eac_launcher-0.2.2 lib/eac_launcher/git/publish_base.rb
eac_launcher-0.2.1 lib/eac_launcher/git/publish_base.rb