Sha256: 3ee62adaebf5dd22122510f89e4d3fcaf59309927af5a7e203f16545a8468059

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

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

module GGSM
  module Switch
    include Submodule
    include Stash

    def switch_flow(branch)
      unless check_submodule
        return
      end

      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

      `git submodule update --init --recursive`

      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

1 entries across 1 versions & 1 rubygems

Version Path
ggsm-1.0.1 lib/ggsm/flow/switch.rb