Sha256: b057a291f974a495d6007b953862defc84658e7eaac2ea049e7afff636cc907d

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

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

module GGSM
  module Switch
    include Submodule
    include Stash

    def switch_flow(branch, is_sync = false)
      check_submodule
      check_submodule_status(is_sync)

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

      arry_conflict = []
      arry_commit_not_exist = []

      need_stash = try_stash
      `git checkout #{branch}`; result=$?.success?
      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

      `git checkout #{branch}`; result=$?.success?

      if result
        commit = sub_commits.fetch(index);
        `git reset --hard #{commit}`; result=$?.success?
        unless result
          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.7.4 lib/ggsm/command/switch.rb
ggsm-1.7.3 lib/ggsm/command/switch.rb
ggsm-1.7.2 lib/ggsm/command/switch.rb