Sha256: e039426d4af09446c92fba218374b82219b429f8bf7bf5d22bef1a51808e7f23

Contents?: true

Size: 1.78 KB

Versions: 16

Compression:

Stored size: 1.78 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|
        if is_sync
          `git fetch | grep 'ignored'`
        end
        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

16 entries across 16 versions & 1 rubygems

Version Path
ggsm-1.9.6 lib/ggsm/command/switch.rb
ggsm-1.9.5 lib/ggsm/command/switch.rb
ggsm-1.9.4 lib/ggsm/command/switch.rb
ggsm-1.9.3 lib/ggsm/command/switch.rb
ggsm-1.9.2 lib/ggsm/command/switch.rb
ggsm-1.9.1 lib/ggsm/command/switch.rb
ggsm-1.9.0 lib/ggsm/command/switch.rb
ggsm-1.8.6 lib/ggsm/command/switch.rb
ggsm-1.8.5 lib/ggsm/command/switch.rb
ggsm-1.8.4 lib/ggsm/command/switch.rb
ggsm-1.8.3 lib/ggsm/command/switch.rb
ggsm-1.8.2 lib/ggsm/command/switch.rb
ggsm-1.8.1 lib/ggsm/command/switch.rb
ggsm-1.8.0 lib/ggsm/command/switch.rb
ggsm-1.7.6 lib/ggsm/command/switch.rb
ggsm-1.7.5 lib/ggsm/command/switch.rb