module GGSM::Finish

Public Instance Methods

finish_flow(force) click to toggle source
# 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_msg() click to toggle source
# 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) click to toggle source
# File lib/ggsm/command/finish.rb, line 81
def get_module_name(module_name)
  module_name.split(/\//).last.downcase
end
process_finish(force, msg='') click to toggle source
# 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