Sha256: 785b1f6ecdf98eaecfbece9d513120c3de508a0b87000d625891b94062ef6657

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

require 'thor'
require 'pathname'
require 'rugged'
require 'gitx'
require 'gitx/executor'

module Gitx
  module Cli
    class BaseCommand < Thor
      include Thor::Actions

      class MergeError < Thor::Error; end

      add_runtime_options!

      private

      def repo
        @repo ||= begin
          path = Dir.pwd
          Rugged::Repository.discover(path)
        end
      end

      def run_cmd(*cmd)
        executor.execute(*cmd) do |output|
          say(output, :yellow)
        end
      end

      def run_git_cmd(*cmd)
        run_cmd('git', *cmd)
      end

      def checkout_branch(branch_name)
        run_git_cmd 'checkout', branch_name
      end

      # lookup the current branch of the repo
      def current_branch
        repo.branches.find(&:head?)
      end

      def assert_aggregate_branch!(target_branch)
        fail "Invalid aggregate branch: #{target_branch} must be one of supported aggregate branches #{config.aggregate_branches}" unless config.aggregate_branch?(target_branch)
      end

      def assert_not_protected_branch!(branch, action)
        fail "Cannot #{action} reserved branch" if config.reserved_branch?(branch) || config.aggregate_branch?(branch)
      end

      def config
        @configuration ||= Gitx::Configuration.new(repo.workdir)
      end

      def executor
        @executor ||= Gitx::Executor.new
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gitx-2.23.0.ci.162.1 lib/gitx/cli/base_command.rb
gitx-2.23.0 lib/gitx/cli/base_command.rb
gitx-2.22.0.ci.154.1 lib/gitx/cli/base_command.rb
gitx-2.22.0 lib/gitx/cli/base_command.rb
gitx-2.21.5.ci.153.1 lib/gitx/cli/base_command.rb
gitx-2.21.5.ci.151.1 lib/gitx/cli/base_command.rb
gitx-2.21.5 lib/gitx/cli/base_command.rb
gitx-2.21.4.ci.145.1 lib/gitx/cli/base_command.rb
gitx-2.21.4 lib/gitx/cli/base_command.rb