Skip to content

Commit

Permalink
add git clone blah which will use your github login to clone your repo
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Dec 9, 2009
1 parent 17f2e12 commit a0fc034
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -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
Expand All @@ -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

Expand Down
10 changes: 8 additions & 2 deletions lib/hub/commands.rb
Expand Up @@ -45,10 +45,16 @@ module Commands
# > 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
Expand All @@ -63,7 +69,7 @@ def remote(args)

# 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
Expand Down
29 changes: 28 additions & 1 deletion test/hub_test.rb
Expand Up @@ -2,6 +2,10 @@
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"
Expand All @@ -14,6 +18,30 @@ def test_public_clone
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"
Expand All @@ -27,7 +55,6 @@ def test_public_remote
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
Expand Down

0 comments on commit a0fc034

Please sign in to comment.