diff --git a/features/core_feature.rb b/features/core_feature.rb index 9716d22f6..f27150b75 100644 --- a/features/core_feature.rb +++ b/features/core_feature.rb @@ -114,6 +114,7 @@ Dir.chdir @app.name end let(:git_config){ `git config --list` } + let(:git_remotes){ `git remote -v` } it "will set Git config values" do git_config.should match "rhc.app-id=#{app.id}" @@ -121,6 +122,11 @@ git_config.should match "rhc.domain-name=#{app.domain_name}" end + it "will set remote branches correctly" do + git_remotes.should match "origin" + git_remotes.should_not match "upstream" + end + it "will infer the current app from the git repository" do r = rhc 'show-app' r.stdout.should match app.name diff --git a/lib/rhc/git_helpers.rb b/lib/rhc/git_helpers.rb index d39023b05..c0a20879a 100644 --- a/lib/rhc/git_helpers.rb +++ b/lib/rhc/git_helpers.rb @@ -41,6 +41,8 @@ def git_clone_application(app) git_config_set "rhc.app-id", app.id git_config_set "rhc.app-name", app.name git_config_set "rhc.domain-name", app.domain_id + + git_remote_add("upstream", app.initial_git_url) if app.initial_git_url.present? end git_clone_deploy_hooks(repo_dir) @@ -48,6 +50,13 @@ def git_clone_application(app) dir end + def git_remote_add(remote_name, remote_url) + cmd = "#{git_cmd} remote add upstream \"#{remote_url}\"" + debug "Running #{cmd} 2>&1" + output = %x[#{cmd} 2>&1] + raise RHC::GitException, "Error while adding upstream remote - #{output}" unless output.empty? + end + # :nocov: These all call external binaries so test them in cucumber def git_config_get(key) return nil unless has_git? diff --git a/spec/rhc/commands/git_clone_spec.rb b/spec/rhc/commands/git_clone_spec.rb index 479662cce..38c039336 100644 --- a/spec/rhc/commands/git_clone_spec.rb +++ b/spec/rhc/commands/git_clone_spec.rb @@ -53,6 +53,19 @@ it { expect { run }.to exit_with_code(0) } it { run_output.should match("Cloned") } + + context 'when app has an initial git url' do + before do + @app2 = @domain.add_application("app2", "mock_unique_standalone_cart", nil, "default", "git://test") + @instance.stub(:git_remote_add) do |remote_name, remote_url| + say "Added remote #{remote_name} pointing to #{remote_url}" + true + end + end + let(:arguments) { ['git-clone', 'app2'] } + it { run_output.should match("Added remote upstream pointing to git://test") } + end + end context "testing git_clone_deploy_hooks" do