Created
November 11, 2011 03:10
-
-
Save felipec/1357082 to your computer and use it in GitHub Desktop.
git rebase challenge build helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
@authors = { | |
"david" => "David S. Miller", | |
"ingo" => "Ingo Molnar", | |
"takashi" => "Takashi Iwai", | |
"alexander" => "Al Viro", | |
"russel" => "Russell King", | |
"paul" => "Paul Mundt", | |
"tejun" => "Tejun Heo", | |
"thomas" => "Thomas Gleixner", | |
"bartlomiej" => "Bartlomiej Zolnierkiewicz", | |
"adrian" => "Adrian Bunk", | |
} | |
@file = "README" | |
n = File.readlines("origin/#{@file}").size | |
def random_text(length = 14) | |
chars = ('a'..'z').to_a + ('A'..'Z').to_a | |
(0..length).map { chars[rand(chars.size)] }.join | |
end | |
@authors.each do |nick, name| | |
ENV['GIT_AUTHOR_NAME'] = "#{name}" | |
ENV['GIT_AUTHOR_EMAIL'] = "#{nick}@foobar.com" | |
system "git clone origin #{nick}" | |
Dir.chdir(nick) | |
(1..10).each do |e| | |
branch_n = rand(e) | |
branch = branch_n > 0 ? "branch_%s" % branch_n : "master" | |
system "git checkout -b branch_%s %s" % [e, branch] | |
(1..2).each do |r| | |
case rand(3) | |
when 0 | |
cmd = '%dd' % [rand(n) + 1] | |
when 1 | |
cmd = '%di %s' % [rand(n) + 1, random_text()] | |
when 2 | |
i = rand(n - 1) + 1 | |
o = rand(n - i) + i + 1 | |
cmd = '%d{h;d};%dg' % [i, o] | |
end | |
system "sed -i -e '#{cmd}' #{@file}" | |
system "git commit -q -a -m 'Random change %s'" % [random_text()] | |
end | |
end | |
Dir.chdir("..") | |
end | |
ENV.delete('GIT_AUTHOR_NAME') | |
ENV.delete('GIT_AUTHOR_EMAIL') | |
system "git clone -q origin mine" | |
Dir.chdir("mine") | |
@authors.each do |nick, name| | |
next if nick == "adrian" | |
system "git remote add #{nick} ../#{nick}" | |
end | |
Dir.chdir("..") | |
puts @authors.keys.map { |e| "#{e}/branch_%s" % [rand(10) + 1] }.join(" ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment