Module: GGSM::Switch

Includes:
Stash, Submodule
Included in:
Cli, Sync
Defined in:
lib/ggsm/command/switch.rb

Instance Method Summary collapse

Methods included from Stash

#stash_pop, #try_stash

Methods included from Submodule

#check_submodule, #check_submodule_status, #check_un_commit_code, #correct_dir, #foreach_module, #get_current_branch, #get_modified_submodule, #get_submodule, #get_submodule_commit, #tip_contact_author

Methods included from Hooks

#check_hooks, #cp_files, #cp_hooks, #update_hooks

Instance Method Details

#process_switch(commit_not_exist, arry_conflict, branch, index, sub, sub_commits) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ggsm/command/switch.rb', line 51

def process_switch(commit_not_exist, arry_conflict, branch, index, sub, sub_commits)
  need_stash = try_stash
  result = system "git checkout #{branch}"

  if result
    commit = sub_commits.fetch(index);
    commit_exist = system "git reset --hard #{commit}"
    unless commit_exist
      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

#switch_flow(branch, is_sync = false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ggsm/command/switch.rb', line 10

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
  result = system "git checkout #{branch}"
  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