Class: BigKeeper::GitService

Inherits:
Object
  • Object
show all
Defined in:
lib/big_keeper/service/git_service.rb

Overview

Operator for got

Instance Method Summary collapse

Instance Method Details

#branchs_with_type(path, type) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/big_keeper/service/git_service.rb', line 37

def branchs_with_type(path, type)
  branchs = []
  Dir.chdir(path) do
    IO.popen('git branch -a') do |io|
      io.each do |line|
        branchs << line.rstrip if line =~ /(\* |  )#{GitflowType.name(type)}*/
      end
    end
  end
  branchs
end

#verify_branch(path, branch_name, type) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/big_keeper/service/git_service.rb', line 8

def verify_branch(path, branch_name, type)
  GitOperator.new.git_fetch(path)

  if OperateType::START == type
    if GitOperator.new.current_branch(path) == branch_name
      raise %(Current branch is '#{branch_name}' already. Use 'update' please)
    end
    if GitOperator.new.has_branch(path, branch_name)
      raise %(Branch '#{branch_name}' already exists. Use 'switch' please)
    end
  elsif OperateType::SWITCH == type
    if !GitOperator.new.has_branch(path, branch_name)
      raise %(Can't find a branch named '#{branch_name}'. Use 'start' please)
    end
    if GitOperator.new.current_branch(path) == branch_name
      raise %(Current branch is '#{branch_name}' already. Use 'update' please)
    end
  elsif OperateType::UPDATE == type
    if !GitOperator.new.has_branch(path, branch_name)
      raise %(Can't find a branch named '#{branch_name}'. Use 'start' please)
    end
    if GitOperator.new.current_branch(path) != branch_name
      raise %(Current branch is not '#{branch_name}'. Use 'switch' please)
    end
  else
    raise %(Not a valid command for '#{branch_name}'.)
  end
end

#verify_rebase(path, branch_name, name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/big_keeper/service/git_service.rb', line 49

def verify_rebase(path, branch_name, name)
  Dir.chdir(path) do
    IO.popen("git rebase #{branch_name} --ignore-whitespace") do |io|
      unless io.gets
        raise "#{name} is already in a rebase-apply, Please:\n\
              1.Resolve it;\n\
              2.Commit the changes;\n\
              3.Push to remote;\n\
              4.Create a MR;\n\
              5.Run 'finish' again."
      end
      io.each do |line|
        next unless line.include? 'Merge conflict'
        raise "Merge conflict in #{name}, Please:\n\
              1.Resolve it;\n\
              2.Commit the changes;\n\
              3.Push to remote;\n\
              4.Create a MR;\n\
              5.Run 'finish' again."
      end
    end
    `git push -f origin #{branch_name}`
    GitOperator.new.git_checkout(path, 'develop')
  end
end