Sha256: c053e976a4a80ed971d484a382481676bf7a4a122a6fe09b72e577ef87467cfd

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

module Braid
  class Command
    include Operations::Mirror
    include Operations::Helpers

    class << self
      include Operations::Helpers
      include Operations::Git

      def run(command, *args)
        raise Braid::Git::VersionTooLow unless verify_git_version(REQUIRED_GIT_VERSION)

        klass = Braid::Commands.const_get(command.to_s.capitalize)
        klass.new.run(*args)

      rescue Braid::Git::LocalChangesPresent => e
        msg "Local changes are present. You have to commit or stash them before running braid commands."
        msg "Exiting."

      rescue Braid::Git::VersionTooLow => e
        msg "This version of braid requires at least git #{REQUIRED_GIT_VERSION}. You have #{extract_git_version}."
        msg "Exiting."

      rescue => e
        # FIXME
      end

      def msg(str)
        puts str
      end
    end

    def config
      @config ||= Braid::Config.new
    end

    private
      def msg(str)
        self.class.msg(str)
      end

      def in_work_branch
        # make sure there is a git repository
        begin
          old_branch = get_current_branch
        rescue => e
          msg "Error occured: #{e.message}"
          raise e
        end

        create_work_branch
        work_head = get_work_head

        begin
          invoke(:git_checkout, WORK_BRANCH)
          yield
        rescue => e
          msg "Error occured: #{e.message}"
          if get_current_branch == WORK_BRANCH
            msg "Resetting '#{WORK_BRANCH}' to '#{work_head}'."
            invoke(:git_reset_hard, work_head)
          end
          raise e
        ensure
          invoke(:git_checkout, old_branch)
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
evilchelu-braid-0.3.8 lib/braid/command.rb
evilchelu-braid-0.4.0 lib/braid/command.rb