-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-test-unmerged
executable file
·54 lines (45 loc) · 1.31 KB
/
git-test-unmerged
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
#!/usr/bin/env ruby
#
# git-test-unmerged
# Runs a command against a checkout of each commit you haven't merged to master.
# Handy for running an automated test suite against each of your changes.
# Stops early if the command returns a non-zero status code.
#
# Usage:
# git test-unmerged command
#
# Example:
# git test-unmerged rake
def formatted_output(current_action = nil, message = '')
reverse, bold, reset = "\e[7m", "\e[1m", "\e[0m"
if current_action.nil?
"#{bold}#{message}#{reset}"
else
"#{reverse} #{current_action} #{reset} #{bold}#{message}#{reset}"
end
end
command = $*.join(' ')
if command.empty?
puts formatted_output(nil, "Usage: git test-unmerged command")
abort
end
commits = `git log master.. --pretty=format:%H`
current_branch = `git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||'`
at_exit do
puts formatted_output("Returning to", current_branch)
`git checkout -q #{current_branch}`
end
commits.split.reverse.each do |sha|
sha.strip!
puts formatted_output("Switching to", sha)
system "git checkout -q #{sha}"
puts formatted_output("Running test", command)
puts
system command
if !$?.success?
puts formatted_output(nil, "Error running test!")
puts formatted_output(nil, "Commit #{sha[0...10]} returned status code #{$?.exitstatus}.\n")
break
end
puts
end