From 6325f0f53ba5bc2449959350c09819b528472e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 22 Dec 2011 00:18:29 +0100 Subject: [PATCH] dirty (temporary) fix for clone command references #98 --- lib/hub/commands.rb | 12 +++++++++--- test/hub_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index fd8bd03e..25cce043 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -180,8 +180,12 @@ module Hub # $ hub clone rtomayko/tilt # $ hub clone tilt if arg =~ NAME_WITH_OWNER_RE - project = github_project(arg) - ssh ||= args[0] != 'submodule' && project.owner == github_user(false) + # FIXME: this logic shouldn't be duplicated here! + name, owner = arg, nil + owner, name = name.split('/', 2) if name.index('/') + host = ENV['GITHUB_HOST'] + project = Context::GithubProject.new(nil, owner || github_user(true, host), name, host || 'github.com') + ssh ||= args[0] != 'submodule' && project.owner == github_user(false, host) || host args[idx] = project.git_url(:private => ssh, :https => https_protocol?) end break @@ -383,7 +387,9 @@ module Hub def init(args) if args.delete('-g') # can't use default_host because there is no local_repo yet - project = Context::GithubProject.new(nil, github_user, File.basename(current_dir), 'github.com') + # FIXME: this shouldn't be here! + host = ENV['GITHUB_HOST'] + project = Context::GithubProject.new(nil, github_user(true, host), File.basename(current_dir), host || 'github.com') url = project.git_url(:private => true, :https => https_protocol?) args.after ['remote', 'add', 'origin', url] end diff --git a/test/hub_test.rb b/test/hub_test.rb index 0ee08ee8..9a2eb6b5 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -61,18 +61,21 @@ class HubTest < Test::Unit::TestCase end def test_private_clone + stub_no_git_repo input = "clone -p rtomayko/ronn" command = "git clone git@github.com:rtomayko/ronn.git" assert_command input, command end def test_private_clone_noop + stub_no_git_repo input = "--noop clone -p rtomayko/ronn" command = "git clone git@github.com:rtomayko/ronn.git\n" assert_output command, hub(input) end def test_https_clone + stub_no_git_repo stub_https_is_preferred input = "clone rtomayko/ronn" command = "git clone https://github.com/rtomayko/ronn.git" @@ -80,40 +83,47 @@ class HubTest < Test::Unit::TestCase end def test_public_clone + stub_no_git_repo input = "clone rtomayko/ronn" command = "git clone git://github.com/rtomayko/ronn.git" assert_command input, command end def test_your_private_clone + stub_no_git_repo input = "clone -p resque" command = "git clone git@github.com:tpw/resque.git" assert_command input, command end def test_your_clone_is_always_private + stub_no_git_repo input = "clone resque" command = "git clone git@github.com:tpw/resque.git" assert_command input, command end def test_clone_repo_with_period + stub_no_git_repo input = "clone hookio/hook.js" command = "git clone git://github.com/hookio/hook.js.git" assert_command input, command end def test_clone_with_arguments + stub_no_git_repo input = "clone --bare -o master resque" command = "git clone --bare -o master git@github.com:tpw/resque.git" assert_command input, command end def test_clone_with_arguments_and_destination + stub_no_git_repo assert_forwarded "clone --template=one/two git://github.com/tpw/resque.git --origin master resquetastic" end def test_your_private_clone_fails_without_config + stub_no_git_repo out = hub("clone -p mustache") do stub_github_user(nil) end @@ -122,6 +132,7 @@ class HubTest < Test::Unit::TestCase end def test_your_public_clone_fails_without_config + stub_no_git_repo out = hub("clone mustache") do stub_github_user(nil) end @@ -130,26 +141,32 @@ class HubTest < Test::Unit::TestCase end def test_private_clone_left_alone + stub_no_git_repo assert_forwarded "clone git@github.com:rtomayko/ronn.git" end def test_public_clone_left_alone + stub_no_git_repo assert_forwarded "clone git://github.com/rtomayko/ronn.git" end def test_normal_public_clone_with_path + stub_no_git_repo assert_forwarded "clone git://github.com/rtomayko/ronn.git ronn-dev" end def test_normal_clone_from_path + stub_no_git_repo assert_forwarded "clone ./test" end def test_clone_with_host_alias + stub_no_git_repo assert_forwarded "clone server:git/repo.git" end def test_enterprise_clone + stub_no_git_repo stub_github_user('myfiname', 'git.my.org') with_host_env('git.my.org') do assert_command "clone myrepo", "git clone git@git.my.org:myfiname/myrepo.git" @@ -519,6 +536,15 @@ class HubTest < Test::Unit::TestCase assert_commands "git init", "git remote add origin git@github.com:tpw/hub.git", "init -g" end + def test_init_enterprise + stub_no_remotes + stub_no_git_repo + stub_github_user('myfiname', 'git.my.org') + with_host_env('git.my.org') do + assert_commands "git init", "git remote add origin git@git.my.org:myfiname/hub.git", "init -g" + end + end + def test_init_no_login out = hub("init -g") do stub_github_user(nil) -- GitLab