Sha256: 0e6969e02bd60067b8e1edcfa2922cf5a50f950ecec99454a584e784996db99b

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 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

      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

2 entries across 2 versions & 1 rubygems

Version Path
ggsm-1.0.2 lib/ggsm/flow/switch.rb
ggsm-1.0.0 lib/ggsm/flow/switch.rb