Module: GGSM::Merge
- Includes:
- Submodule
- Included in:
- Cli
- Defined in:
- lib/ggsm/command/merge.rb
Instance Method Summary
collapse
Methods included from Submodule
#check_submodule, #check_submodule_status, #check_un_commit_code, #correct_dir, #foreach_module, #get_current_branch, #get_head_commit, #get_lastest_msg, #get_lastest_msg_not_merge, #get_lastest_msg_of_module, #get_modified_submodule, #get_submodule, #get_submodule_commit, #is_submodule, #tip_contact_author
Methods included from Hooks
#check_hooks, #cp_files, #cp_hooks, #install_billow, #update_hooks
Instance Method Details
#can_rebase(current_branch) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/ggsm/command/merge.rb', line 92
def can_rebase(current_branch)
remote = `git config --get branch.#{current_branch}.remote`
if remote == ''
`git branch -r`.split("\n").each do |branch|
if branch.strip == "origin/#{current_branch}"
remote = 'origin'
yield remote
end
end
else
yield remote
end
true
end
|
#merge_flow(branch, force_rebase) ⇒ Object
8
9
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
50
51
52
53
54
55
|
# File 'lib/ggsm/command/merge.rb', line 8
def merge_flow(branch, force_rebase)
check_submodule
check_un_commit_code
arry_conflict = []
foreach_module {|sub|
if branch.start_with?('origin/')
`git fetch | grep 'ignored'`
end
process_merge(arry_conflict, sub, branch)
}
puts '==> 进入主工程:'.yellow
main_rebase = false
if force_rebase
main_rebase = true
end
if branch.start_with?('origin/')
`git fetch | grep 'ignored'`
end
if need_rebase(branch) || force_rebase
process_rebase(arry_conflict, branch)
puts 'Tip: 主工程rebase模式'.blue
else
process_merge(arry_conflict, '主工程', branch)
puts 'Tip: 主工程merge模式'.blue
end
if arry_conflict.size > 0
tip = "==> #{arry_conflict.size}个模块冲突:"
arry_conflict.reverse.each do |sub|
tip = "#{tip} #{sub}"
end
puts tip.red
puts "Tip: 当你解决冲突后,执行\"git add .\",如需推送远程,在主工程执行\"ggsm finish\"".blue
else
if main_rebase
puts "Tip: 如需推送远程,执行\"ggsm finish -f|--force\"".blue
else
puts "Tip: 如需推送远程,执行\"ggsm finish\"".blue
end
end
end
|
#need_rebase(branch) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/ggsm/command/merge.rb', line 75
def need_rebase(branch)
pattern = /[0-9a-z]{7}(?=\s)/
current_branch = get_current_branch
can_rebase(current_branch) {|remote|
diff_logs = `git log --oneline #{branch}..#{current_branch}`.split("\n").reverse
if diff_logs.length > 0
commit = pattern.match(diff_logs[0].strip)[0]
result = `git log #{remote}/#{current_branch} |grep #{commit}`
if `git log --oneline #{current_branch}..#{branch}`.split("\n").length > 0 && result.strip != ''
return false
end
end
}
end
|
#process_merge(arry_conflict, module_name, branch) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/ggsm/command/merge.rb', line 57
def process_merge(arry_conflict, module_name, branch)
result_merge = `git merge #{branch}`
puts result_merge
if result_merge.include? 'Merge conflict'
arry_conflict.push(module_name)
end
end
|
#process_rebase(arry_conflict, branch) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/ggsm/command/merge.rb', line 66
def process_rebase(arry_conflict, branch)
result_merge = `git rebase #{branch}`
puts result_merge
if result_merge.include? 'Merge conflict'
arry_conflict.push('主工程')
end
end
|