Sha256: 01a3abda52df78ab1d8f12d685b28719b987205868d5a2df66cc1df528ad9568

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 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 = []

      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

      subs = get_submodule
      subs.each do |sub|
        Dir.chdir sub
        puts "==> 进入#{sub}:".yellow
        need_stash = try_stash
        result = system "git checkout #{branch}"

        if result
          system "git reset --hard #{sub_commits.fetch(subs.index(sub))}"
        else
          puts "[#{sub}] 没有#{branch}分支,创建并切换到#{branch}".blue
          system "git checkout -b #{branch}"
        end

        if need_stash
          stash_pop(arry_conflict, sub)
        end
        Dir.chdir '..'
      end

      if arry_conflict.size > 0
        tip = '==> 冲突待解决:'
        arry_conflict.each do |sub|
          tip = "#{tip}  #{sub}"
        end
        puts tip.red
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ggsm-1.2.0 lib/ggsm/flow/switch.rb
ggsm-1.1.2 lib/ggsm/flow/switch.rb
ggsm-1.1.1 lib/ggsm/flow/switch.rb
ggsm-1.1.0 lib/ggsm/flow/switch.rb