Module: Karo::Common

Includes:
Thor::Actions
Included in:
Assets, CLI, Db, Workflow
Defined in:
lib/karo/common.rb

Instance Method Summary collapse

Instance Method Details

#branch_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/karo/common.rb', line 31

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

#checkout_branch(name) ⇒ Object



39
40
41
# File 'lib/karo/common.rb', line 39

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

#create_and_checkout_branch(name) ⇒ Object



47
48
49
50
# File 'lib/karo/common.rb', line 47

def create_and_checkout_branch(name)
  create_branch name
  checkout_branch name
end

#create_branch(name) ⇒ Object



35
36
37
# File 'lib/karo/common.rb', line 35

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

#current_branchObject



43
44
45
# File 'lib/karo/common.rb', line 43

def current_branch
  git_repo.head.name
end

#git_repoObject



27
28
29
# File 'lib/karo/common.rb', line 27

def git_repo
  Rugged::Repository.new(".")
end

#make_command(configuration, namespace, command, extras) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/karo/common.rb', line 10

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

#run_it(cmd, verbose = false) ⇒ Object



22
23
24
25
# File 'lib/karo/common.rb', line 22

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