-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebase-all.rb
65 lines (50 loc) · 1.75 KB
/
rebase-all.rb
1
2
3
4
5
6
7
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
56
57
58
59
60
61
62
63
64
65
branches = `git branch --remotes | grep -v master | grep origin`
good = []
bad = []
noop = []
branches.split.each { |branch|
localname=branch.delete_prefix('origin/')
num_commits = Integer(`git rev-list --count #{branch} ^origin/master`.chomp)
puts "\e[1;32m#{branch}\e[0m: #{num_commits} commits"
rebase_on_log = `git show --format="%s" -s #{branch}#{?~ * num_commits}`.chomp
puts "\e[1;32m#{branch}\e[0m: looking for \e[1;33m#{rebase_on_log}\e[0m"
targets = `git log master --format="%H" --grep '^#{rebase_on_log}$'`.lines
if targets.size != 1
puts "\e[1;32m#{branch}\e[0m: \e[1;31mExpected one target\e[0m: #{targets}"
bad << branch
next
end
target = targets[0].chomp
system("git merge-base --is-ancestor #{target} #{branch}")
if $?.exitstatus == 0
puts "\e[1;32m#{branch}\e[0m: already has \e[1;33m#{target}\e[0m"
noop << branch
next
else
puts "\e[1;32m#{branch}\e[0m: will rebase on \e[1;33m#{target}\e[0m"
end
system("git checkout #{localname}")
system("git rebase -i #{target}")
remote_ref = `git show-ref #{branch}`.split[0]
local_ref = `git show-ref #{localname}`.split[0]
puts "\e[1;32m#{branch}\e[0m: remote #{remote_ref} local #{local_ref}"
if remote_ref == local_ref
noop << branch
system("git checkout master")
system("git branch --delete #{localname}")
next
end
system("git diff #{branch} HEAD")
puts 'CONFIRM??? (anything starting with n for no, otherwise yes)'
if STDIN.gets.downcase.start_with?(?n)
bad << branch
next
end
system("git push --force-with-lease")
system("git checkout master")
system("git branch --delete #{localname}")
good << branch
}
puts "good #{good.size}: #{good}"
puts "bad #{bad.size}: #{bad}"
puts "noop #{noop.size}: #{noop}"