Sha256: f691ca7be6b276f4799e7a45ae793fe43045d64985a51c104c872a45bbfbce6e

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'karo/config'
require 'thor'

module Karo

  module Common Thor

    include Thor::Actions

    def make_command(configuration, namespace, command, extras)
      commands = configuration["commands"]

      if commands && commands[namespace] && commands[namespace][command]
        command = commands[namespace][command]
      end

      extras = extras.flatten(1).uniq.join(" ").strip

      "#{command} #{extras}"
    end

    def run_it(cmd, verbose=false)
      say cmd, :green if verbose
      system cmd unless options[:dryrun]
    end

    def git_repo
      Grit::Repo.new(".")
    end

    def branch_exists?(name)
      git_repo.branches.find { |b| b.name.start_with?(name) }
    end

    def create_branch(name)
      run_it "git branch #{name}", options[:verbose]
    end

    def checkout_branch(name)
      run_it "git checkout #{name}", options[:verbose]
    end

    def current_branch
      git_repo.head.name
    end

    def create_and_checkout_branch(name)
      create_branch name
      checkout_branch name
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
karo-2.4.0 lib/karo/common.rb
karo-2.3.9 lib/karo/common.rb
karo-2.3.8 lib/karo/common.rb