-
Notifications
You must be signed in to change notification settings - Fork 1
/
commit
executable file
·31 lines (26 loc) · 998 Bytes
/
commit
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
#!/usr/bin/env ruby
logs = {}
diff = `git diff --cached --submodule`
diff.each_line do |line|
if /^Submodule (?<submodule>.*) (?<old_hash>\w+)\.\.(?<non_ff>\.?)(?<new_hash>\w+)/ =~ line
Dir.chdir(submodule) do
if `git rev-parse HEAD` != `git rev-parse @{push}`
puts "ERROR: #{submodule}: Some commits have not been pushed."
exit 1
end
logs[submodule] =
if non_ff != ''
"#{submodule}: #{old_hash}...#{new_hash} (no fast-forward!)\n\n" +
`git log #{old_hash}...#{new_hash} --no-merges --pretty="format: * %m %h %s (%an)%n%n%w(76,4,4)%-b%n"`
else
"#{submodule}: #{old_hash}..#{new_hash}\n\n" +
`git log #{old_hash}..#{new_hash} --no-merges --pretty="format: * %h %s (%an)%n%n%w(76,4,4)%-b%n"`
end
end
end
end
log = "Submodule updates: " + logs.keys.join(", ").gsub(".tmbundle", "") + "\n\n"
log << logs.values.join("\n")
IO.popen "git commit -e -F -", "w" do |f|
f.puts log
end