提交 a0fc0344 编写于 作者: C Chris Wanstrath

add `git clone blah` which will use your github login to clone your repo

上级 17f2e124
......@@ -97,6 +97,12 @@ superpowers:
$ git clone -p schacon/ticgit
> git clone git@github.com:schacon/ticgit.git
$ git clone resque
> git clone git://github.com/YOUR_USER/resque.git
$ git clone -p resque
> git clone git@github.com:YOUR_USER/resque.git
### git remote add
$ git remote add rtomayko
......@@ -109,7 +115,7 @@ superpowers:
$ git init -g
> git init
> git remote add origin git@github.com:USER/REPO.git
> git remote add origin git@github.com:YOUR_USER/REPO.git
### git help
......
......@@ -45,10 +45,16 @@ module Hub
# > git clone git@github.com:kneath/hemingway.git
def clone(args)
ssh = args.delete('-p')
args.each_with_index do |arg, i|
args[1..-1].each_with_index do |arg, i|
i += 1
if arg.scan('/').size == 1 && !arg.include?(':')
url = ssh ? PRIVATE : PUBLIC
args[i] = url % arg.split('/')
break
elsif arg !~ /:|\//
url = ssh ? PRIVATE : PUBLIC
args[i] = url % [ USER, arg ]
break
end
end
end
......@@ -63,7 +69,7 @@ module Hub
# Assume GitHub usernames don't ever contain : or /, while URLs
# do.
if args[-1] !~ /:\//
if args[-1] !~ /:|\//
ssh = args.delete('-p')
user = args.last
url = ssh ? PRIVATE : PUBLIC
......
......@@ -2,6 +2,10 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
require 'helper'
class HubTest < Test::Unit::TestCase
def setup
Hub::Commands::USER.replace("tpw")
end
def test_private_clone
input = "clone -p rtomayko/ron"
command = "git clone git@github.com:rtomayko/ron.git"
......@@ -14,6 +18,30 @@ class HubTest < Test::Unit::TestCase
assert_command input, command
end
def test_your_private_clone
input = "clone -p resque"
command = "git clone git@github.com:tpw/resque.git"
assert_command input, command
end
def test_your_public_clone
input = "clone resque"
command = "git clone git://github.com/tpw/resque.git"
assert_command input, command
end
def test_private_clone_left_alone
input = "clone git@github.com:rtomayko/ron.git"
command = "git clone git@github.com:rtomayko/ron.git"
assert_command input, command
end
def test_public_clone_left_alone
input = "clone git://github.com/rtomayko/ron.git"
command = "git clone git://github.com/rtomayko/ron.git"
assert_command input, command
end
def test_private_remote
input = "remote add -p rtomayko"
command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
......@@ -27,7 +55,6 @@ class HubTest < Test::Unit::TestCase
end
def test_init
Hub::Commands::USER.replace("tpw")
h = Hub("init -g")
assert_equal "git init", h.command
assert_equal "git remote add origin git@github.com:tpw/hub.git", h.after
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册