5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/pr/m3.rb', line 5
def self.update_all_with(main_branch)
`git fetch`
branches = {}
pulls = []
`git ls-remote origin | grep refs\/`.each_line do |a|
ref = a.match(/[a-z0-9]{40}/)
spec = a.match(/refs\/([^\/]+)\/([^\/]+)\/?([^\/]+)?\n/)
if spec[1] == 'heads'
branches[ref.to_s] = spec[2]
elsif spec[1] == 'pull' && spec[3] == 'head'
pulls << ref.to_s
end
end
pulls.each do |commit|
branch = branches[commit]
`git checkout #{branch} && git merge origin/#{main_branch} && git push origin #{branch}`
end
`git checkout #{main_branch}`
end
|