module GGSM::Start

Public Instance Methods

start_flow(branch, action) click to toggle source
# File lib/ggsm/command/start.rb, line 10
def start_flow(branch, action)
  check_submodule

  puts '==> 进入主工程:'.yellow

  arry_conflict = []
  current_branch = get_current_branch

  need_stash = try_stash
  if action.start_with?('origin/')
    need_fetch = `git fetch`
    if need_fetch != ''
      `git submodule foreach git fetch | grep 'ignored'`
    end
  end
  result = system "git checkout -b #{branch} #{action}"
  if need_stash
    stash_pop(arry_conflict, '主工程')
  end

  unless result
    return
  end

  result = system 'git submodule update --init --recursive'
  unless result
    tip_contact_author
    `git checkout #{current_branch};git branch -D #{branch}`
    return
  end

  foreach_module {|sub|
    need_stash = try_stash
    system "git checkout -b #{branch}"
    if need_stash
      stash_pop(arry_conflict, sub)
    end
  }

  if arry_conflict.size > 0
    tip = "==> #{arry_conflict.size}个模块冲突:"
    arry_conflict.each do |sub|
      tip = "#{tip}  #{sub}"
    end
    puts tip.red
  end
end