Sha256: e1c62facd3880728d477d1fef00a37cee0e801f8b505786a685b7df5f76575b3

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

require 'colorize'
require_relative '../util/submodule'
require_relative '../util/stash'

module GGSM
  module Switch
    include Submodule
    include Stash

    def switch_flow(branch)
      check_submodule

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

      arry_conflict = []
      arry_commit_not_exist = []

      need_stash = try_stash
      result = system "git checkout #{branch}"
      if need_stash
        stash_pop(arry_conflict, '主工程')
      end

      unless result
        return
      end

      sub_commits = get_submodule_commit

      foreach_module {|sub, index|
        process_switch(arry_commit_not_exist, arry_conflict, branch, index, sub, sub_commits)
      }

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

      if arry_commit_not_exist.size > 0
        arry_commit_not_exist.each do |tip|
          puts tip.red
        end
        tip_contact_author
      end
    end

    def process_switch(commit_not_exist, arry_conflict, branch, index, sub, sub_commits)
      need_stash = try_stash
      result = system "git checkout #{branch}"

      if result
        commit = sub_commits.fetch(index);
        commit_exist = system "git reset --hard #{commit}"
        unless commit_exist
          commit_not_exist.push("==> #{sub}模块不存在远程commit:#{commit}")
        end
      else
        puts "[#{sub}] 没有#{branch}分支,创建并切换到#{branch}".blue
        system "git checkout -b #{branch}"
      end

      if need_stash
        stash_pop(arry_conflict, sub)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ggsm-1.5.1 lib/ggsm/flow/switch.rb
ggsm-1.5.0 lib/ggsm/flow/switch.rb
ggsm-1.4.0 lib/ggsm/flow/switch.rb