Interpret the current branch to push to Heroku

This commit is contained in:
Seth Vargo 2014-11-13 17:47:08 -05:00
parent 1f49b7ef62
commit b9e8f6e892
2 changed files with 61 additions and 5 deletions

View File

@ -10,6 +10,9 @@ module VagrantPlugins
# Expand any paths relative to the root
dir = File.expand_path(config.dir, env.root_path)
# Get the current branch
branch = git_branch(dir)
# Verify git is installed
verify_git_bin!(config.git_bin)
@ -22,7 +25,7 @@ module VagrantPlugins
end
# Push to Heroku
git_push_heroku(config.remote, config.branch, dir)
git_push_heroku(config.remote, branch, dir)
end
# Verify that git is installed.
@ -49,6 +52,20 @@ module VagrantPlugins
"#{path}/.git"
end
# The name of the current git branch.
# @param [String] path
# @return [String]
def git_branch(path)
result = execute!("git",
"--git-dir", git_dir(path),
"--work-tree", path,
"branch",
)
# Returns something like "* master"
result.stdout.sub("*", "").strip
end
# Push to the Heroku remote.
# @param [String] remote
# @param [String] branch
@ -56,7 +73,7 @@ module VagrantPlugins
execute!("git",
"--git-dir", git_dir(path),
"--work-tree", path,
"push", remote, branch,
"push", remote, "#{branch}:master",
)
end

View File

@ -17,17 +17,20 @@ describe VagrantPlugins::HerokuPush::Push do
dir: "lib",
git_bin: "git",
remote: "heroku",
branch: "master",
)
end
subject { described_class.new(env, config) }
describe "#push" do
let(:branch) { "master" }
let(:root_path) { "/handy/dandy" }
let(:dir) { "#{root_path}/#{config.dir}" }
before do
allow(subject).to receive(:git_branch)
.and_return(branch)
allow(subject).to receive(:verify_git_bin!)
allow(subject).to receive(:verify_git_repo!)
allow(subject).to receive(:has_git_remote?)
@ -78,7 +81,7 @@ describe VagrantPlugins::HerokuPush::Push do
it "pushes to heroku" do
expect(subject).to receive(:git_push_heroku)
.with(config.remote, config.branch, dir)
.with(config.remote, branch, dir)
subject.push
end
end
@ -157,7 +160,7 @@ describe VagrantPlugins::HerokuPush::Push do
.with("git",
"--git-dir", "#{dir}/.git",
"--work-tree", dir,
"push", "bacon", "hamlet",
"push", "bacon", "hamlet:master",
)
subject.git_push_heroku("bacon", "hamlet", dir)
end
@ -232,6 +235,42 @@ describe VagrantPlugins::HerokuPush::Push do
end
end
describe "#git_branch" do
let(:stdout) { "" }
let(:process) { double("process", stdout: stdout) }
before do
allow(subject).to receive(:execute!)
.and_return(process)
end
let(:branch) { subject.git_branch("/path") }
context "when the branch is prefixed with a star" do
let(:stdout) { "*bacon" }
it "returns the correct name" do
expect(branch).to eq("bacon")
end
end
context "when the branch is prefixed with a star space" do
let(:stdout) { "* bacon" }
it "returns the correct name" do
expect(branch).to eq("bacon")
end
end
context "when the branch is not prefixed" do
let(:stdout) { "bacon" }
it "returns the correct name" do
expect(branch).to eq("bacon")
end
end
end
describe "#execute!" do
let(:exit_code) { 0 }
let(:stdout) { "This is the output" }