Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

dirty (temporary) fix for clone command

references #98
  • Loading branch information...
commit 6325f0f53ba5bc2449959350c09819b528472e2a 1 parent 3b1a31f
@mislav mislav authored
Showing with 35 additions and 3 deletions.
  1. +9 −3 lib/hub/commands.rb
  2. +26 −0 test/hub_test.rb
View
12 lib/hub/commands.rb
@@ -180,8 +180,12 @@ def clone(args)
# $ 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 @@ def am(args)
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
View
26 test/hub_test.rb
@@ -61,18 +61,21 @@ def setup
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 @@ def test_https_clone
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 @@ def test_your_private_clone_fails_without_config
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 @@ def test_your_public_clone_fails_without_config
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 @@ def test_init
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)
Please sign in to comment.
Something went wrong with that request. Please try again.