Skip to content

Instantly share code, notes, and snippets.

@orangejulius
Created June 19, 2015 18:56
Show Gist options
  • Save orangejulius/5ab22b0d2f134a7d675a to your computer and use it in GitHub Desktop.
Save orangejulius/5ab22b0d2f134a7d675a to your computer and use it in GitHub Desktop.
require 'git'
require 'logger'
revert_branch_name = "origin/remove-failing-tests"
working_dir = '.'
g = Git.open(working_dir, :log => Logger.new(STDOUT))
base_commit = g.gcommit('5b78d2b')
branch_tip_commit = g.gcommit(revert_branch_name)
current_commit = branch_tip_commit
def apply_inverse_patch(g,sha)
g.revert(sha, {strategy: 'ours'})
end
def make_commit(g, message, commit)
full_message = message + "\n\n" +
"This commit reverts and modifies #{commit.sha}"
g.commit(full_message, {amend: true})
end
def push_branch
end
def cleanup(g)
g.reset_hard('HEAD')
g.checkout('master')
end
def replace_fail_status(g)
`sed -i s/\\"fail\\"/\\"pass\\"/ test_cases/*`
g.add('test_cases/*')
g.commit(nil, {amend: true})
end
def make_pull_request_from_reverted_commit(g, commit)
message = commit.message
new_message = message.gsub("Remove", "Add")
branch_name = new_message.downcase.gsub(" ", "-").delete('",')
#patch = g.diff(commit, commit.parent).patch
#patch = patch.gsub('"status": "fail"', '"status": "pass"')
g.branch(branch_name).checkout
if (g.gcommit('HEAD').sha == g.gcommit('master').sha)
apply_inverse_patch(g, commit.sha)
replace_fail_status(g)
make_commit(g, new_message, commit)
end
cleanup(g)
exit(0)
end
while (current_commit.sha != base_commit.sha) do
cleanup(g)
unless current_commit.sha =~ /f02bb3/ # exception commit that doesn't do what the rest do
make_pull_request_from_reverted_commit(g, current_commit)
end
current_commit = current_commit.parent
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment