boneyard-formula-pr: add local-only mode

Allow boneyarding a formula locally, i.e. make all the necessary changes
in the local repositories but don't push them to a remote and don't open
a pull request automatically.
This commit is contained in:
Martin Afanasjew 2016-06-20 17:32:12 +02:00
parent c6022104f9
commit 69401bfe91

View File

@ -4,6 +4,7 @@
# #
# Options: # Options:
# --dry-run: Print what would be done rather than doing it. # --dry-run: Print what would be done rather than doing it.
# --local: Perform only local operations (don't push and don't create PR).
require "formula" require "formula"
require "utils/json" require "utils/json"
@ -19,6 +20,7 @@ end
module Homebrew module Homebrew
def boneyard_formula_pr def boneyard_formula_pr
local_only = ARGV.include?("--local")
formula = ARGV.formulae.first formula = ARGV.formulae.first
odie "No formula found!" unless formula odie "No formula found!" unless formula
@ -58,7 +60,7 @@ module Homebrew
tap_migrations = tap_migrations.sort.inject({}) { |a, e| a.merge!(e[0] => e[1]) } tap_migrations = tap_migrations.sort.inject({}) { |a, e| a.merge!(e[0] => e[1]) }
tap_migrations_path.atomic_write(JSON.pretty_generate(tap_migrations) + "\n") tap_migrations_path.atomic_write(JSON.pretty_generate(tap_migrations) + "\n")
end end
unless Formula["hub"].any_version_installed? unless Formula["hub"].any_version_installed? || local_only
if ARGV.dry_run? if ARGV.dry_run?
puts "brew install hub" puts "brew install hub"
else else
@ -70,17 +72,22 @@ module Homebrew
puts "cd #{formula.tap.path}" puts "cd #{formula.tap.path}"
puts "git checkout -b #{branch} origin/master" puts "git checkout -b #{branch} origin/master"
puts "git commit --no-edit --verbose --message=\"#{formula.name}: migrate to boneyard\" -- #{formula_relpath} #{tap_migrations_path.basename}" puts "git commit --no-edit --verbose --message=\"#{formula.name}: migrate to boneyard\" -- #{formula_relpath} #{tap_migrations_path.basename}"
unless local_only
puts "hub fork --no-remote" puts "hub fork --no-remote"
puts "hub fork" puts "hub fork"
puts "hub fork (to read $HUB_REMOTE)" puts "hub fork (to read $HUB_REMOTE)"
puts "git push $HUB_REMOTE #{branch}:#{branch}" puts "git push $HUB_REMOTE #{branch}:#{branch}"
puts "hub pull-request -m $'#{formula.name}: migrate to boneyard\\n\\nCreated with `brew boneyard-formula-pr`.'" puts "hub pull-request -m $'#{formula.name}: migrate to boneyard\\n\\nCreated with `brew boneyard-formula-pr`.'"
end
else else
cd formula.tap.path cd formula.tap.path
safe_system "git", "checkout", "-b", branch, "origin/master" safe_system "git", "checkout", "-b", branch, "origin/master"
safe_system "git", "commit", "--no-edit", "--verbose", safe_system "git", "commit", "--no-edit", "--verbose",
"--message=#{formula.name}: migrate to boneyard", "--message=#{formula.name}: migrate to boneyard",
"--", formula_relpath, tap_migrations_path.basename "--", formula_relpath, tap_migrations_path.basename
unless local_only
safe_system "hub", "fork", "--no-remote" safe_system "hub", "fork", "--no-remote"
quiet_system "hub", "fork" quiet_system "hub", "fork"
remote = Utils.popen_read("hub fork 2>&1")[/fatal: remote (.+) already exists./, 1] remote = Utils.popen_read("hub fork 2>&1")[/fatal: remote (.+) already exists./, 1]
@ -93,6 +100,7 @@ module Homebrew
EOS EOS
pr_url = Utils.popen_read("hub", "pull-request", "-m", pr_message).chomp pr_url = Utils.popen_read("hub", "pull-request", "-m", pr_message).chomp
end end
end
if ARGV.dry_run? if ARGV.dry_run?
puts "cd #{boneyard_tap.path}" puts "cd #{boneyard_tap.path}"
@ -104,11 +112,14 @@ module Homebrew
end end
puts "git add #{formula_file}" puts "git add #{formula_file}"
puts "git commit --no-edit --verbose --message=\"#{formula.name}: migrate from #{formula.tap.repo}\" -- #{formula_file}" puts "git commit --no-edit --verbose --message=\"#{formula.name}: migrate from #{formula.tap.repo}\" -- #{formula_file}"
unless local_only
puts "hub fork --no-remote" puts "hub fork --no-remote"
puts "hub fork" puts "hub fork"
puts "hub fork (to read $HUB_REMOTE)" puts "hub fork (to read $HUB_REMOTE)"
puts "git push $HUB_REMOTE #{branch}:#{branch}" puts "git push $HUB_REMOTE #{branch}:#{branch}"
puts "hub pull-request --browse -m $'#{formula.name}: migrate from #{formula.tap.repo}\\n\\nGoes together with $PR_URL\\n\\nCreated with `brew boneyard-formula-pr`.'" puts "hub pull-request --browse -m $'#{formula.name}: migrate from #{formula.tap.repo}\\n\\nGoes together with $PR_URL\\n\\nCreated with `brew boneyard-formula-pr`.'"
end
else else
cd boneyard_tap.formula_dir cd boneyard_tap.formula_dir
safe_system "git", "checkout", "-b", branch, "origin/master" safe_system "git", "checkout", "-b", branch, "origin/master"
@ -119,6 +130,8 @@ module Homebrew
safe_system "git", "commit", "--no-edit", "--verbose", safe_system "git", "commit", "--no-edit", "--verbose",
"--message=#{formula.name}: migrate from #{formula.tap.repo}", "--message=#{formula.name}: migrate from #{formula.tap.repo}",
"--", formula_file "--", formula_file
unless local_only
safe_system "hub", "fork", "--no-remote" safe_system "hub", "fork", "--no-remote"
quiet_system "hub", "fork" quiet_system "hub", "fork"
remote = Utils.popen_read("hub fork 2>&1")[/fatal: remote (.+) already exists./, 1] remote = Utils.popen_read("hub fork 2>&1")[/fatal: remote (.+) already exists./, 1]
@ -133,4 +146,5 @@ module Homebrew
EOS EOS
end end
end end
end
end end