Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
ensure netrc is available first
Browse files Browse the repository at this point in the history
  • Loading branch information
dickeyxxx committed Dec 1, 2014
1 parent 3f58d5c commit c21ad3a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 29 deletions.
14 changes: 12 additions & 2 deletions lib/heroku/command/apps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def info
# -l, --locked # lock the app
# --ssh-git # Use SSH git protocol
# -t, --tier TIER # HIDDEN: the tier for this app
# --http-git # HIDDEN: Use HTTP git protocol
#
#Examples:
#
Expand Down Expand Up @@ -290,6 +291,8 @@ def create
#
# rename the app
#
# --ssh-git # Use SSH git protocol
#
#Example:
#
# $ heroku apps:rename example-newname
Expand All @@ -303,18 +306,25 @@ def rename
end
validate_arguments!

git_url = if options[:ssh_git]
app_data["git_url"]
else
warn_if_netrc_does_not_have_https_git
git_url = "https://#{Heroku::Auth.http_git_host}/#{newname}.git"
end

action("Renaming #{app} to #{newname}") do
api.put_app(app, "name" => newname)
end

app_data = api.get_app(newname).body
hputs([ app_data["web_url"], app_data["git_url"] ].join(" | "))
hputs([ app_data["web_url"], git_url ].join(" | "))

if remotes = git_remotes(Dir.pwd)
remotes.each do |remote_name, remote_app|
next if remote_app != app
git "remote rm #{remote_name}"
git "remote add #{remote_name} #{app_data["git_url"]}"
git "remote add #{remote_name} #{git_url}"
hputs("Git remote #{remote_name} updated")
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/heroku/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def app_owner email
end

def warn_if_netrc_does_not_have_https_git
unless Auth.netrc["git.heroku.com"]
unless Auth.netrc && Auth.netrc["git.heroku.com"]
warn "WARNING: Incomplete credentials detected, git may not work with Heroku. Run `heroku login` to update your credentials. See documentation for details: https://devcenter.heroku.com/articles/http-git#authentication"
exit 1
end
Expand Down
36 changes: 18 additions & 18 deletions spec/heroku/command/apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating #{name}... done, stack is bamboo-mri-1.9.2
http://#{name}.herokuapp.com/ | git@heroku.com:#{name}.git
http://#{name}.herokuapp.com/ | https://git.heroku.com/#{name}.git
Git remote heroku added
STDOUT
end
Expand All @@ -89,7 +89,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating example... done, stack is bamboo-mri-1.9.2
http://example.herokuapp.com/ | git@heroku.com:example.git
http://example.herokuapp.com/ | https://git.heroku.com/example.git
Git remote heroku added
STDOUT
end
Expand All @@ -102,7 +102,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating example... done, stack is bamboo-mri-1.9.2
http://example.herokuapp.com/ | git@heroku.com:example.git
http://example.herokuapp.com/ | https://git.heroku.com/example.git
Git remote heroku added
STDOUT
end
Expand All @@ -115,7 +115,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating example... done, stack is bamboo-mri-1.9.2
http://example.herokuapp.com/ | git@heroku.com:example.git
http://example.herokuapp.com/ | https://git.heroku.com/example.git
STDOUT
end
api.delete_app("example")
Expand All @@ -129,7 +129,7 @@ module Heroku::Command
Creating addonapp... done, stack is bamboo-mri-1.9.2
Adding custom_domains:basic to addonapp... done
Adding releases:basic to addonapp... done
http://addonapp.herokuapp.com/ | git@heroku.com:addonapp.git
http://addonapp.herokuapp.com/ | https://git.heroku.com/addonapp.git
Git remote heroku added
STDOUT
end
Expand All @@ -143,7 +143,7 @@ module Heroku::Command
expect(stdout).to eq <<-STDOUT
Creating buildpackapp... done, stack is bamboo-mri-1.9.2
BUILDPACK_URL=http://example.org/buildpack.git
http://buildpackapp.herokuapp.com/ | git@heroku.com:buildpackapp.git
http://buildpackapp.herokuapp.com/ | https://git.heroku.com/buildpackapp.git
Git remote heroku added
STDOUT
end
Expand All @@ -156,7 +156,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating alternate-remote... done, stack is bamboo-mri-1.9.2
http://alternate-remote.herokuapp.com/ | git@heroku.com:alternate-remote.git
http://alternate-remote.herokuapp.com/ | https://git.heroku.com/alternate-remote.git
Git remote alternate added
STDOUT
end
Expand Down Expand Up @@ -267,7 +267,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Renaming example to example2... done
http://example2.herokuapp.com/ | git@heroku.com:example2.git
http://example2.herokuapp.com/ | https://git.heroku.com/example2.git
Don't forget to update your Git remotes on any local checkouts.
STDOUT
end
Expand Down Expand Up @@ -341,7 +341,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating example... done, stack is bamboo-mri-1.9.2
http://example.herokuapp.com/ | git@heroku.com:example.git
http://example.herokuapp.com/ | https://git.heroku.com/example.git
Git remote heroku added
STDOUT
expect(`git remote`.strip).to match(/^heroku$/)
Expand All @@ -355,7 +355,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating example... done, stack is bamboo-mri-1.9.2
http://example.herokuapp.com/ | git@heroku.com:example.git
http://example.herokuapp.com/ | https://git.heroku.com/example.git
Git remote myremote added
STDOUT
expect(`git remote`.strip).to match(/^myremote$/)
Expand All @@ -370,7 +370,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
Creating example... done, stack is bamboo-mri-1.9.2
http://example.herokuapp.com/ | git@heroku.com:example.git
http://example.herokuapp.com/ | https://git.heroku.com/example.git
STDOUT
api.delete_app("example")
end
Expand All @@ -379,8 +379,8 @@ module Heroku::Command
it "renames updating the corresponding heroku git remote" do
with_blank_git_repository do
`git remote add github git@github.com:test/test.git`
`git remote add production git@heroku.com:example.git`
`git remote add staging git@heroku.com:example-staging.git`
`git remote add production https://git.heroku.com/example.git`
`git remote add staging https://git.heroku.com/example-staging.git`

api.post_app("name" => "example", "stack" => "cedar")
stderr, stdout = execute("apps:rename example2")
Expand All @@ -390,17 +390,17 @@ module Heroku::Command
expect(remotes).to eq <<-REMOTES
github\tgit@github.com:test/test.git (fetch)
github\tgit@github.com:test/test.git (push)
production\tgit@heroku.com:example2.git (fetch)
production\tgit@heroku.com:example2.git (push)
staging\tgit@heroku.com:example-staging.git (fetch)
staging\tgit@heroku.com:example-staging.git (push)
production\thttps://git.heroku.com/example2.git (fetch)
production\thttps://git.heroku.com/example2.git (push)
staging\thttps://git.heroku.com/example-staging.git (fetch)
staging\thttps://git.heroku.com/example-staging.git (push)
REMOTES
end
end

it "destroys removing any remotes pointing to the app" do
with_blank_git_repository do
`git remote add heroku git@heroku.com:example.git`
`git remote add heroku https://git.heroku.com/example.git`

api.post_app("name" => "example", "stack" => "cedar")
stderr, stdout = execute("apps:destroy --confirm example")
Expand Down
16 changes: 8 additions & 8 deletions spec/heroku/command/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Heroku::Command

it "clones and adds remote" do
any_instance_of(Heroku::Command::Git) do |git|
mock(git).system("git clone -o heroku git@heroku.com:example.git") do
mock(git).system("git clone -o heroku https://git.heroku.com/example.git") do
puts "Cloning into 'example'..."
end
end
Expand All @@ -34,7 +34,7 @@ module Heroku::Command

it "clones into another dir" do
any_instance_of(Heroku::Command::Git) do |git|
mock(git).system("git clone -o heroku git@heroku.com:example.git somedir") do
mock(git).system("git clone -o heroku https://git.heroku.com/example.git somedir") do
puts "Cloning into 'somedir'..."
end
end
Expand All @@ -48,7 +48,7 @@ module Heroku::Command

it "can specify app with -a" do
any_instance_of(Heroku::Command::Git) do |git|
mock(git).system("git clone -o heroku git@heroku.com:example.git") do
mock(git).system("git clone -o heroku https://git.heroku.com/example.git") do
puts "Cloning into 'example'..."
end
end
Expand All @@ -62,7 +62,7 @@ module Heroku::Command

it "can specify app with -a and a dir" do
any_instance_of(Heroku::Command::Git) do |git|
mock(git).system("git clone -o heroku git@heroku.com:example.git somedir") do
mock(git).system("git clone -o heroku https://git.heroku.com/example.git somedir") do
puts "Cloning into 'somedir'..."
end
end
Expand All @@ -76,7 +76,7 @@ module Heroku::Command

it "clones and sets -r remote" do
any_instance_of(Heroku::Command::Git) do |git|
mock(git).system("git clone -o other git@heroku.com:example.git") do
mock(git).system("git clone -o other https://git.heroku.com/example.git") do
puts "Cloning into 'example'..."
end
end
Expand Down Expand Up @@ -106,7 +106,7 @@ module Heroku::Command
it "adds remote" do
any_instance_of(Heroku::Command::Git) do |git|
stub(git).git('remote').returns("origin")
stub(git).git('remote add heroku git@heroku.com:example.git')
stub(git).git('remote add heroku https://git.heroku.com/example.git')
end
stderr, stdout = execute("git:remote")
expect(stderr).to eq("")
Expand All @@ -118,7 +118,7 @@ module Heroku::Command
it "adds -r remote" do
any_instance_of(Heroku::Command::Git) do |git|
stub(git).git('remote').returns("origin")
stub(git).git('remote add other git@heroku.com:example.git')
stub(git).git('remote add other https://git.heroku.com/example.git')
end
stderr, stdout = execute("git:remote -r other")
expect(stderr).to eq("")
Expand All @@ -130,7 +130,7 @@ module Heroku::Command
it "updates remote when it already exists" do
any_instance_of(Heroku::Command::Git) do |git|
stub(git).git('remote').returns("heroku")
stub(git).git('remote set-url heroku git@heroku.com:example.git')
stub(git).git('remote set-url heroku https://git.heroku.com/example.git')
end
stderr, stdout = execute("git:remote")
expect(stderr).to eq("")
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ module Heroku::Helpers
def home_directory
@home_directory
end
undef_method :warn_if_netrc_does_not_have_https_git
def warn_if_netrc_does_not_have_https_git; end
end

require "support/display_message_matcher"
Expand Down

0 comments on commit c21ad3a

Please sign in to comment.