Module: GGSM::Finish

Includes:
Submodule
Included in:
Cli
Defined in:
lib/ggsm/command/finish.rb

Instance Method Summary collapse

Methods included from Submodule

#check_submodule, #check_submodule_status, #check_un_commit_code, #correct_dir, #foreach_module, #get_current_branch, #get_head_commit, #get_lastest_msg, #get_lastest_msg_not_merge, #get_lastest_msg_of_module, #get_modified_submodule, #get_submodule, #get_submodule_commit, #is_submodule, #tip_contact_author

Methods included from Hooks

#check_hooks, #cp_files, #cp_hooks, #install_billow, #update_hooks

Instance Method Details

#finish_flow(force) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ggsm/command/finish.rb', line 8

def finish_flow(force)
  check_submodule

  foreach_module {
    process_finish(false)
  }

  puts '==> 进入主工程:'.yellow
  process_finish(force, get_main_project_msg)

  puts 'Modules执行:git add & commit & push'.blue
end

#get_main_project_msgObject



46
47
48
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
74
75
76
77
78
79
# File 'lib/ggsm/command/finish.rb', line 46

def get_main_project_msg()
  system 'git add .'

  pattern = /[A-Z]\s*(.*)/
  result = `git status -s | grep -e '[A-Z].*'`.split(/\n/).delete_if do |r|
    r == ''
  end
  modified = []
  result.each do |r|
    if match = r.match(pattern)
      module_name = match[1].strip
      if is_submodule(module_name)
        modified.push(match[1].strip)
      end
    end
  end

  whole_files = `git status -s`.split(/\n/).delete_if do |w|
    w == ''
  end
  return '' if whole_files.length != modified.length

  outputs = ''
  modified.each_with_index do |m, index|
    msg = get_lastest_msg_of_module(m)
    outputs += msg.insert(msg.index(':') + 1, "[#{get_module_name(m)}]")
    if index != modified.length - 1
      outputs += "\n"
    end
  end

  puts outputs
  outputs
end

#get_module_name(module_name) ⇒ Object



81
82
83
# File 'lib/ggsm/command/finish.rb', line 81

def get_module_name(module_name)
  module_name.split(/\//).last.downcase
end

#process_finish(force, msg = '') ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ggsm/command/finish.rb', line 21

def process_finish(force, msg='')
  system 'git add .'

  branch = get_current_branch
  if branch.include?('rebas')
    system 'git rebase --continue'
  else
    stage = `git diff --cached --name-only`.strip
    if stage == ''
      `git commit`
    else
      if msg == ''
        result = system 'git commit'
      else
        result = system "git commit -m \"#{msg}\""
      end
      unless result
        exit 1
      end
    end
  end

  `git push -u origin #{get_current_branch} #{force ? '-f' : ''}`
end